Sha256: 2c631c43e43e5083604cdff32e117fdc209309cdb68a437c03cd0c6682727646

Contents?: true

Size: 629 Bytes

Versions: 13

Compression:

Stored size: 629 Bytes

Contents

# encoding: UTF-8

require File.expand_path("./helper", File.dirname(__FILE__))

class Order < Ohm::Model
  include Ohm::ExtraValidations

  attribute :state

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

test "validates for all 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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ohm-contrib-0.1.2 test/membership_validation_test.rb
ohm-contrib-0.1.1 test/membership_validation_test.rb
ohm-contrib-0.1.0 test/membership_validation_test.rb
ohm-contrib-0.0.42 test/membership_validation_test.rb
ohm-contrib-0.0.41 test/membership_validation_test.rb
ohm-contrib-0.0.40 test/membership_validation_test.rb
ohm-contrib-0.0.39 test/membership_validation_test.rb
ohm-contrib-0.0.38 test/membership_validation_test.rb
ohm-contrib-0.0.37 test/membership_validation_test.rb
ohm-contrib-0.0.36 test/membership_validation_test.rb
ohm-contrib-0.0.35 test/membership_validation_test.rb
ohm-contrib-0.0.34 test/membership_validation_test.rb
ohm-contrib-0.0.33 test/membership_validation_test.rb