Sha256: ff754ce6466d3272bc2bb46d51ee3ffb7c2cc4c7289758d711fba35e01f40040

Contents?: true

Size: 760 Bytes

Versions: 7

Compression:

Stored size: 760 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

7 entries across 7 versions & 1 rubygems

Version Path
ohm-contrib-0.0.23 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.22 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.21 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.20 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.19 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.18 test/test_ohm_extra_validations.rb
ohm-contrib-0.0.17 test/test_ohm_extra_validations.rb