Sha256: b6228c376dead0ccad13e31ee7218c85ee673adf027639c3d6c4b3636f849d29

Contents?: true

Size: 1.95 KB

Versions: 12

Compression:

Stored size: 1.95 KB

Contents

require "helper"

class CoreTest < TestCaseClass
  include FriendlyId::Test

  test "friendly_id can be added using 'extend'" do
    klass = Class.new(ActiveRecord::Base) do
      extend FriendlyId
    end
    assert klass.respond_to? :friendly_id
  end

  test "friendly_id can be added using 'include'" do
    klass = Class.new(ActiveRecord::Base) do
      include FriendlyId
    end
    assert klass.respond_to? :friendly_id
  end

  test "friendly_id should accept a base and a hash" do
    klass = Class.new(ActiveRecord::Base) do
      self.abstract_class = true
      extend FriendlyId
      friendly_id :foo, :use => :slugged, :slug_column => :bar
    end
    assert klass < FriendlyId::Slugged
    assert_equal :foo, klass.friendly_id_config.base
    assert_equal :bar, klass.friendly_id_config.slug_column
  end


  test "friendly_id should accept a block" do
    klass = Class.new(ActiveRecord::Base) do
      self.abstract_class = true
      extend FriendlyId
      friendly_id :foo do |config|
        config.use :slugged
        config.base = :foo
        config.slug_column = :bar
      end
    end
    assert klass < FriendlyId::Slugged
    assert_equal :foo, klass.friendly_id_config.base
    assert_equal :bar, klass.friendly_id_config.slug_column
  end

  test "the block passed to friendly_id should be evaluated before arguments" do
    klass = Class.new(ActiveRecord::Base) do
      self.abstract_class = true
      extend FriendlyId
      friendly_id :foo do |config|
        config.base = :bar
      end
    end
    assert_equal :foo, klass.friendly_id_config.base
  end

  test "should allow defaults to be set via a block" do
    begin
      FriendlyId.defaults do |config|
        config.base = :foo
      end
      klass = Class.new(ActiveRecord::Base) do
        self.abstract_class = true
        extend FriendlyId
      end
      assert_equal :foo, klass.friendly_id_config.base
    ensure
      FriendlyId.instance_variable_set :@defaults, nil
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
friendly_id-5.4.2 test/base_test.rb
friendly_id-5.4.1 test/base_test.rb
friendly_id-5.4.0 test/base_test.rb
friendly_id-5.3.0 test/base_test.rb
friendly_id-5.2.5 test/base_test.rb
friendly_id-5.2.4 test/base_test.rb
friendly_id-5.2.3 test/base_test.rb
friendly_id-5.2.2 test/base_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/friendly_id-5.2.1/test/base_test.rb
friendly_id-5.2.1 test/base_test.rb
friendly_id-5.2.0 test/base_test.rb
friendly_id-5.2.0.beta.1 test/base_test.rb