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

Scoped slug regeneration gives wrong slug #512

Closed
PikachuEXE opened this issue Jan 9, 2014 · 1 comment
Closed

Scoped slug regeneration gives wrong slug #512

PikachuEXE opened this issue Jan 9, 2014 · 1 comment

Comments

@PikachuEXE
Copy link
Contributor

Rails 4.0.2, FriendlyId 5.0.2

Config:

config.use Module.new {
     def should_generate_new_friendly_id?
       slug.blank? || new_record?
     end
  }

Test Result:

b1=FactoryGirl.create(:building)
b1.slug
#=> "building-1"

b2=FactoryGirl.build(:building, neighbourhood: b1.neighbourhood, name: b1.name)
b2.send(:set_slug)
Building Exists (0.8ms)  SELECT 1 AS one FROM "buildings" WHERE "buildings"."neighbourhood_id" = 4 AND "buildings"."slug" = 'building-2' LIMIT 1
#=> "building-1--91415ad1-565b-43d6-9a4b-e8a23df3c041"

b2.send(:set_slug)
Building Exists (0.6ms)  SELECT 1 AS one FROM "buildings" WHERE "buildings"."neighbourhood_id" = 4 AND ("buildings"."id" <> NULL) AND "buildings"."slug" = 'building-2' LIMIT 1
#=> "building-1"

Model:

class Building
  include FriendlyId

  belongs_to :neighbourhood
  friendly_id :name_en, use: [:scoped], scope: :neighbourhood
end
@PikachuEXE
Copy link
Contributor Author

Failed test added
PikachuEXE@a958dc9

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

No branches or pull requests

1 participant