Here is the rspec code for the controller:
it "should render edit if update was not saved" do item = Factory(:lease_item) session[:corp_head] = true post 'update', {:id => item.id, :name => 'nil'} flash[:notice].should_not be_nil response.should render 'edit' end
Update in the controller:
def update if (eng? && dept_head?) || corp_head? || ceo? @lease_item = LeaseItem.find(params[:id]) @lease_item.input_by_id = session[:user_id] if @lease_item.update_attributes(params[:lease_item], :as => :roles_update)
Here is the error code from rspec:
1) LeaseItemsController GET 'update' should render edit if update was not saved Failure/Error: flash[:notice].should_not be_nil expected: not nil got: nil
"Item NOT updated" was expected in the flash. However, why is there nothing with flash [: notice]? Or, as rspec there is a message with the 'edit' renderer: notice => 'Item NOT updated'
Thanks.
UPDATE:
Here is the change in the controller:
........... else #back to new flash[:notice] = "Item NOT updated" render 'edit' end .........
Here is the rspec code that passes:
it "should render edit if update was not saved" do item = Factory(:lease_item) session[:corp_head] = true post 'update', {:id => item.id, :lease_item => {:name => 'nil'}} flash.should_not be_nil response.should render_template(:action=> "edit") end
This did not work if you use flash [: notice] .should_not be_nil (or .. flash.now [: notice] ...). Error: Got nil, which is similar to the previous one. Also, response.should render 'edit' (or ... render: action => 'edit') also failed. Error: NameError or NoMethodError. I do not know why.