Skip to content

Commit

Permalink
parameterize updated taxon permalink #3086
Browse files Browse the repository at this point in the history
add test for parameterize taxon permalink when taxon parent #3086

correct grammar on test description

test parameterization on children taxon permalink #3086
  • Loading branch information
loicginoux committed Feb 14, 2019
1 parent 4c9f71f commit 01509d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/app/models/spree/taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def seo_title
# Sets this taxons permalink to a valid url encoded string based on its
# name and its parents permalink (if present.)
def set_permalink
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
self.permalink_part = Spree::Config.taxon_url_parametizer_class.parameterize(permalink_tail)
end

# Update the permalink for this taxon and all children (if necessary)
Expand Down
28 changes: 28 additions & 0 deletions core/spec/models/spree/taxon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

context "with parent taxon" do
let(:parent) { FactoryBot.build(:taxon, permalink: "brands") }
before { allow(taxon).to receive_messages parent: parent }
Expand All @@ -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) }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01509d4

Please sign in to comment.