Skip to content

Commit

Permalink
Add failed tests for slug regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Jan 9, 2014
1 parent b7d2b0c commit 3445b81
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/scoped_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Novel < ActiveRecord::Base
belongs_to :novelist
belongs_to :publisher
friendly_id :name, :use => :scoped, :scope => [:publisher, :novelist]

def should_generate_new_friendly_id?
new_record? || super
end
end

class Publisher < ActiveRecord::Base
Expand Down Expand Up @@ -54,6 +58,36 @@ def model_class
end
end

test "should not allow duplicate slugs inside scope after regeneration for persisted record" do
with_instance_of Novelist do |novelist|
novel1 = Novel.create! :name => "a", :novelist => novelist
novel2 = Novel.new :name => "a", :novelist => novelist
novel2.save!

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

assert novel1.friendly_id != novel2.friendly_id
end
end

test "should not allow duplicate slugs inside scope after regeneration for new record" do
with_instance_of Novelist do |novelist|
novel1 = Novel.create! :name => "a", :novelist => novelist
novel2 = Novel.new :name => "a", :novelist => novelist

novel2.send(:set_slug)
first_generated_friendly_id = novel2.friendly_id
novel2.send(:set_slug)
second_generated_friendly_id = novel2.friendly_id
novel2.save!

assert novel1.friendly_id != novel2.friendly_id
end
end

test "should apply scope with multiple columns" do
transaction do
novelist = Novelist.create! :name => "a"
Expand Down

2 comments on commit 3445b81

@xymbol
Copy link
Collaborator

@xymbol xymbol commented on 3445b81 Jun 2, 2014

Choose a reason for hiding this comment

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

@PikachuEXE Still wondering what these tests are trying to reproduce. Are they valid anymore?

@PikachuEXE
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This validates that the slug regeneration wont produce slug with UUID unnecessary due to query bug
see #513

Please sign in to comment.