Sha256: 2aac81f283697dd256bea2b0b0c361a85057bfdb89bcca1ae05b41558366a895

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'helper'

setup_active_record

class User < ActiveRecord::Base
  include HasConstant

  has_constant :salutations, ['Mr', 'Mrs']
end

class ActiveRecordTest < Test::Unit::TestCase
  should 'save values as integers' do
    u = User.new(:salutation => 'Mr')
    u.save!
    assert_equal 'Mr', u.salutation
    assert_equal 0, u.attributes['salutation']
  end

  context 'scopes' do
    setup do
      @man = User.create!(:salutation => 'Mr')
      @woman = User.create!(:salutation => 'Mrs')
    end

    should 'provide by_constant scope' do
      assert_equal 1, User.by_constant('salutation', 'Mr').count
      assert_equal @man, User.by_constant('salutation', 'Mr').first
    end

    should 'provide singular_is scope' do
      assert_equal 1, User.salutation_is('Mr').count
      assert_equal @man, User.salutation_is('Mr').first
    end

    should 'provide singular_is_not scope' do
      assert_equal 1, User.salutation_is_not('Mr').count
      assert_equal @woman, User.salutation_is_not('Mr').first
    end
  end
end if defined?(ActiveRecord)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
has_constant-0.5.1 test/unit/orm/active_record_test.rb
has_constant-0.5.0 test/unit/orm/active_record_test.rb