Sha256: 4c60260c41b6dd340392139427c00d32502cdd5a63777381de05f3f4cdbccae4

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

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

class Monica # :nodoc:
  include DataMapper::Resource
  property :id, Integer, :serial => true
  property :birth_date, Date, :auto_validation => false
  property :happy, TrueClass
  validates_is_primitive :birth_date
end

describe DataMapper::Validate::PrimitiveValidator do
  it "should validate a property to check for the type" do
    b = Monica.new
    p b.valid?
    p b.errors
    b.should be_valid

    b.birth_date = 'ABC'
    b.should_not be_valid
    b.birth_date.should eql('ABC')
    b.birth_date = '2008-01-01'
    b.should be_valid
    b.birth_date.should eql(Date.civil(2008,1,1))
  end
  it "should accept FalseClass even when the property type is TrueClass" do
    b = Monica.new
    b.happy = false
    b.valid?.should == true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-validations-0.9.5 spec/integration/primitive_validator_spec.rb