Sha256: 24051bd0cb86a7ca8823a3bf3a56b2068e5f0b90162f2da8a7cbbacf0662a2b3

Contents?: true

Size: 774 Bytes

Versions: 3

Compression:

Stored size: 774 Bytes

Contents

require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

describe DataMapper::Validate::ContextualValidators do

  before :all do
    class Kayak
      include DataMapper::Resource
      property :id, Integer, :key => true
      property :salesman, String, :auto_validation => false
      validates_absent :salesman, :when => :sold
    end
  end

  it "should pass validation for a specific context" do
    k = Kayak.new
    k.valid?(:sold).should == true
    k.salesman = 'John Doe'
    k.valid?(:sold).should_not == true
  end

  it "should raise an exception if you provide an invalid context to save" do
    lambda { Kayak.new.save(:invalid_context) }.should raise_error
    lambda { Kayak.new.save(false) }.should raise_error
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dm-validations-0.9.7 spec/integration/contextual_validators_spec.rb
dm-validations-0.9.8 spec/integration/contextual_validators_spec.rb
dm-validations-0.9.9 spec/integration/contextual_validators_spec.rb