Sha256: 2cdf243f898b6fcbecb8544c1dd1ff7a7abb875c9e95a73f2fce17b0c4eb3a4b

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require 'helper'

setup_mongoid

class MongoUser
  include Mongoid::Document
  include HasConstant
  include HasConstant::Orm::Mongoid

  field :salutation, :type => Integer

  has_constant :salutations, ['Mr', 'Mrs']
end if defined?(Mongoid)

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

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
has_constant-0.2.2 test/unit/orm/mongoid_test.rb
has_constant-0.2.1 test/unit/orm/mongoid_test.rb
has_constant-0.2.0 test/unit/orm/mongoid_test.rb