I'm trying to write spec for inherited_resources controller. I decided to mock all integration with the database using rspec's mock_model. Unfortunately I can't write spec for create and update action because I'm getting the following error: https://gist.github.com/936947 Can someone help me with this issue?
Asked
Active
Viewed 840 times
2 Answers
4
I was having the same issue using flexmock.
the cause is that it does not use the update_attributes
method to make the routing decision. It checks the resource.errors
to see whether it is empty.
So to get it to respond properly, we will need to mock out the errors
method as well.
Here is the pertinent code @line 248 in lib/inherited_resources/base_helpers.rb
def respond_with_dual_blocks(object, options, &block) #:nodoc:
args = (with_chain(object) << options)
case block.try(:arity)
when 2
respond_with(*args) do |responder|
blank_slate = InheritedResources::BlankSlate.new
if object.errors.empty?
block.call(responder, blank_slate)
else
block.call(blank_slate, responder)
end
end
when 1
respond_with(*args, &block)
else
options[:location] = block.call if block
respond_with(*args)
end
end

Geoff Lanotte
- 7,490
- 1
- 38
- 50
-
Mock out the errors method with what, exactly? I've come across this exact same issue... – sevenseacat Sep 04 '11 at 14:28
-
1Ah right, I've used stub_chain with `team.stub_chain(:errors, :empty?).and_return(false)` and it works perfectly. – sevenseacat Sep 04 '11 at 14:38
0
The failure messages are about the inability to access named routes from inside the controller, so I'm not sure that this has anything to do with mock_model. Have you tried the same examples using real models?

David Chelimsky
- 8,920
- 2
- 38
- 30