Sha256: 03949547100d3f10d127a3d6e6a2222acda360c69b835e9c642b7e65b05b922b

Contents?: true

Size: 1.96 KB

Versions: 43

Compression:

Stored size: 1.96 KB

Contents

require "helper"

class CoreTest < MiniTest::Unit::TestCase
  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

43 entries across 38 versions & 4 rubygems

Version Path
friendly_id-5.0.4 test/base_test.rb
friendly_id-5.0.3 test/base_test.rb
friendly_id-5.0.2 test/base_test.rb
friendly_id-5.0.1 test/base_test.rb
friendly_id-5.0.0 test/base_test.rb
friendly_id-5.0.0.rc3 test/base_test.rb
friendly_id-5.0.0.rc2 test/base_test.rb
mil_friendly_id-4.0.9.9 test/base_test.rb
friendly_id-5.0.0.rc1 test/base_test.rb
friendly_id-5.0.0.beta4 test/base_test.rb
friendly_id-5.0.0.beta3 test/base_test.rb
friendly_id-4.0.10.1 test/base_test.rb
friendly_id-5.0.0.beta2 test/base_test.rb
friendly_id-5.0.0.beta1 test/base_test.rb
friendly_id-4.0.10 test/base_test.rb
friendly_id-5.0.0.alpha.1 test/base_test.rb
mil_friendly_id-4.0.9.8 test/base_test.rb
geothird_friendly_id-4.0.9.8 test/base_test.rb
geothird_friendly_id-4.0.9.7 test/base_test.rb
geothird_friendly_id-4.0.9.6 test/base_test.rb