ruby on rails 3 - Failure/Error: get :show, :id => @user -
i have issue on learn rails example book chapter 7 @ end of chapter these error messages in rspec spec
1) userscontroller should have right title failure/error: :show, :id => @user actioncontroller::routingerror: no route matches {:id=>nil, :controller=>"users", :action=>"show"} # ./spec/controllers/users_controller_spec.rb:36:in `block (2 levels) in '
2) userscontroller should include user's name failure/error: :show, :id => @user actioncontroller::routingerror: no route matches {:id=>nil, :controller=>"users", :action=>"show"} # ./spec/controllers/users_controller_spec.rb:41:in `block (2 levels) in '
3) userscontroller should have profile image failure/error: :show, :id => @user actioncontroller::routingerror: no route matches {:id=>nil, :controller=>"users", :action=>"show"} # ./spec/controllers/users_controller_spec.rb:46:in `block (2 levels) in '
below relevant code have done,
spec/controllers/users_controller_spec.rb
it "should have right title" :show, :id => @user response.should have_selector("title", :content => @user.name) end "should include user's name" :show, :id => @user response.should have_selectori("h1", :content => @user.name) end "should have profile image" :show, :id => @user response.should have_selector("h1>img", :class => "gravatar") end end
app/controllers/users_controller.rb
class userscontroller < applicationcontroller def show @user = user.find(params[:id]) @title = @user.name end
app/helpers/users_helper.rb
module usershelper def gravatar_for(user, options = { :size => 50 }) gravatar_image_tag(user.email.downcase, :alt => user.name, :class => 'gravatar', :gravatar => options) end end
app/views/users/show.html.erb
<%= @user.name %>, <%= @user.email %> <table class="profile" summary="profile information"> <tr> <td class="main"> <h1> <%= gravatar_for @user %> <%= @user.name %> </h1> </td> <td class="sidebar round"> <strong>name</strong> <%= @user.name %><br /> <strong>url</strong> <%= link_to user_path(@user), @user %> </td> </tr> </table>
spec/factories.rb
factory.define :user |user| user.name "michael hartl" user.email "mhartl@example.com" user.password "foobar" user.password_confirmation "foobar" end
i think needed
get :show, :id => @user.id
or
get :show, :id => '1'
instead using entire object parameter.
Comments
Post a Comment