Sha256: 8558df92249a29c60a0401c38065fe165b1ebdb6f7b8cfefdc00e3c00212f926

Contents?: true

Size: 1.35 KB

Versions: 16

Compression:

Stored size: 1.35 KB

Contents

require 'test_helper'


class User < ActiveRecord::Base
  add_to_bag :name
end

class Administrator < User
  add_to_bag :key
end


class StiTest < ActiveSupport::TestCase

  def setup
    @user = User.new
    @admin = Administrator.new
  end

  test "kind of" do
    assert_kind_of User, @user
    assert_kind_of Administrator, @admin
  end

  test "STI field type" do
    assert_nil @user.type
    assert_equal 'Administrator', @admin.type
  end

  test "have bag" do
    assert @user.respond_to?(:bag)
    assert @admin.respond_to?(:bag)
  end

  test "has setters and getters" do
    assert @user.respond_to?(:name)
    assert @admin.respond_to?(:name)
    assert @admin.respond_to?(:key)

    assert @user.respond_to?('name=')
    assert @admin.respond_to?('name=')
    assert @admin.respond_to?('key=')

    assert_equal false, @user.respond_to?(:key)
    assert_equal false, @user.respond_to?('key=')
  end

  test "access to name & key" do
    name = 'name'
    key = 'key'
    @admin.name = name
    @admin.key = key
    assert_equal name, @admin.name
    assert_equal key, @admin.key
    assert_not_equal 'def', @admin.name
    assert_not_equal 'def', @admin.key
  end

  test "merge" do
    model = :administrator
    params = {model => {'at(1i)' => '1', 'at(2i)' => '2','at(3i)' => '3'}}
    res = Administrator.merge({}, params)
    assert_nil res[model][:at]
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
act_with_bag-1.0.4 test/sti_test.rb
act_with_bag-1.0.3 test/sti_test.rb
act_with_bag-1.0.2 test/sti_test.rb
act_with_bag-1.0.0 test/sti_test.rb
act_with_bag-0.5.7 test/sti_test.rb
act_with_bag-0.5.6 test/sti_test.rb
act_with_bag-0.4.9.1 test/sti_test.rb
act_with_bag-0.5.5 test/sti_test.rb
act_with_bag-0.5.3 test/sti_test.rb
act_with_bag-0.5.2 test/sti_test.rb
act_with_bag-0.5.1 test/sti_test.rb
act_with_bag-0.4.9 test/sti_test.rb
act_with_bag-0.4.7 test/sti_test.rb
act_with_bag-0.4.4 test/sti_test.rb
act_with_bag-0.4.2 test/sti_test.rb
act_with_bag-0.4.0 test/sti_test.rb