Skip to content
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

Merged
merged 1 commit into from
Feb 20, 2019

Conversation

loicginoux
Copy link
Contributor

@loicginoux loicginoux commented Feb 8, 2019

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.

Copy link
Member

@kennyadsl kennyadsl left a 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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added

Copy link
Member

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. 🙂

Copy link
Contributor Author

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

@@ -26,6 +26,14 @@
expect(taxon.permalink).to eql "ruby-on-rails"
end

context "updating a taxon permalink" do
it 'parameterize permalink correctly' do
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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. 🙂

Copy link
Member

@kennyadsl kennyadsl left a 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? 🙏

@loicginoux loicginoux force-pushed the fix_taxon_permalink_edition branch from a1627f6 to 584c3da Compare February 11, 2019 16:10
@loicginoux
Copy link
Contributor Author

ok, all in one commit now. thx for the review !

@kennyadsl kennyadsl changed the title parameterize updated taxon permalink Parameterize taxon's permalink also on update Feb 11, 2019
Copy link
Member

@spaghetticode spaghetticode left a 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 👍

Copy link
Member

@kennyadsl kennyadsl left a 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
@loicginoux loicginoux force-pushed the fix_taxon_permalink_edition branch from 584c3da to 01509d4 Compare February 14, 2019 18:31
@loicginoux
Copy link
Contributor Author

Ok I changed commit description and removed one correct grammar on test description

@kennyadsl kennyadsl merged commit ec57c3d into solidusio:master Feb 20, 2019
@kennyadsl
Copy link
Member

Thanks @loicginoux!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants