public
Rubygem
Description: Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-more.git
Search Repo:
myabc (author)
Thu May 08 06:46:07 -0700 2008
commit  d030592d948d24d86511bc03af0026d7ebebce64
tree    06627dd67de4db6f2becbc5c8e1934721d682869
parent  53973fb564838e387c4721a46b3bba7d2fa10bcf
dm-more / dm-validations / spec / absent_field_validator_spec.rb
100644 35 lines (28 sloc) 0.986 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'pathname'
require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
 
describe DataMapper::Validate::AbsentFieldValidator do
  before(:all) do
    class Kayak
      include DataMapper::Resource
      include DataMapper::Validate
      property :salesman, String, :auto_validation => false
            
      validates_absence_of :salesman, :when => :sold
    end
    
    class Pirogue
      include DataMapper::Resource
      include DataMapper::Validate
      property :salesman, String, :default => 'Layfayette'
      validates_absence_of :salesman, :when => :sold
    end
  end
 
  it "should validate the absense of a value on an instance of a resource" do
    kayak = Kayak.new
    kayak.valid_for_sold?.should == true
    
    kayak.salesman = 'Joe'
    kayak.valid_for_sold?.should_not == true
  end
  
  it "should validate the absense of a value and ensure defaults" do
    pirogue = Pirogue.new
    pirogue.should_not be_valid_for_sold
  end
  
end