I broke a test in an odd way today and it brought up some design and
testing questions. I was working through some problems in my
integration tests, and all was going well. I found that to get a certain
test to pass, I changed this
class Container
belongs_to :parent, :polymorphic=>true
def connected_to?(other)
return false if parent.nil?
parent.connected_to_container?(other)
end
end
To this:
def connected_to?(other)
return false if parent.nil?
parent(true).connected_to_container?(other)
end
I then made a few other changes, my integration test passed and I reran
the whole test suite. When I did, the unit test for Container which had
passed for quite a while, suddenly dumped Red tests all over the place.
I discovered that by reloading the association the Mock that I had so
carefully crafted to go in its place got replaced by what was actually
in the database -- that is nil.
I ended up changing the way my integration tests work a little so I
could revert the change in Container, but it left me with some
questions:
1) Should a model ever force a reload of its associations?
2) If a model does reload its associations how do you still use mocks?
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---