Skip to content

Commit

Permalink
Add tests for slug regeneration in non scoped record
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Jan 16, 2014
1 parent 547ae17 commit b5bf8f7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/slugged_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@ def model_class
end
end

test "should not allow duplicate slugs after regeneration for persisted record" do
transaction do
model1 = model_class.create! :name => "a"
model2 = model_class.new :name => "a"
model2.save!

model2.send(:set_slug)

This comment has been minimized.

Copy link
@xymbol

xymbol May 28, 2014

Collaborator

@PikachuEXE What is the intention behind these tests? Unless I'm wrong, #set_slug is useless here as it is being protected by the default implementation of #should_generate_new_friendly_id? once slug is set. Then, there're unused variables. I can rewrite these tests but would like to better understand the context. Thanks!

This comment has been minimized.

Copy link
@PikachuEXE

PikachuEXE May 29, 2014

Author Contributor

I guess I should create a new model class and make #should_generate_new_friendly_id? to true to make sure it always set it.

This comment has been minimized.

Copy link
@xymbol

xymbol May 29, 2014

Collaborator

Did that locally but still can't figure out the intention for these tests. Are they regression tests? Also, would be better to override #should_generate_new_friendly_id? for tested instances, not fixture classes.

first_generated_friendly_id = model2.friendly_id
model2.send(:set_slug)
second_generated_friendly_id = model2.friendly_id

assert model1.friendly_id != model2.friendly_id
end
end

test "should not allow duplicate slugs after regeneration for new record" do
transaction do
model1 = model_class.create! :name => "a"
model2 = model_class.new :name => "a"

model2.send(:set_slug)
first_generated_friendly_id = model2.friendly_id
model2.send(:set_slug)
second_generated_friendly_id = model2.friendly_id

assert model1.friendly_id != model2.friendly_id
end
end

end

class SlugSeparatorTest < MiniTest::Unit::TestCase
Expand Down Expand Up @@ -220,7 +249,7 @@ class MenuItem < ActiveRecord::Base
friendly_id :name, :use => :slugged
before_create :init_primary_key

def self.primary_key
def self.primary_key
"string_key"
end

Expand Down

0 comments on commit b5bf8f7

Please sign in to comment.