Question

I'm running through the Ruby on Rails Tutorial 3, and having a ball doing it, but I've just come across some problems that aren't getting solved. When I run my specs, two tests fail.

Failures:
  1) UsersController PUT 'update' failure should render the 'edit' page
  Failure/Error: put :update, :id => @user, :user => @attr
  undefined local variable or method `object' for #<#<Class:0x00000102c861c8>:0x00000101d25558>
 # ./app/views/shared/_error_messages.html.erb:3:in `_app_views_shared__error_messages_html_erb___3390867530789228804_2170854120__2806434579894406668'
 # ./app/views/users/edit.html.erb:4:in `block in _app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
 # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
 # ./app/controllers/users_controller.rb:47:in `update'
 # ./spec/controllers/users_controller_spec.rb:158:in `block (4 levels) in <top (required)>'

2) UsersController PUT 'update' failure should have the right title
 Failure/Error: put :update, :id => @user, :user => @attr
 undefined local variable or method `object' for #<#<Class:0x00000102c861c8>:0x00000101b211f8>
 # ./app/views/shared/_error_messages.html.erb:3:in `_app_views_shared__error_messages_html_erb___3390867530789228804_2170854120__2806434579894406668'
 # ./app/views/users/edit.html.erb:4:in `block in _app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
 # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb__558009768664311469_2170714160__919273585470661416'
 # ./app/controllers/users_controller.rb:47:in `update'
 # ./spec/controllers/users_controller_spec.rb:163:in `block (4 levels) in <top (required)>'

I've searched through my code as best I can comparing it against the code in the book, and I've come up with nothing. I'm sure it's one stupid little thing that I've missed, and I would greatly appreciate a second pair (or more ;) of eyes.

Here are my tests:

describe "failure" do
  before(:each) do
    @attr = { :email => "", :name => "", :password => "", :password_confirmation => "" }
  end

  it "should render the 'edit' page" do
    put :update, :id => @user, :user => @attr
    response.should render_template('edit')
  end

  it "should have the right title" do
    put :update, :id => @user, :user => @attr
    response.should have_selector("title", :content => "Edit User")
  end
end

And here is the update methods from the users_controller:

def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
  flash[:success] = "Profile updated"
  redirect_to @user
else
  @title = "Edit User"
  render 'edit'
end
end

Any thoughts on where I should look are greatly appreciated.

Was it helpful?

Solution

The source of the problem is not in spec files even though the problem manifests itself in those spec files. The instructor, Michael Hartl, changes the following statement:

<%= render 'shared/error_messages' %
                  to 
<%= render 'shared/error_messages', :object => f.object %>

statement. In other words, he adds “, :object => f.object” to the first statement. And you must look in all files that have the original statement and change them to the second one. If you miss any of them you will have these errors. Specifically look in the following files (and any other that may have the original statement):

app/views/users/edit.html.erb
app/views/users/fields.html.erb
app/views/users/new.html.erb
app/views/shared/micropost_form.html.erb
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top