-
-
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
Parameterize taxon's permalink also on update #3090
Conversation
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.
Thanks, just left some questions/comments.
permalink_tail = permalink.split('/').last if permalink.present? | ||
permalink_tail ||= Spree::Config.taxon_url_parametizer_class.parameterize(name) | ||
self.permalink_part = permalink_tail | ||
permalink_tail = permalink.present? ? permalink.split('/').last : name |
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:
after_update :update_child_permalinks, if: :saved_change_to_permalink?
...
def update_permalinks
set_permalink
# This will trigger update_child_permalinks if permalink has changed
save!
end
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.
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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 spécial&charactèrs/child
for example) so we can see the parameterization reflected on those taxons as well. Anyway the test you added can stay, better to have that as well. 🙂
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 added 2 more tests
core/spec/models/spree/taxon_spec.rb
Outdated
@@ -26,6 +26,14 @@ | |||
expect(taxon.permalink).to eql "ruby-on-rails" | |||
end | |||
|
|||
context "updating a taxon permalink" do | |||
it 'parameterize permalink correctly' do |
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.
it's parameterizes
here, right?
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.
yes updated
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 comment
The 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 spécial&charactèrs/child
for example) so we can see the parameterization reflected on those taxons as well. Anyway the test you added can stay, better to have that as well. 🙂
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.
Thanks, last thing and I'll be ok. Can we squash commits into a single one, please? 🙏
a1627f6
to
584c3da
Compare
ok, all in one commit now. thx for the review ! |
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.
@loicginoux thanks for this PR! 🍰
I noticed that the commit includes the sentence correct grammar on test description
twice, can please fix it?
Again, thanks for the changes 👍
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 think this works, please address the @spaghetticode comment if you have time.
add test for parameterize taxon permalink when taxon parent solidusio#3086 correct grammar on test description test parameterization on children taxon permalink solidusio#3086
584c3da
to
01509d4
Compare
Ok I changed commit description and removed one |
Thanks @loicginoux! |
Description
fix bug #3086
the fix allows to use the
Spree::Config.taxon_url_parametizer_class
on taxon permalink update, and not only on the name. We insure permalink is always parameterized on save.