Sha256: 2e776f4e7a62e08f1bdabbe5d1ca2daf0cd041f8d2486a2e3075aa961555ab0e

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

require "helper"

class ConfigurationTest < MiniTest::Unit::TestCase

  include FriendlyId::Test

  def setup
    @model_class = Class.new(ActiveRecord::Base) do
      self.abstract_class = true
    end
  end

  test "should set model class on initialization" do
    config = FriendlyId::Configuration.new @model_class
    assert_equal @model_class, config.model_class
  end

  test "should set options on initialization if present" do
    config = FriendlyId::Configuration.new @model_class, :base => "hello"
    assert_equal "hello", config.base
  end

  test "should raise error if passed unrecognized option" do
    assert_raises NoMethodError do
      FriendlyId::Configuration.new @model_class, :foo => "bar"
    end
  end

  test "#use should accept a name that resolves to a module" do
    refute @model_class < FriendlyId::Slugged
    @model_class.class_eval do
      extend FriendlyId
      friendly_id :hello, :use => :slugged
    end
    assert @model_class < FriendlyId::Slugged
  end

  test "#use should accept a module" do
    my_module = Module.new
    refute @model_class < my_module
    @model_class.class_eval do
      extend FriendlyId
      friendly_id :hello, :use => my_module
    end
    assert @model_class < my_module
  end

  test "#base should optionally set a value" do
    config = FriendlyId::Configuration.new @model_class
    assert_nil config.base
    config.base = 'foo'
    assert_equal 'foo', config.base
  end

  test "#base can set the value to nil" do
    config = FriendlyId::Configuration.new @model_class
    config.base 'foo'
    config.base nil
    assert_nil config.base

  end


end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
friendly_id-5.0.4 test/configuration_test.rb
friendly_id-5.0.3 test/configuration_test.rb
friendly_id-5.0.2 test/configuration_test.rb
friendly_id-5.0.1 test/configuration_test.rb
friendly_id-5.0.0 test/configuration_test.rb
friendly_id-5.0.0.rc3 test/configuration_test.rb
friendly_id-5.0.0.rc2 test/configuration_test.rb
friendly_id-5.0.0.rc1 test/configuration_test.rb
friendly_id-5.0.0.beta4 test/configuration_test.rb