-
-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for slug regeneration in non scoped record
- Loading branch information
1 parent
547ae17
commit b5bf8f7
Showing
1 changed file
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
PikachuEXE
Author
Contributor
|
||
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 | ||
|
@@ -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 | ||
|
||
|
@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!