friendly_id 1.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +81 -0
- data/MIT-LICENSE +19 -0
- data/Manifest.txt +53 -0
- data/README.rdoc +313 -0
- data/Rakefile +43 -0
- data/coverage/index.html +409 -0
- data/coverage/lib-friendly_id-non_sluggable_class_methods_rb.html +646 -0
- data/coverage/lib-friendly_id-non_sluggable_instance_methods_rb.html +638 -0
- data/coverage/lib-friendly_id-shoulda_macros_rb.html +641 -0
- data/coverage/lib-friendly_id-sluggable_class_methods_rb.html +714 -0
- data/coverage/lib-friendly_id-sluggable_instance_methods_rb.html +710 -0
- data/coverage/lib-friendly_id-string_helpers_rb.html +685 -0
- data/coverage/lib-friendly_id_rb.html +665 -0
- data/coverage/lib-slug_rb.html +695 -0
- data/coverage/rails-init_rb.html +606 -0
- data/friendly_id.gemspec +38 -0
- data/generators/friendly_id/friendly_id_generator.rb +12 -0
- data/generators/friendly_id/templates/create_slugs.rb +18 -0
- data/generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb +11 -0
- data/generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.rb +19 -0
- data/init.rb +1 -0
- data/lib/friendly_id.rb +61 -0
- data/lib/friendly_id/non_sluggable_class_methods.rb +41 -0
- data/lib/friendly_id/non_sluggable_instance_methods.rb +33 -0
- data/lib/friendly_id/shoulda_macros.rb +36 -0
- data/lib/friendly_id/slug.rb +90 -0
- data/lib/friendly_id/sluggable_class_methods.rb +109 -0
- data/lib/friendly_id/sluggable_instance_methods.rb +105 -0
- data/lib/friendly_id/version.rb +8 -0
- data/lib/tasks/friendly_id.rake +48 -0
- data/lib/tasks/friendly_id.rb +1 -0
- data/test/database.yml +3 -0
- data/test/fixtures/countries.yml +4 -0
- data/test/fixtures/country.rb +4 -0
- data/test/fixtures/people.yml +7 -0
- data/test/fixtures/person.rb +6 -0
- data/test/fixtures/post.rb +3 -0
- data/test/fixtures/posts.yml +19 -0
- data/test/fixtures/slugs.yml +45 -0
- data/test/fixtures/user.rb +3 -0
- data/test/fixtures/users.yml +7 -0
- data/test/non_slugged_test.rb +63 -0
- data/test/rails/2.x/app/controllers/application.rb +0 -0
- data/test/rails/2.x/config/boot.rb +109 -0
- data/test/rails/2.x/config/database.yml +3 -0
- data/test/rails/2.x/config/environment.rb +7 -0
- data/test/rails/2.x/config/environments/test.rb +6 -0
- data/test/rails/2.x/config/routes.rb +0 -0
- data/test/schema.rb +38 -0
- data/test/scoped_model_test.rb +21 -0
- data/test/slug_test.rb +87 -0
- data/test/sluggable_test.rb +181 -0
- data/test/test_helper.rb +35 -0
- metadata +155 -0
- metadata.gz.sig +1 -0
| @@ -0,0 +1,6 @@ | |
| 1 | 
            +
            config.cache_classes = true
         | 
| 2 | 
            +
            config.whiny_nils = true
         | 
| 3 | 
            +
            config.action_controller.consider_all_requests_local = true
         | 
| 4 | 
            +
            config.action_controller.perform_caching             = false
         | 
| 5 | 
            +
            config.action_controller.allow_forgery_protection    = false
         | 
| 6 | 
            +
            config.action_mailer.delivery_method = :test
         | 
| 
            File without changes
         | 
    
        data/test/schema.rb
    ADDED
    
    | @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            ActiveRecord::Schema.define(:version => 3) do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              create_table "posts", :force => true do |t|
         | 
| 4 | 
            +
                t.string   "name"
         | 
| 5 | 
            +
                t.text     "content"
         | 
| 6 | 
            +
                t.datetime "created_at"
         | 
| 7 | 
            +
                t.datetime "updated_at"
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              create_table "users", :force => true do |t|
         | 
| 11 | 
            +
                t.string   "login"
         | 
| 12 | 
            +
                t.string   "email"
         | 
| 13 | 
            +
                t.datetime "created_at"
         | 
| 14 | 
            +
                t.datetime "updated_at"
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              create_table "people", :force => true do |t|
         | 
| 18 | 
            +
                t.string "name"
         | 
| 19 | 
            +
                t.integer "country_id"
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              create_table "countries", :force => true do |t|
         | 
| 23 | 
            +
                t.string "name"
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              create_table "slugs", :force => true do |t|
         | 
| 27 | 
            +
                t.string "name"
         | 
| 28 | 
            +
                t.integer "sluggable_id"
         | 
| 29 | 
            +
                t.integer "sequence", :null       => false, :default => 1
         | 
| 30 | 
            +
                t.string "sluggable_type", :limit => 40
         | 
| 31 | 
            +
                t.string "scope", :limit          => 40
         | 
| 32 | 
            +
                t.datetime "created_at"
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              add_index "slugs", ["sluggable_id"], :name           => "index_slugs_on_sluggable_id"
         | 
| 36 | 
            +
              add_index "slugs", ["name", "sluggable_type", "scope", "sequence"], :name => "index_slugs_on_n_s_s_and_s", :unique => true
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class ScopedModelTest < Test::Unit::TestCase
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              fixtures :people, :countries, :slugs
         | 
| 6 | 
            +
              
         | 
| 7 | 
            +
              def test_should_find_scoped_records_without_scope
         | 
| 8 | 
            +
                assert_equal 2, Person.find(:all, "john-smith").size
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def test_should_find_scoped_records_with_scope
         | 
| 12 | 
            +
                assert_equal people(:john_smith), Person.find("john-smith", :scope => "argentina")
         | 
| 13 | 
            +
                assert_equal people(:john_smith2), Person.find("john-smith", :scope => "usa")
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              def test_should_create_scoped_records_with_scope
         | 
| 17 | 
            +
                person = Person.create!(:name => "Joe Schmoe", :country => countries(:usa))
         | 
| 18 | 
            +
                assert_equal "usa", person.slug.scope
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            end
         | 
    
        data/test/slug_test.rb
    ADDED
    
    | @@ -0,0 +1,87 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class SlugTest < Test::Unit::TestCase
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              fixtures :posts, :slugs
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def test_should_indicate_if_it_is_the_most_recent
         | 
| 8 | 
            +
                assert slugs(:two_new).is_most_recent?
         | 
| 9 | 
            +
                assert !slugs(:two_old).is_most_recent?
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def test_parse_should_return_slug_name_and_sequence
         | 
| 13 | 
            +
                assert_equal ["test", "2"], Slug::parse("test--2")
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def test_parse_should_return_a_default_sequnce_of_1
         | 
| 17 | 
            +
                assert_equal ["test", "1"], Slug::parse("test")
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def test_strip_diacritics_should_strip_diacritics
         | 
| 21 | 
            +
                assert_equal "acai", Slug::strip_diacritics("açaí")
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def test_to_friendly_id_should_include_sequence_if_its_greater_than_1
         | 
| 25 | 
            +
                slug = Slug.new(:name => "test", :sequence => 2)
         | 
| 26 | 
            +
                assert_equal "test--2", slug.to_friendly_id
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def test_to_friendly_id_should_include_sequence_if_its_than_1
         | 
| 30 | 
            +
                slug = Slug.new(:name => "test", :sequence => 1)
         | 
| 31 | 
            +
                assert_equal "test", slug.to_friendly_id
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              def test_normalize_should_lowercase_strings
         | 
| 35 | 
            +
                assert_match /abc/, Slug::normalize("ABC")
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def test_normalize_should_replace_whitespace_with_dashes
         | 
| 39 | 
            +
                assert_match /a-b/, Slug::normalize("a b")
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def test_normalize_should_replace_2spaces_with_1dash
         | 
| 43 | 
            +
                assert_match /a-b/, Slug::normalize("a  b")
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              def test_normalize_should_remove_punctuation
         | 
| 47 | 
            +
                assert_match /abc/, Slug::normalize('abc!@#$%^&*•¶§∞¢££¡¿()><?"":;][]\.,/')
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def test_normalize_should_strip_trailing_space
         | 
| 51 | 
            +
                assert_match /ab/, Slug::normalize("ab ")
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              def test_normalize_should_strip_leading_space
         | 
| 55 | 
            +
                assert_match /ab/, Slug::normalize(" ab")
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              def test_normalize_should_strip_trailing_slashes
         | 
| 59 | 
            +
                assert_match /ab/, Slug::normalize("ab-")
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def test_normalize_should_strip_leading_slashes
         | 
| 63 | 
            +
                assert_match /ab/, Slug::normalize("-ab")
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              def test_normalize_should_not_modify_valid_name_strings
         | 
| 67 | 
            +
                assert_match /a-b-c-d/, Slug::normalize("a-b-c-d")
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              # These strings are taken from various international Google homepages. I
         | 
| 71 | 
            +
              # would be most grateful if a fluent speaker of any language that uses a
         | 
| 72 | 
            +
              # writing system other than the Roman alphabet could help me make some
         | 
| 73 | 
            +
              # better tests to ensure this is working correctly.
         | 
| 74 | 
            +
              def test_normalize_works_with_non_roman_chars
         | 
| 75 | 
            +
                assert_equal "検-索", Slug::normalize("検 索")
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def test_strip_diactics_correctly_strips_diacritics
         | 
| 79 | 
            +
                input  = "ÀÁÂÃÄÅÆÇÈÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"
         | 
| 80 | 
            +
                output = Slug::strip_diacritics(input).split(//)
         | 
| 81 | 
            +
                expected = "AAAAAAAECEEEIIIIDNOOOOOOUUUUYThssaaaaaaaeceeeeiiiidnoooooouuuuythy".split(//)
         | 
| 82 | 
            +
                output.split.each_index do |i|
         | 
| 83 | 
            +
                  assert_equal output[i], expected[i]
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
              
         | 
| 87 | 
            +
            end
         | 
| @@ -0,0 +1,181 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class SluggableTest < Test::Unit::TestCase
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              fixtures :posts, :slugs
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def setup
         | 
| 8 | 
            +
                Post.friendly_id_options[:max_length] = FriendlyId::ClassMethods::DEFAULT_FRIENDLY_ID_OPTIONS[:max_length]
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def test_class_should_have_friendly_id_options
         | 
| 12 | 
            +
                assert_not_nil Post.friendly_id_options
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def test_should_generate_slug_text
         | 
| 16 | 
            +
               @post = Post.new(:name => "Test post", :content => "Test content")
         | 
| 17 | 
            +
               assert_equal "test-post", @post.slug_text
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def test_should_save_slug_when_creating
         | 
| 21 | 
            +
                @post = Post.create(:name => "Test post", :content => "Test content")
         | 
| 22 | 
            +
                assert @post.slug
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def test_to_param_should_always_return_a_string
         | 
| 26 | 
            +
                assert_equal String, posts(:without_slug).to_param.class
         | 
| 27 | 
            +
                assert_equal String, posts(:with_one_slug).to_param.class
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def test_finder_options_are_not_ignored
         | 
| 31 | 
            +
                assert_raises ActiveRecord::RecordNotFound do
         | 
| 32 | 
            +
                  Post.find(slugs(:one).name, :conditions => "1 = 2")
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              def test_should_still_be_able_to_find_record_by_id
         | 
| 37 | 
            +
                post = Post.create!(:name => "New post")
         | 
| 38 | 
            +
                Post.create!(:name => "#{post.id.to_s} and some text")
         | 
| 39 | 
            +
                assert_equal post, Post.find(post.id)
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
             | 
| 43 | 
            +
              def test_should_not_be_found_using_friendly_id_by_default
         | 
| 44 | 
            +
                @post = Post.new
         | 
| 45 | 
            +
                assert !@post.found_using_friendly_id?
         | 
| 46 | 
            +
                assert @post.found_using_numeric_id?
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              def test_should_be_using_friendly_id_when_find_arg_is_an_array
         | 
| 50 | 
            +
                @posts = Post.find([posts(:with_one_slug).friendly_id, posts(:with_two_slugs).friendly_id])
         | 
| 51 | 
            +
                assert @posts.all? { |post| post.found_using_friendly_id? }
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              def test_raises_active_record_not_found_when_not_all_records_found
         | 
| 55 | 
            +
                assert_raises(ActiveRecord::RecordNotFound) do
         | 
| 56 | 
            +
                  Post.find([posts(:with_one_slug).slug.name, 'non-existant-slug-record'])
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              def test_should_indicate_if_it_was_found_using_numeric_id
         | 
| 61 | 
            +
                @post = Post.find(posts(:with_two_slugs).id)
         | 
| 62 | 
            +
                assert @post.found_using_numeric_id?
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              def test_post_should_indicate_if_it_was_found_using_friendly_id
         | 
| 66 | 
            +
                @post = Post.find(posts(:with_two_slugs).slug.name)
         | 
| 67 | 
            +
                assert @post.found_using_friendly_id?
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              def test_post_should_indicate_if_it_was_found_using_outdated_friendly_id
         | 
| 71 | 
            +
                @post = Post.find(posts(:with_two_slugs).slugs.last.name)
         | 
| 72 | 
            +
                assert @post.found_using_outdated_friendly_id?
         | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
              def test_should_indicate_there_is_a_better_id_if_found_by_numeric_id
         | 
| 76 | 
            +
                @post = Post.find(posts(:with_one_slug).id)
         | 
| 77 | 
            +
                assert @post.has_better_id?
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              def test_should_indicate_there_is_a_better_id_if_found_by_outdated_friendly_id
         | 
| 81 | 
            +
                @post = Post.find(posts(:with_two_slugs).slugs.last.name)
         | 
| 82 | 
            +
                assert @post.has_better_id?
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              def test_slug_should_always_be_the_most_recent
         | 
| 86 | 
            +
                @post = Post.find(posts(:with_two_slugs).slug.name)
         | 
| 87 | 
            +
                assert !@post.has_better_id?
         | 
| 88 | 
            +
                assert slugs(:two_new).name, @post.slug.name
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              def test_should_strip_diactics_from_slug_if_configured_to_do_so
         | 
| 92 | 
            +
                Post.friendly_id_options[:strip_diacritics] = true
         | 
| 93 | 
            +
                @post = Post.new(:name => "¡FELIZ AÑO!")
         | 
| 94 | 
            +
                # Happy anus to you too
         | 
| 95 | 
            +
                assert_equal "feliz-ano", @post.slug_text
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              def test_should_not_strip_diactics_from_slug_unless_configured_to_do_so
         | 
| 99 | 
            +
                Post.friendly_id_options[:strip_diacritics] = false
         | 
| 100 | 
            +
                @post = Post.new(:name => "¡FELIZ AÑO!")
         | 
| 101 | 
            +
                assert_equal "feliz-año", @post.slug_text
         | 
| 102 | 
            +
              end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
              def test_should_not_make_new_slug_unless_friendly_id_method_has_changed
         | 
| 105 | 
            +
                posts(:with_one_slug).content = "Edited content"
         | 
| 106 | 
            +
                posts(:with_one_slug).save!
         | 
| 107 | 
            +
                assert_equal 1, posts(:with_one_slug).slugs.size
         | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              def test_post_should_make_new_slug_if_friendly_id_method_is_changed
         | 
| 111 | 
            +
                posts(:with_one_slug).name = "Edited name"
         | 
| 112 | 
            +
                posts(:with_one_slug).save!
         | 
| 113 | 
            +
                assert_equal 2, posts(:with_one_slug).slugs.size
         | 
| 114 | 
            +
              end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              def test_should_increment_sequence_for_duplicate_slugs
         | 
| 117 | 
            +
                @post = Post.create!(:name => slugs(:one).name, :content => "stuff")
         | 
| 118 | 
            +
                assert_equal 2, @post.slug.sequence
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
              def test_friendly_id_should_contain_sequence_unless_its_1
         | 
| 122 | 
            +
                @post = Post.create!(:name => slugs(:one).name, :content => "stuff")
         | 
| 123 | 
            +
                assert_equal "#{slugs(:one).name}--2", @post.friendly_id
         | 
| 124 | 
            +
              end
         | 
| 125 | 
            +
             | 
| 126 | 
            +
              def test_should_truncate_slugs_longer_than_maxlength
         | 
| 127 | 
            +
                Post.friendly_id_options[:max_length] = 10
         | 
| 128 | 
            +
                @post = Post.new(:name => "x" * 11, :content => "Test content")
         | 
| 129 | 
            +
                assert @post.slug_text.length <= Post.friendly_id_options[:max_length]
         | 
| 130 | 
            +
              end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
              def test_should_ensure_truncated_slugs_that_collide_have_different_sequences
         | 
| 133 | 
            +
                Post.friendly_id_options[:max_length] = 2
         | 
| 134 | 
            +
                p = Post.create!(:name => "aaa")
         | 
| 135 | 
            +
                q = Post.create!(:name => "aaab")
         | 
| 136 | 
            +
                assert_not_equal p.friendly_id, q.friendly_id
         | 
| 137 | 
            +
                assert_equal p.slug.name, q.slug.name
         | 
| 138 | 
            +
                assert_not_equal p.slug.sequence, q.slug.sequence
         | 
| 139 | 
            +
              end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
              def test_should_be_able_to_rename_back_to_old_friendly_id
         | 
| 142 | 
            +
                p = Post.create!(:name => "value")
         | 
| 143 | 
            +
                assert_equal "value", p.friendly_id
         | 
| 144 | 
            +
                p.name = "different value"
         | 
| 145 | 
            +
                p.save!
         | 
| 146 | 
            +
                p.reload
         | 
| 147 | 
            +
                assert_equal "different-value", p.friendly_id
         | 
| 148 | 
            +
                p.name = "value"
         | 
| 149 | 
            +
                assert p.save!
         | 
| 150 | 
            +
                p.reload
         | 
| 151 | 
            +
                assert_equal "value", p.friendly_id
         | 
| 152 | 
            +
              end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
              def test_should_raise_error_if_friendly_id_is_blank
         | 
| 155 | 
            +
                assert_raises(FriendlyId::SlugGenerationError) do
         | 
| 156 | 
            +
                  Post.create(:name => nil)
         | 
| 157 | 
            +
                end
         | 
| 158 | 
            +
              end
         | 
| 159 | 
            +
             | 
| 160 | 
            +
              def test_should_raise_error_if_normalized_friendly_id_becomes_blank
         | 
| 161 | 
            +
                assert_raises(FriendlyId::SlugGenerationError) do
         | 
| 162 | 
            +
                  post = Post.create!(:name => "-.-")
         | 
| 163 | 
            +
                end
         | 
| 164 | 
            +
              end
         | 
| 165 | 
            +
             | 
| 166 | 
            +
              def test_should_raise_error_if_slug_text_is_reserved
         | 
| 167 | 
            +
                assert_raises(FriendlyId::SlugGenerationError) do
         | 
| 168 | 
            +
                  Post.create(:name => "new")
         | 
| 169 | 
            +
                end
         | 
| 170 | 
            +
              end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
              def test_should_allow_eager_loading_of_slugs
         | 
| 173 | 
            +
                assert_nothing_raised do
         | 
| 174 | 
            +
                  Post.find(slugs(:one).name, :include => :slugs)
         | 
| 175 | 
            +
                end
         | 
| 176 | 
            +
                assert_nothing_raised do
         | 
| 177 | 
            +
                  Post.find([slugs(:one).name, slugs(:two_new).name], :include => :slugs)
         | 
| 178 | 
            +
                end
         | 
| 179 | 
            +
              end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
            end
         | 
    
        data/test/test_helper.rb
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            $:.unshift(File.dirname(__FILE__) + '/../lib')
         | 
| 2 | 
            +
            $VERBOSE = false
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ENV['RAILS_ENV'] = 'test'
         | 
| 5 | 
            +
            require File.dirname(__FILE__) + '/rails/2.x/config/environment.rb'
         | 
| 6 | 
            +
            ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'test/unit'
         | 
| 9 | 
            +
            require 'active_record/fixtures'
         | 
| 10 | 
            +
            require 'action_controller/test_process'
         | 
| 11 | 
            +
            require 'sqlite3'
         | 
| 12 | 
            +
            require 'friendly_id/slug'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
         | 
| 15 | 
            +
            ActiveRecord::Base.establish_connection
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            silence_stream(STDOUT) do
         | 
| 18 | 
            +
              load(File.dirname(__FILE__) + "/schema.rb")
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures"
         | 
| 22 | 
            +
            $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            class Test::Unit::TestCase #:nodoc:
         | 
| 25 | 
            +
              include ActionController::TestProcess
         | 
| 26 | 
            +
              def create_fixtures(*table_names)
         | 
| 27 | 
            +
                if block_given?
         | 
| 28 | 
            +
                  Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
         | 
| 29 | 
            +
                else
         | 
| 30 | 
            +
                  Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
              self.use_transactional_fixtures = true
         | 
| 34 | 
            +
              self.use_instantiated_fixtures  = false
         | 
| 35 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,155 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: friendly_id
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              version: 1.9.9
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors: 
         | 
| 7 | 
            +
            - Norman Clarke
         | 
| 8 | 
            +
            - Adrian Mugnolo
         | 
| 9 | 
            +
            - Emilio Tagua
         | 
| 10 | 
            +
            autorequire: 
         | 
| 11 | 
            +
            bindir: bin
         | 
| 12 | 
            +
            cert_chain: 
         | 
| 13 | 
            +
            - |
         | 
| 14 | 
            +
              -----BEGIN CERTIFICATE-----
         | 
| 15 | 
            +
              MIIDNDCCAhygAwIBAgIBADANBgkqhkiG9w0BAQUFADBAMQ8wDQYDVQQDDAZub3Jt
         | 
| 16 | 
            +
              YW4xGDAWBgoJkiaJk/IsZAEZFghyYW5kb21iYTETMBEGCgmSJomT8ixkARkWA29y
         | 
| 17 | 
            +
              ZzAeFw0wODA3MjUxOTEyMDJaFw0wOTA3MjUxOTEyMDJaMEAxDzANBgNVBAMMBm5v
         | 
| 18 | 
            +
              cm1hbjEYMBYGCgmSJomT8ixkARkWCHJhbmRvbWJhMRMwEQYKCZImiZPyLGQBGRYD
         | 
| 19 | 
            +
              b3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0MuX/i3u1A7Gu2pC
         | 
| 20 | 
            +
              y3tUIeGen3nJ8KrMpugJ2bo/VRcOLwo3bQl742idpfUE/Wq3rXexxc0Dg9jKQ8yb
         | 
| 21 | 
            +
              1vHqM0s29UmC+UJjKG87eqQDXiq8jHgRcvykGmTZE8GBAVYvm0Wsm7aXWW6hMM/z
         | 
| 22 | 
            +
              9QnhZHmBjCaBb8LXsXCgNHFctKkbtxmEXQk2j9pfWuMVSWVVXJR8Nd03u8G2k4RS
         | 
| 23 | 
            +
              DhvPTP0eAsWRda/6oxGm+QDYv1tfwDVtqUEgD0zFFlpqJcJiKjn/vquJc8tPMYwK
         | 
| 24 | 
            +
              E7eh4J9cT83sgTGs65l9e2Z9cF920DQMJmkzSAVpm7LKSglfO+WWGQlpagZbcC3J
         | 
| 25 | 
            +
              hoR5WQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU
         | 
| 26 | 
            +
              axQXpjRK4llQWMZYVQvaZIJ7/a0wDQYJKoZIhvcNAQEFBQADggEBABappQnc8jtY
         | 
| 27 | 
            +
              ZjbWN1Ya8emsRx2w//Z0LElusQ4PjBfWOzDjQ/BM6JjBA0tC1UyDISpTxD507lZ8
         | 
| 28 | 
            +
              ydTETFAbzTrjJwBwwc1fxwgNm6MZQkZ/7A6WO7OfQw+nkiEaDw7fa10Gd4DBCqhY
         | 
| 29 | 
            +
              Ot72besSspWtxuzTkpl/9YjbUk/XGL2ZjONUUsdzig12eGA659E0AM7LreIiLvSu
         | 
| 30 | 
            +
              EI6rjC8mzEcTVXpeZKtVL5Ba7JSpWT5ojVXF8b4+5o3W5iSH2s4vWeRCS3KK3cww
         | 
| 31 | 
            +
              sJ9/D9IfrPBgbrLYAldiZhGbSxBmwc6mbpPxWaT7SKRbw+XhSGhEeYbBcJs+8gvo
         | 
| 32 | 
            +
              h7fbBRfStxI=
         | 
| 33 | 
            +
              -----END CERTIFICATE-----
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            date: 2008-12-19 00:00:00 -02:00
         | 
| 36 | 
            +
            default_executable: 
         | 
| 37 | 
            +
            dependencies: 
         | 
| 38 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 39 | 
            +
              name: unicode
         | 
| 40 | 
            +
              type: :runtime
         | 
| 41 | 
            +
              version_requirement: 
         | 
| 42 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 43 | 
            +
                requirements: 
         | 
| 44 | 
            +
                - - ">="
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 46 | 
            +
                    version: "0.1"
         | 
| 47 | 
            +
                version: 
         | 
| 48 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 49 | 
            +
              name: hoe
         | 
| 50 | 
            +
              type: :development
         | 
| 51 | 
            +
              version_requirement: 
         | 
| 52 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 53 | 
            +
                requirements: 
         | 
| 54 | 
            +
                - - ">="
         | 
| 55 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 56 | 
            +
                    version: 1.8.2
         | 
| 57 | 
            +
                version: 
         | 
| 58 | 
            +
            description: A comprehensive slugging and pretty-URL plugin for Ruby on Rails.
         | 
| 59 | 
            +
            email: 
         | 
| 60 | 
            +
            - norman@randomba.org
         | 
| 61 | 
            +
            - adrian@randomba.org
         | 
| 62 | 
            +
            - miloops@gmail.com
         | 
| 63 | 
            +
            executables: []
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            extensions: []
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            extra_rdoc_files: 
         | 
| 68 | 
            +
            - History.txt
         | 
| 69 | 
            +
            - Manifest.txt
         | 
| 70 | 
            +
            files: 
         | 
| 71 | 
            +
            - History.txt
         | 
| 72 | 
            +
            - MIT-LICENSE
         | 
| 73 | 
            +
            - Manifest.txt
         | 
| 74 | 
            +
            - README.rdoc
         | 
| 75 | 
            +
            - Rakefile
         | 
| 76 | 
            +
            - coverage/index.html
         | 
| 77 | 
            +
            - coverage/lib-friendly_id-non_sluggable_class_methods_rb.html
         | 
| 78 | 
            +
            - coverage/lib-friendly_id-non_sluggable_instance_methods_rb.html
         | 
| 79 | 
            +
            - coverage/lib-friendly_id-shoulda_macros_rb.html
         | 
| 80 | 
            +
            - coverage/lib-friendly_id-sluggable_class_methods_rb.html
         | 
| 81 | 
            +
            - coverage/lib-friendly_id-sluggable_instance_methods_rb.html
         | 
| 82 | 
            +
            - coverage/lib-friendly_id-string_helpers_rb.html
         | 
| 83 | 
            +
            - coverage/lib-friendly_id_rb.html
         | 
| 84 | 
            +
            - coverage/lib-slug_rb.html
         | 
| 85 | 
            +
            - coverage/rails-init_rb.html
         | 
| 86 | 
            +
            - friendly_id.gemspec
         | 
| 87 | 
            +
            - generators/friendly_id/friendly_id_generator.rb
         | 
| 88 | 
            +
            - generators/friendly_id/templates/create_slugs.rb
         | 
| 89 | 
            +
            - generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb
         | 
| 90 | 
            +
            - generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.rb
         | 
| 91 | 
            +
            - init.rb
         | 
| 92 | 
            +
            - lib/friendly_id.rb
         | 
| 93 | 
            +
            - lib/friendly_id/non_sluggable_class_methods.rb
         | 
| 94 | 
            +
            - lib/friendly_id/non_sluggable_instance_methods.rb
         | 
| 95 | 
            +
            - lib/friendly_id/shoulda_macros.rb
         | 
| 96 | 
            +
            - lib/friendly_id/slug.rb
         | 
| 97 | 
            +
            - lib/friendly_id/sluggable_class_methods.rb
         | 
| 98 | 
            +
            - lib/friendly_id/sluggable_instance_methods.rb
         | 
| 99 | 
            +
            - lib/friendly_id/version.rb
         | 
| 100 | 
            +
            - lib/tasks/friendly_id.rake
         | 
| 101 | 
            +
            - lib/tasks/friendly_id.rb
         | 
| 102 | 
            +
            - test/database.yml
         | 
| 103 | 
            +
            - test/fixtures/countries.yml
         | 
| 104 | 
            +
            - test/fixtures/country.rb
         | 
| 105 | 
            +
            - test/fixtures/people.yml
         | 
| 106 | 
            +
            - test/fixtures/person.rb
         | 
| 107 | 
            +
            - test/fixtures/post.rb
         | 
| 108 | 
            +
            - test/fixtures/posts.yml
         | 
| 109 | 
            +
            - test/fixtures/slugs.yml
         | 
| 110 | 
            +
            - test/fixtures/user.rb
         | 
| 111 | 
            +
            - test/fixtures/users.yml
         | 
| 112 | 
            +
            - test/non_slugged_test.rb
         | 
| 113 | 
            +
            - test/rails/2.x/app/controllers/application.rb
         | 
| 114 | 
            +
            - test/rails/2.x/config/boot.rb
         | 
| 115 | 
            +
            - test/rails/2.x/config/database.yml
         | 
| 116 | 
            +
            - test/rails/2.x/config/environment.rb
         | 
| 117 | 
            +
            - test/rails/2.x/config/environments/test.rb
         | 
| 118 | 
            +
            - test/rails/2.x/config/routes.rb
         | 
| 119 | 
            +
            - test/schema.rb
         | 
| 120 | 
            +
            - test/scoped_model_test.rb
         | 
| 121 | 
            +
            - test/slug_test.rb
         | 
| 122 | 
            +
            - test/sluggable_test.rb
         | 
| 123 | 
            +
            - test/test_helper.rb
         | 
| 124 | 
            +
            has_rdoc: true
         | 
| 125 | 
            +
            homepage: http://randomba.org
         | 
| 126 | 
            +
            post_install_message: 
         | 
| 127 | 
            +
            rdoc_options: 
         | 
| 128 | 
            +
            - --main
         | 
| 129 | 
            +
            - README.txt
         | 
| 130 | 
            +
            require_paths: 
         | 
| 131 | 
            +
            - lib
         | 
| 132 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 133 | 
            +
              requirements: 
         | 
| 134 | 
            +
              - - ">="
         | 
| 135 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 136 | 
            +
                  version: "0"
         | 
| 137 | 
            +
              version: 
         | 
| 138 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 139 | 
            +
              requirements: 
         | 
| 140 | 
            +
              - - ">="
         | 
| 141 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 142 | 
            +
                  version: "0"
         | 
| 143 | 
            +
              version: 
         | 
| 144 | 
            +
            requirements: []
         | 
| 145 | 
            +
             | 
| 146 | 
            +
            rubyforge_project: friendly-id
         | 
| 147 | 
            +
            rubygems_version: 1.3.1
         | 
| 148 | 
            +
            signing_key: 
         | 
| 149 | 
            +
            specification_version: 2
         | 
| 150 | 
            +
            summary: A comprehensive slugging and pretty-URL plugin for Ruby on Rails.
         | 
| 151 | 
            +
            test_files: 
         | 
| 152 | 
            +
            - test/non_slugged_test.rb
         | 
| 153 | 
            +
            - test/scoped_model_test.rb
         | 
| 154 | 
            +
            - test/slug_test.rb
         | 
| 155 | 
            +
            - test/sluggable_test.rb
         |