I have a simple test, to a large extent, that created the scaffold, although I cannot understand why it does not work. Here's the situation:
I have an AttachmentsController:
And specification:
describe AttachmentsController do def mock_attachment(stubs={}) @mock_attachment ||= mock_model(Attachment, stubs).as_null_object end describe "POST create" do describe "with valid params" do it "assigns a newly created attachment as @attachment" do Attachment.stub(:new).with({'these' => 'params'}) { mock_attachment(:save => true) } post :create,:attachment => {'these' => 'params'} assigns(:attachment).should be(mock_attachment) end
but this (and every other test in this specification) fails with something in the lines
expected #<Attachment:33902000> => #<Attachment:0x2054db0 @name="Attachment_1001"> got #<NilClass:4> => nil
Because for reasons that I cannot understand, AttachmentsController # create is not called.
Route:
POST /attachments(.:format) {:action=>"create", :controller=>"attachments"}
Here is what the magazine says:
Processing by AttachmentsController#create as HTML Parameters: {"attachment"=>{"these"=>"params"}} Rendered text template (0.0ms) Completed 302 Found in 52ms (Views: 23.1ms | ActiveRecord: 0.0ms)
I should also note that I can invoke the creation code (and it works fine) through the website itself .. these are just tests that fail.
So what can call post () or get () so as not to call such a controller?
source share