Topic: Help with RSpec test on redering 'edit' page after unsuccessful update
I'm coding a small web application which allows users to add some of the goals they have, where goals belong_to user, and a user has_many goals. I'm trying to test the unsuccessful update of a goal, where the 'edit' page is rendered on failure.
The Test:
describe "PUT 'update'" do
before(:each) do
@user = test_sign_in(Factory(:user))
@goal = Factory(:goal, :user => @user)
end
describe "failure" do
it "should render the edit page" do
@goal.update_attributes(:content => "")
put :update, :id => @goal, :goal => {}
response.should render_template('edit')
end
end
end
The Code:
def update
@goal = Goal.find params[:id]
if @goal.update_attributes params[:goal]
redirect_to user_path(current_user), :flash => { :success => "Goal updated" }
else
@title = "Edit Goal"
render 'edit'
end
end
The Failure:
Failures:
1) GoalsController PUT 'update' failure should render the edit page
Failure/Error: response.should render_template('edit')
Expected block to return true value.
# ./spec/controllers/goals_controller_spec.rb:97:in `block (4 levels) in <top (required)>'
For some reason I cannot for the life of me get this test to pass. If it helps, I viewed the actual results in the browser, and it's behaving exactly how I'd like. The errors are being rendered and no update is occuring. However, in the debug params at the bottom, it says I am still in the update action. Any help would be appreciated, thanks!
Last edited by grantbachman (2011-05-19 00:33:20)