Sha256: db8423bf2d4d342a52692476a9af100d01e6669b1fc6835465c40eeb80194f38

Contents?: true

Size: 829 Bytes

Versions: 5

Compression:

Stored size: 829 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(nil) }.should raise_error
    lambda { Kayak.new.save(false) }.should raise_error
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dm-validations-0.9.3 spec/integration/contextual_validators_spec.rb
dm-validations-0.9.4 spec/integration/contextual_validators_spec.rb
dm-validations-0.9.2 spec/integration/contextual_validators_spec.rb
dm-validations-0.9.5 spec/integration/contextual_validators_spec.rb
dm-validations-0.9.6 spec/integration/contextual_validators_spec.rb