Sha256: 5bf00d96c2c8a2afc188db5bbcd53961d9b077812f45877b9de358ed0aa18e97

Contents?: true

Size: 761 Bytes

Versions: 12

Compression:

Stored size: 761 Bytes

Contents

require "helper"

class OhmExtraValidationsTest < Test::Unit::TestCase
  context "membership assertion" do
    class Order < Ohm::Model
      include Ohm::ExtraValidations

      attribute :state

      def validate
        assert_member :state, %w(pending authorized declined)
      end
    end

    should "be successful given all the members" do
      order = Order.new(:state => 'pending')
      assert order.valid?

      order = Order.new(:state => 'authorized')
      assert order.valid?

      order = Order.new(:state => 'declined')
      assert order.valid?
    end

    should "fail on a non-member" do
      order = Order.new(:state => 'foobar')
      assert ! order.valid?
      assert_equal [[:state, :not_member]], order.errors
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ohm-contrib-0.0.31 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.30 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.29 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.28 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.27 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.26 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.25 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.24 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.16 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.15 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.14 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.13 test/test_ohm_extra_validations.rb