Sha256: d383d2634ca00a338bf93b01c74b432477e87ed15965aacce1a663b92cb7f86f

Contents?: true

Size: 1.05 KB

Versions: 27

Compression:

Stored size: 1.05 KB

Contents

# encoding: utf-8

require File.dirname(__FILE__) + '/test_helper'

class CustomSlugNormalizerTest < Test::Unit::TestCase

  context "A slugged model using a custom slug generator" do

    setup do
      Thing.friendly_id_options = FriendlyId::DEFAULT_FRIENDLY_ID_OPTIONS.merge(:column => :name, :use_slug => true)
      Thing.delete_all
      Slug.delete_all
    end

    should "invoke the block code" do
      @thing = Thing.create!(:name => "test")
      assert_equal "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", @thing.friendly_id
    end

    should "respect the max_length option" do
      Thing.friendly_id_options = Thing.friendly_id_options.merge(:max_length => 10)
      @thing = Thing.create!(:name => "test")
      assert_equal "a94a8fe5cc", @thing.friendly_id
    end

    should "respect the reserved option" do
      Thing.friendly_id_options = Thing.friendly_id_options.merge(:reserved => ["a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"])
      assert_raises FriendlyId::SlugGenerationError do
        Thing.create!(:name => "test")
      end
    end
  
  end

end

Version data entries

27 entries across 27 versions & 8 rubygems

Version Path
dougcole-friendly_id-2.0.6 test/custom_slug_normalizer_test.rb
nateabbott-friendly_id-2.1.4 test/custom_slug_normalizer_test.rb
nateabbott-friendly_id-2.1.7 test/custom_slug_normalizer_test.rb
nateabbott-friendly_id-2.1.8 test/custom_slug_normalizer_test.rb
nateabbott-nateabbott-friendly_id-2.1.5 test/custom_slug_normalizer_test.rb
nateabbott-nateabbott-friendly_id-2.1.6 test/custom_slug_normalizer_test.rb
norman-friendly_id-2.0.4 test/custom_slug_normalizer_test.rb
norman-friendly_id-2.1.0 test/custom_slug_normalizer_test.rb
norman-friendly_id-2.1.1 test/custom_slug_normalizer_test.rb
norman-friendly_id-2.1.2 test/custom_slug_normalizer_test.rb
norman-friendly_id-2.1.3 test/custom_slug_normalizer_test.rb
norman-friendly_id-2.1.4 test/custom_slug_normalizer_test.rb
nwp-friendly_id-2.1.3 test/custom_slug_normalizer_test.rb
rakutenusa-friendly_id-2.0.6 test/custom_slug_normalizer_test.rb
rakutenusa-friendly_id-2.0.7 test/custom_slug_normalizer_test.rb
rakutenusa-friendly_id-2.0.8 test/custom_slug_normalizer_test.rb
rakutenusa-friendly_id-2.0.9 test/custom_slug_normalizer_test.rb
friendly_id-2.1.5 test/custom_slug_normalizer_test.rb
nateabbott-friendly-id-2.2.1 test/custom_slug_normalizer_test.rb
friendly_id-2.2.1 test/custom_slug_normalizer_test.rb