0
@@ -8,130 +8,126 @@ class SluggableTest < Test::Unit::TestCase
0
Post.friendly_id_options[:max_length] = FriendlyId::ClassMethods::DEFAULT_FRIENDLY_ID_OPTIONS[:max_length]
0
- # This test fails right now because this fix has not been implemented
0
- # for sluggable models, only non-sluggable models. The failing test is here
0
- # as a reminder to FIX THE CODE, but I don't have time to do it right now.
0
- # The test is temporarily commented out so as not to break anybody's build.
0
- # def test_finder_options_are_not_ignored
0
- # assert_raises ActiveRecord::RecordNotFound do
0
- # Post.find_using_friendly_id(slugs(:one).name, :conditions => "1 = 2")
0
+ def test_finder_options_are_not_ignored
0
+ assert_raises ActiveRecord::RecordNotFound do
0
+ Post.find(slugs(:one).name, :conditions => "1 = 2")
0
def test_post_should_generate_friendly_id
0
@post = Post.new(:name => "Test post", :content => "Test content")
0
assert_equal "test-post", @post.generate_friendly_id
0
assert_equal "Test post", @post.name
0
def test_post_should_have_friendly_id_options
0
assert_not_nil Post.friendly_id_options
0
def test_slug_should_not_have_friendly_id_options
0
assert_raises NoMethodError do
0
Slug.friendly_id_options
0
def test_post_should_not_be_found_using_friendly_id_unless_it_really_was
0
assert !@post.found_using_friendly_id?
0
def test_posts_should_be_using_friendly_id_when_given_as_array
0
@posts = Post.find([posts(:with_one_slug).slug.name, posts(:with_two_slugs).slug.name])
0
assert @posts.all? { |post| post.found_using_friendly_id? }
0
def test_posts_raises_active_record_not_found_when_not_all_records_found
0
assert_raises(ActiveRecord::RecordNotFound) do
0
Post.find([posts(:with_one_slug).slug.name, 'non-existant-slug-record'])
0
def test_post_should_be_considered_found_by_numeric_id_as_default
0
assert @post.found_using_numeric_id?
0
def test_post_should_indicate_if_it_was_found_using_numeric_id
0
@post = Post.find(posts(:with_two_slugs).id)
0
assert @post.found_using_numeric_id?
0
def test_post_should_indicate_if_it_was_found_using_friendly_id
0
@post = Post.find(posts(:with_two_slugs).slug.name)
0
assert @post.found_using_friendly_id?
0
def test_post_should_indicate_if_it_was_found_using_outdated_friendly_id
0
@post = Post.find(posts(:with_two_slugs).slugs.last.name)
0
assert @post.found_using_outdated_friendly_id?
0
def test_should_indicate_there_is_a_better_id_if_found_by_numeric_id
0
@post = Post.find(posts(:with_one_slug).id)
0
assert @post.has_better_id?
0
def test_should_indicate_there_is_a_better_id_if_found_by_outdated_friendly_id
0
@post = Post.find(posts(:with_two_slugs).slugs.last.name)
0
assert @post.has_better_id?
0
def test_should_indicate_correct_best_id
0
@post = Post.find(posts(:with_two_slugs).slug.name)
0
assert !@post.has_better_id?
0
assert slugs(:two_new).name, @post.slug.name
0
def test_should_strip_diactics_from_slug
0
Post.friendly_id_options[:strip_diacritics] = true
0
@post = Post.new(:name => "ÀÁÂÃÄÅÆÇÈÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ", :content => "Test content")
0
assert_equal "aaaaaaaeceeeiiiidnoooooouuuuythssaaaaaaaeceeeeiiiidnoooooouuuuythy", @post.generate_friendly_id
0
def test_should_not_strip_diactics_from_slug
0
Post.friendly_id_options[:strip_diacritics] = false
0
@post = Post.new(:name => "ÀÁÂÃÄÅÆÇÈÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ", :content => "Test content")
0
assert_equal "ÀÁÂÃÄÅÆÇÈÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ", @post.generate_friendly_id
0
def test_post_should_not_make_new_slug_if_name_is_unchanged
0
posts(:with_one_slug).content = "Edited content"
0
posts(:with_one_slug).save!
0
assert_equal 1, posts(:with_one_slug).slugs.size
0
def test_post_should_make_new_slug_if_name_is_changed
0
posts(:with_one_slug).name = "Edited name"
0
posts(:with_one_slug).save!
0
assert_equal 2, posts(:with_one_slug).slugs.size
0
def test_should_not_consider_substrings_as_duplicate_slugs
0
@substring = slugs(:one).name[0, slugs(:one).name.length - 1]
0
@post = Post.new(:name => @substring, :content => "stuff")
0
assert_equal @substring, @post.generate_friendly_id
0
def test_should_append_extension_to_duplicate_slugs
0
@post = Post.new(:name => slugs(:one).name, :content => "stuff")
0
assert_equal slugs(:one).name + "-2", @post.generate_friendly_id
0
def test_should_create_post_with_slug
0
@post = Post.create(:name => "Test post", :content => "Test content")
0
assert_not_nil @post.slug
0
def test_should_truncate_slugs_longer_than_maxlength
0
Post.friendly_id_options[:max_length] = 10
0
@post = Post.new(:name => "x" * 11, :content => "Test content")
0
assert @post.generate_friendly_id.length <= Post.friendly_id_options[:max_length]
0
def test_should_ensure_truncated_slugs_are_unique
0
max_length = posts(:with_one_slug).friendly_id.length
0
Post.friendly_id_options[:max_length] = max_length
0
@@ -141,7 +137,7 @@ class SluggableTest < Test::Unit::TestCase
0
assert_not_equal posts(:with_one_slug).friendly_id, q.friendly_id
0
assert_not_equal p.friendly_id, q.friendly_id
0
def test_should_be_able_to_rename_back_to_old_friendly_id
0
p = Post.create!(:name => "value")
0
assert_equal "value", p.friendly_id
0
@@ -154,7 +150,7 @@ class SluggableTest < Test::Unit::TestCase
0
assert_equal "value", p.friendly_id
0
def test_should_avoid_extention_collisions
0
Post.create!(:name => "Post 2/4")
0
assert Post.create!(:name => "Post")
0
@@ -164,17 +160,17 @@ class SluggableTest < Test::Unit::TestCase
0
assert Post.create!(:name => "Post-2-2")
0
assert Post.create!(:name => "Post 2/4")
0
def test_slug_should_indicate_if_it_is_the_most_recent
0
assert slugs(:two_new).is_most_recent?
0
def test_should_raise_error_if_friendly_is_base_is_blank
0
assert_raises(FriendlyId::SlugGenerationError) do
0
Post.create(:name => nil)
0
def test_should_not_use_reserved_slugs
0
post = Post.create!(:name => 'new')
0
assert_not_equal 'new', post.friendly_id
whoops.
Yes indeed. Fixed in the latest commit. :-)