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
myabc (author)
Thu May 08 07:07:12 -0700 2008
commit  f331f4c3fc6c52f69790feecfee0bb804a66296c
tree    5fb83dae55257e19319abeb649316564a5d8e835
parent  d030592d948d24d86511bc03af0026d7ebebce64
dm-more / dm-validations / spec / absent_field_validator_spec.rb
100644 50 lines (39 sloc) 1.323 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'pathname'
require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
 
begin
  gem 'do_sqlite3', '=0.9.0'
  require 'do_sqlite3'
  
  DataMapper.setup(:sqlite3, "sqlite3://#{DB_PATH}")
 
  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
 
rescue LoadError => e
  describe 'do_sqlite3' do
    it 'should be required' do
      fail "validation specs not run! Could not load do_sqlite3: #{e}"
    end
  end
end