Hi
I've got a problem validating a boolean and I can't see what the problem is. Here's my model:
class FinanceAgreement < ActiveRecord::Base belongs_to :asset
validates_presence_of :finance_company validates_inclusion_of :balance, :in => 0.01..10_000_000 validates_inclusion_of :term, :in => 1..600 validates_numericality_of :term, :only_integer => true validates_inclusion_of :linked_to_residual_value_of_asset, :in => [true, false] end
and here's the RSpec code I'm using to test it:
context "A FinanceAgreement with valid attributes" do setup do @finance_agreement = FinanceAgreement.new(:finance_company => "Jigsaw Finance", :start_date => nil, :balance => 5000, :term => 36, :linked_to_residual_value_of_asset => true) end
aspect "validation" do specify "should be valid" do @finance_agreement.should be_valid end
specify "should be invalid if linked_to_residual_value_of_asset is not true or false" do @finance_agreement.linked_to_residual_value_of_asset = true @finance_agreement.should be_valid
@finance_agreement.linked_to_residual_value_of_asset = false @finance_agreement.should be_valid
@finance_agreement.linked_to_residual_value_of_asset = 1 @finance_agreement.should_not be_valid end end end
The first two expectations (true and false should be valid values) pass but it fails on this error:
should be invalid if linked_to_residual_value_of_asset is not true or false expected valid? to return false, got true
/Users/ashleymoran/Documents/Development/YourMoney/trunk/src/spec/models/finance_agreement_spec.rb:65:
(I cut some specs out, line 65 is "@finance_agreement.should_not be_valid")
Any idea why 1 makes the model valid? The only thing I can find that makes it (correctly) invalid is nil.
Thanks Ashley