So, I’m getting a pretty strange error here… I tried to isolate it but it’s quasi-intermittent. I’m kinda wondering if it has something to do with using capybara with a javascript driver, because this isn’t happening in my non-capybara tests. Here it is:
Failure/Error: @existing_user, household = create_new_user_and_household
ActiveRecord::AssociationTypeMismatch:
User(#57141560) expected, got User(#42098260)
# ./app/models/household.rb:64:in `block in create_new_household'
# ./app/models/household.rb:62:in `new'
# ./app/models/household.rb:62:in `create_new_household'
# ./spec/support/spec_helpers.rb:55:in `create_new_user_and_household'
# ./spec/integration/accepting_an_invitation_spec.rb:21:in `block (4 levels) in <top (required)>'
Here’s the block in question:
household = Household.new attributes, do |h|
h.account = user.account || Account.create(user: user)
end
Pretty basic, and works fine when I do it manually in the rails console.
I’m not sure what else to tell you guys… but I’m happy to provide more info.
I’m using rspec for all of my testing.
So the answer, as Frederick Cheung pointed out was to set
cache_classestotrueintest.rb.This supposedly conflicts with spork, which is why I was told to turn it off in the first place–since you want spork to re-load your models and whatnot whenever you run another test. The solution is to set
cache_classestotruebut also putActiveSupport::Dependencies.clearin your spork prefork block.References: