On 6 Dec 2011, at 16:10, Ori Kremer <[email protected]> wrote:

> I see different results when running 'rake test' and when running 'rake
> test:integration'.
> 
> When running all tests with 'rake test' all tests pass.
> When running 'rake test:integration' I have a failed test because my
> model fails to validate inclusion of an attribute before saving.
> 
> My model looks something like:
> 
>  class Order < ActiveRecord::Base
>    belongs_to :payment_type
>    validates :payment_type, :inclusion => PaymentType.all
>    ...
>  end
> 
> 
> PaymentType is a lookup table, which I have a fixture for.
> 
> When debugging the save method in the Order model I see that it fails
> the inclusion validation (again, only when running just the integration
> tests), but
> 
>  PaymentType.all.include?(payment_type)
> 
> evaluates to 'true'.
> 
> Any ideas why it fails when running only integration tests?
> 

The call to validates (and thus the evaluation of its argument) happens when 
your order class is loaded. If this happens before your fixtures are loaded 
then you'll effectively be doing validates :blah, :inclusion => []

Why running rake test versus rake test:integration matters I don't know - 
perhaps one has extra dependencies that force fixtures to be loaded earlier or 
later, but either way I've generally tried to avoid this sort of thing. I'm not 
sure what your current code gets you over just validating the presence of the 
payment_type

Fred


> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to