-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameterize taxon's permalink also on update #3090
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,14 @@ | |
expect(taxon.permalink).to eql "ruby-on-rails" | ||
end | ||
|
||
context "updating a taxon permalink" do | ||
it 'parameterizes permalink correctly' do | ||
taxon.save! | ||
taxon.update_attributes(permalink: 'spécial&charactèrs') | ||
expect(taxon.permalink).to eql "special-characters" | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change also has effects on permalinks of children. Can we test that it works with children as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I'll add this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the test you added is testing that the permalink is correctly saved when it has a parent taxon. I mean to test when the taxon with special chars has children instead (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added 2 more tests |
||
|
||
context "with parent taxon" do | ||
let(:parent) { FactoryBot.build(:taxon, permalink: "brands") } | ||
before { allow(taxon).to receive_messages parent: parent } | ||
|
@@ -41,6 +49,12 @@ | |
expect(taxon.permalink).to eql "brands/rubyonrails" | ||
end | ||
|
||
it 'parameterizes permalink correctly' do | ||
taxon.save! | ||
taxon.update_attributes(permalink_part: 'spécial&charactèrs') | ||
expect(taxon.reload.permalink).to eql "brands/special-characters" | ||
end | ||
|
||
# Regression test for https://github.com/spree/spree/issues/3390 | ||
context "setting a new node sibling position via :child_index=" do | ||
let(:idx) { rand(0..100) } | ||
|
@@ -121,6 +135,20 @@ | |
is_expected.to change{ taxon2_child.reload.permalink }.from('t/t2/t2_child').to('t/t1/foo/t2_child') | ||
end | ||
end | ||
|
||
context 'changing parent permalink with special characters ' do | ||
subject do | ||
-> { taxon2.update!(permalink: 'spécial&charactèrs') } | ||
end | ||
|
||
it 'changes own permalink with parameterized characters' do | ||
is_expected.to change{ taxon2.reload.permalink }.from('t/t2').to('t/special-characters') | ||
end | ||
|
||
it 'changes child permalink with parameterized characters' do | ||
is_expected.to change{ taxon2_child.reload.permalink }.from('t/t2/t2_child').to('t/special-characters/t2_child') | ||
end | ||
end | ||
end | ||
|
||
# Regression test for https://github.com/spree/spree/issues/2620 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can use
permalink_part_changed?
here to change the permalink_part only when it is changed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change that, it's better yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we cannot really use that condition because this method is called also for all children via:
it breaks current test, I will leave it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, can't see any clean solution here. I agree it's better to keep it as is.