Sha256: 1c764538ae7b4c0907df7b50041fb85c9ef157c655e7b1cd1d1ab7fecee29f39

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

require 'helper'

setup_active_record

class User < ActiveRecord::Base
  include HasConstant
  include HasConstant::Orm::ActiveRecord

  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

10 entries across 10 versions & 1 rubygems

Version Path
has_constant-0.4.9 test/unit/orm/active_record_test.rb
has_constant-0.4.8 test/unit/orm/active_record_test.rb
has_constant-0.4.7 test/unit/orm/active_record_test.rb
has_constant-0.4.6 test/unit/orm/active_record_test.rb
has_constant-0.4.5 test/unit/orm/active_record_test.rb
has_constant-0.4.4 test/unit/orm/active_record_test.rb
has_constant-0.4.3 test/unit/orm/active_record_test.rb
has_constant-0.4.2 test/unit/orm/active_record_test.rb
has_constant-0.4.1 test/unit/orm/active_record_test.rb
has_constant-0.4.0 test/unit/orm/active_record_test.rb