I'm currently going through the awesome Rails Tutorial, and after I did a git reset to return to a previous commit, something broke to my database and all of a sudden I get 5 failures when I run rspec.
Failures:
1) UsersController Get 'show' should be successfull
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xaad9990>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
2) UsersController Get 'show' should find the right user
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xa820ca8>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:18:in `block (3 levels) in <top (required)>'
3) UsersController Get 'show' should have the right title
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0x9f0e7b4>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
4) UsersController Get 'show' should include the user's name
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb930cc8>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:28:in `block (3 levels) in <top (required)>'
5) UsersController Get 'show' should have a profile image
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb9ade94>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:33:in `block (3 levels) in <top (required)>'
I'm sure this easy to fix, but I honestly dont know where to even look at. Can anyone help?
This is your problem:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb9ade94>
You need to make sure the gravatar is specificed in your profile model.
You are calling gravatar_for, which is unknown, line 5 of: ./app/views/users/show.html.erb
Even if this is already an answer, please provide details so that we fix it.
I'm pretty sure you forgot to add the method to your User model.
Related
I've just started using rspec_api_documentation and cannot get it to work with my api. Created simple spec, as basic as first example in the readme but it keeps throwing undefined method 'call' for nil:NilClass error at me, and I have no idea what may cause the problem.
Here is full stack trace:
1) Users GET /api/v1/users Listing users
Failure/Error: do_request
NoMethodError:
undefined method `call' for nil:NilClass
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rspec_api_documentation-4.7.0/lib/rspec_api_documentation/rack_test_client.rb:38:in `do_request'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rspec_api_documentation-4.7.0/lib/rspec_api_documentation/client_base.rb:42:in `process'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rspec_api_documentation-4.7.0/lib/rspec_api_documentation/client_base.rb:12:in `get'
# ./spec/acceptance/users_spec.rb:7:in `block (3 levels) in <top (required)>
Here is the spec
require 'spec_helper'
require 'rspec_api_documentation/dsl'
RSpec.resource 'Users' do
get '/api/v1/users' do
example 'Listing users' do
do_request
status.should == 200
end
end
end
and here is the controller
class Api::V1::UsersController < ApplicationController
skip_before_action :authenticate_with_token, only: %i(index show create)
expose(:users)
def index
render json: users, each_serializer: ::V1::UserSerializer
end
end
My api is under localhost:3000/api/v1/users
Any help appreciated
It seems that configuration block is required, so I've just created acceptance_helper.rb as in the example application and imported it in spec.
I'm having issue with rendering an active admin view
RSpec.describe "active_admin/resource/new" do
it "is just simple test" do
render
end
end
but it returns
Failure/Error:
render# template: 'active_admin/resource/new.html.arb'
ActionView::Template::Error:
undefined method `renderer_for' for :Arbre::Context
# ./spec/views/admin/form_spec.rb:7:in `block (2 levels) in <top (required)>'
How to properly render it so I can do some tests on its content
I think this could be a starting point: https://github.com/activeadmin/activeadmin/blob/master/spec/unit/views/pages/form_spec.rb
I am a bit confused here. I am trying to do TDD and have run into an issue. Rspec is telling me the following-
1) Sammiches GET /sammiches display some sammiches
Failure/Error: visit sammiches_path
NameError:
undefined local variable or method `sammiches_path' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_1:0x007fa7afcfed70>
# ./spec/requests/sammiches_spec.rb:7:in `block (3 levels) in <top (required)>'
2) Sammiches GET /sammiches creates a new sammich
Failure/Error: visit sammiches_path
NameError:
undefined local variable or method `sammiches_path' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_1:0x007fa7ae11e6f0>
# ./spec/requests/sammiches_spec.rb:12:in `block (3 levels) in <top (required)>'
This is what my spec file looks like
require 'spec_helper'
describe "Sammiches" do
describe "GET /sammiches" do
it "display some sammiches" do
#sammich = Sammich.create :name => 'bacon'
visit sammiches_path
page.should have_content 'bacon'
end
it "creates a new sammich" do
visit sammiches_path
fill_in 'Sammich', :with => 'lechuga'
click_button 'add Sammich'
current_path.should = root_path
page.should have_content 'lechuga'
save_and_open_page
end
end
end
My routes are -
sammiches_index GET /sammiches/index(.:format) sammiches#index
Sammiches GET /Sammiches(.:format) Sammiches#index
POST /Sammiches(.:format) Sammiches#create
new_Sammich GET /Sammiches/new(.:format) Sammiches#new
edit_Sammich GET /Sammiches/:id/edit(.:format) Sammiches#edit
Sammich GET /Sammiches/:id(.:format) Sammiches#show
PUT /Sammiches/:id(.:format) Sammiches#update
DELETE /Sammiches/:id(.:format) Sammiches#destroy
root / Sammiches#index
Routes-
Sammiches::Application.routes.draw do
get "Sammiches/index"
resources :sammiches
root :to => 'Sammiches#index'
New Error-
1) Sammiches GET /sammiches creates a new sammich
Failure/Error: visit sammiches_path
ActionView::Template::Error:
undefined method `sammich' for #<Sammich:0x007fd0007d2f80>
# ./app/views/sammiches/index.html.erb:4:in `block in _app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
# ./app/views/sammiches/index.html.erb:2:in `_app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
# ./spec/requests/sammiches_spec.rb:12:in `block (3 levels) in <top (required)>'
2) Sammiches GET /sammiches display some sammiches
Failure/Error: visit sammiches_path
ActionView::Template::Error:
undefined method `sammich' for #<Sammich:0x007fd00006f4f0>
# ./app/views/sammiches/index.html.erb:4:in `block in _app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
# ./app/views/sammiches/index.html.erb:2:in `_app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
# ./spec/requests/sammiches_spec.rb:7:in `block (3 levels) in <top (required)>'
I am at a bit of a loss here. Any advice would be greatly appreciated.
Thanks.
You seem to have added resources :Sammiches in config/routes.rb.
Change it to resources :sammiches. Sticking to the convention, helps. :)
Your route file should look like:
Sammiches::Application.routes.draw do
resources :sammiches
root :to => 'sammiches#index'
I have almost completed this tutorial when I started to get these error messages. Can someone give me a starting point on where to begin find out whats wrong. What files do you all need to see?
Failures:
1) MicropostsController DELETE 'destroy' for an unauthorized user should deny access
Failure/Error: response.should redirect_to(root_path)
Expected response to be a redirect to <http://test.host/> but was a redirect to <http://test.host/signin>
# ./spec/controllers/microposts_controller_spec.rb:72:in `block (4 levels) in <top (required)>'
2) UsersController GET 'new' should be successful
Failure/Error: get :new
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000005a62f70>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./spec/controllers/users_controller_spec.rb:131:in `block (3 levels) in <top (required)>'
3) UsersController GET 'new' should have the right title
Failure/Error: get :new
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000004242df0>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./spec/controllers/users_controller_spec.rb:136:in `block (3 levels) in <top (required)>'
4) UsersController GET 'new' POST 'create' failure should have the right title
Failure/Error: post :create, :user => #attr
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000004c96518>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/controllers/users_controller.rb:29:in `create'
# ./spec/controllers/users_controller_spec.rb:148:in `block (5 levels) in <top (required)>'
5) UsersController GET 'new' POST 'create' failure should render the 'new' page
Failure/Error: post :create, :user => #attr
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000056482c8>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/controllers/users_controller.rb:29:in `create'
# ./spec/controllers/users_controller_spec.rb:152:in `block (5 levels) in <top (required)>'
6) UsersController GET 'new' POST 'create' failure should not create a user
Failure/Error: post :create, :user => #attr
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000051f8038>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/controllers/users_controller.rb:29:in `create'
# ./spec/controllers/users_controller_spec.rb:157:in `block (6 levels) in <top (required)>'
# ./spec/controllers/users_controller_spec.rb:156:in `block (5 levels) in <top (required)>'
7) UsersController GET 'new' GET 'edit' should be succesful
Failure/Error: get :edit, :id => #user
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000053301f8>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./spec/controllers/users_controller_spec.rb:197:in `block (4 levels) in <top (required)>'
8) UsersController GET 'new' GET 'edit' should have the right title
Failure/Error: get :edit, :id => #user
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x0000000508af20>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./spec/controllers/users_controller_spec.rb:202:in `block (4 levels) in <top (required)>'
9) UsersController GET 'new' GET 'edit' should have a link to change the gravatar
Failure/Error: get :edit, :id => #user
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000059d7d08>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./spec/controllers/users_controller_spec.rb:207:in `block (4 levels) in <top (required)>'
10) UsersController GET 'new' PUT 'update' should change the user's attributes
Failure/Error: put :update, :id => #user, :user => #attr
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000004cf6990>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/controllers/users_controller.rb:43:in `update'
# ./spec/controllers/users_controller_spec.rb:247:in `block (4 levels) in <top (required)>'
11) UsersController GET 'new' PUT 'update' should have the right title
Failure/Error: put :update, :id => #user, :user => #attr
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000054200b8>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/controllers/users_controller.rb:43:in `update'
# ./spec/controllers/users_controller_spec.rb:255:in `block (4 levels) in <top (required)>'
12) UsersController GET 'new' PUT 'update' failure should render the 'edit' page
Failure/Error: put :update, :id => #user, :user => #attr
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000057c0448>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/controllers/users_controller.rb:43:in `update'
# ./spec/controllers/users_controller_spec.rb:231:in `block (5 levels) in <top (required)>'
13) FriendlyForwardings should forward to the requested page after signin
Failure/Error: click_button
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x0000000541df48>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
# ./spec/requests/friendly_forwardings_spec.rb:10:in `block (2 levels) in <top (required)>'
14) LayoutLinks should have an signup page at '/signup'
Failure/Error: get '/signup'
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000003980370>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./spec/requests/layout_links_spec.rb:28:in `block (2 levels) in <top (required)>'
15) LayoutLinks should have the right links on the layout
Failure/Error: click_link "Sign up now!"
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000058c3098>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./spec/requests/layout_links_spec.rb:47:in `block (2 levels) in <top (required)>'
16) creation failure should not make a new micropost
Failure/Error: fill_in :micropost_content, :with => ""
Webrat::NotFoundError:
Could not find field: :micropost_content
# ./spec/requests/microposts_spec.rb:17:in `block (4 levels) in <top (required)>'
# ./spec/requests/microposts_spec.rb:15:in `block (3 levels) in <top (required)>'
17) creation success should make a new micropost
Failure/Error: fill_in :micropost_content, :with => content
Webrat::NotFoundError:
Could not find field: :micropost_content
# ./spec/requests/microposts_spec.rb:30:in `block (4 levels) in <top (required)>'
# ./spec/requests/microposts_spec.rb:28:in `block (3 levels) in <top (required)>'
18) Users signup failure should not make a new user
Failure/Error: visit signup_path
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000005766c40>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./spec/requests/users_spec.rb:11:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:10:in `block (4 levels) in <top (required)>'
19) Users signup success should make a new
Failure/Error: visit signup_path
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000059e8bd0>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
# ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
# ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
Finished in 4.31 seconds
124 examples, 19 failures
Failed examples:
rspec ./spec/controllers/microposts_controller_spec.rb:70 # MicropostsController DELETE 'destroy' for an unauthorized user should deny access
rspec ./spec/controllers/users_controller_spec.rb:130 # UsersController GET 'new' should be successful
rspec ./spec/controllers/users_controller_spec.rb:135 # UsersController GET 'new' should have the right title
rspec ./spec/controllers/users_controller_spec.rb:147 # UsersController GET 'new' POST 'create' failure should have the right title
rspec ./spec/controllers/users_controller_spec.rb:151 # UsersController GET 'new' POST 'create' failure should render the 'new' page
rspec ./spec/controllers/users_controller_spec.rb:155 # UsersController GET 'new' POST 'create' failure should not create a user
rspec ./spec/controllers/users_controller_spec.rb:196 # UsersController GET 'new' GET 'edit' should be succesful
rspec ./spec/controllers/users_controller_spec.rb:201 # UsersController GET 'new' GET 'edit' should have the right title
rspec ./spec/controllers/users_controller_spec.rb:206 # UsersController GET 'new' GET 'edit' should have a link to change the gravatar
rspec ./spec/controllers/users_controller_spec.rb:246 # UsersController GET 'new' PUT 'update' should change the user's attributes
rspec ./spec/controllers/users_controller_spec.rb:254 # UsersController GET 'new' PUT 'update' should have the right title
rspec ./spec/controllers/users_controller_spec.rb:230 # UsersController GET 'new' PUT 'update' failure should render the 'edit' page
rspec ./spec/requests/friendly_forwardings_spec.rb:4 # FriendlyForwardings should forward to the requested page after signin
rspec ./spec/requests/layout_links_spec.rb:27 # LayoutLinks should have an signup page at '/signup'
rspec ./spec/requests/layout_links_spec.rb:38 # LayoutLinks should have the right links on the layout
rspec ./spec/requests/microposts_spec.rb:14 # creation failure should not make a new micropost
rspec ./spec/requests/microposts_spec.rb:26 # creation success should make a new micropost
rspec ./spec/requests/users_spec.rb:8 # Users signup failure should not make a new user
rspec ./spec/requests/users_spec.rb:25 # Users signup success should make a new
# Finished at 2012-05-15 16:41:20
This is _error_messages.html.erb
<% if object.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(object.errors.count, "error") %>
prohibited this <%= object.class.to_s.underscore.humanize.downcase %> from being saved:
</h2>
<p>There were problems with the following fields:</p>
<ul>
<% object.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
This my _micropost_form.html.erb
<%= form_for(#micropost) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.text_area :content %>
</div>
<div class="=actions">
<%= f.submit "Submit" %>
</div>
<%end%>
This is _fields.html.erb
<%= render 'shared/error_messages'%>
<div class="field">
<%= f.label :name %><br/>
<%= f.text_field :name%>
</div>
<div class="field">
<%= f.label :email %><br/>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br/>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br/>
<%= f.password_field :password_confirmation %>
</div>
Errors 2 through 15 have a simple fix: your _fields.html.erb is missing some code on the first line. The entire line should read:
app/views/layouts/_fields.html.erb
<%= render 'shared/error_messages', object: f.object %> #object: f.object allows the form variable to
#access the associated object.
Unfortunately I can't do anything with the rest of your errors since your relevant code isn't attached.
This is still an issue in the latest version of the book as of this posting.
Earlier in the book the fields for user related forms were refactored and put in a partial _fields.html.erb where the shared/error_messages was rendered.
The users/new and users/edit files don't need to be modified, as stated in the book, and instead the only part that needs to be modified is _fields.html.erb to pass object: f.object to shared/error_messages
I had this issue as well, to fix it I didn't adjust the code from Michael's example, I just moved the _fields.html.erb partial from the views/users folder to the views/shared folder. Once in the shared folder it seemed to accept objects from both controllers. Hope this helps.
I think you need to go to the file that is calling the _error_messages partial and simply make sure you're calling it using the following:
<%= render 'shared/error_messages', object: f.object %>
This is because you're adding the hidden field tag.
Update Saturday April 23, 2011
Lesson is green after implementing the following in user.rb
def authenticate_with_salt(id, cookie_salt)
user = find_by_id(id)
(user && user.salt == cookie_salt) ? user : nil
end
I get:
Failures:
1) SessionsController POST 'create' success should sign the user in
Failure/Error: controller.current_user.should == #user
ArgumentError:
wrong number of arguments (1 for 2)
# ./app/models/user.rb:45:in `authenticate_with_salt'
# ./app/helpers/sessions_helper.rb:36:in `user_from_remember_token'
# ./app/helpers/sessions_helper.rb:14:in `current_user'
# ./spec/controllers/sessions_controller_spec.rb:58:in `block (4 levels) in <top (required)>'
Finished in 0.54296 seconds
7 examples, 1 failure
I am continuing to investigate... oh the joy! :D
EDIT: Working on finishing lesson 9 then will post back here -- seems that im back onto the path finding the problem myself again thanks to GrahamJRoy!
Update Friday April 22, 2011 :
I've spent the last day trying to find the similar problem but have been sorely unsuccessful, if you need any more information please let me know, both failures are highly likely related to each other so if i fix one i think it will fix the other
Failures:
1) SessionsController POST 'create' success should sign the user in
Failure/Error: post :create, :session => #attr
NameError:
undefined local variable or method `clear_return_to' for #<SessionsController:0x00000101648ac8>
# ./app/helpers/sessions_helper.rb:28:in `redirect_back_or'
# ./app/controllers/sessions_controller.rb:16:in `create'
# ./spec/controllers/sessions_controller_spec.rb:51:in `block (4 levels) in <top (required)>'
2) SessionsController POST 'create' success should redirect to the user show page
Failure/Error: post :create, :session => #attr
NameError:
undefined local variable or method `clear_return_to' for #<SessionsController:0x00000100ea0690>
# ./app/helpers/sessions_helper.rb:28:in `redirect_back_or'
# ./app/controllers/sessions_controller.rb:16:in `create'
# ./spec/controllers/sessions_controller_spec.rb:57:in `block (4 levels) in <top (required)>'
Finished in 0.42858 seconds
7 examples, 2 failures
In sessions helper.rb file:
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
clear_return_to
end
In sessions_controller_spec.rb file:
it "should sign the user in" do
post :create, :session => #attr
controller.current_user.should == #user
controller.should be_signed_in
end
it "should redirect to the user show page" do
post :create, :session => #attr
response.should redirect_to(user_path(#user))
end
In sessions_controller.rb file:
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
#title = "Sign in"
render 'new'
else
sign_in user
redirect_back_or user
end
end
Original Problem below:
I'm currently working in Lesson 9 on the Ruby on Rails Tutorial and am getting the following error when running autotest:
Failures:
1) SessionsController POST 'create' success should sign the user in
Failure/Error: post :create, :session => #attr
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x000001017082d8>
# ./app/controllers/sessions_controller.rb:15:in `create'
# ./spec/controllers/sessions_controller_spec.rb:51:in `block (4 levels) in <top (required)>'
2) SessionsController POST 'create' success should redirect to the user show page
Failure/Error: post :create, :session => #attr
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x00000100ecbca0>
# ./app/controllers/sessions_controller.rb:15:in `create'
# ./spec/controllers/sessions_controller_spec.rb:57:in `block (4 levels) in <top (required)>'
sessions_controller_spec.rb:
it "should sign the user in" do
post :create, :session => #attr
controller.current_user.should == #user
controller.should be_signed_in
end
it "should redirect to the user show page" do
post :create, :session => #attr
response.should redirect_to(user_path(#user))
end
IF i comment out the above sessions_controller_spec.rb I will be GREEN! Possibly that will help someone guide me in the right direction as I am clueless!
sessions_controller.rb:
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
#title = "Sign in"
render 'new'
else
sign_in user
redirect_back_or user
end
end
sessions_helper.rb:
def sign_in(user)
cookies.permanent.signed[:remember_token] = [user.id, user.salt]
self.current_user = user
end
ADDED per GrahamJRoy 'include SessionsHelper' in application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
end
2 new errors that I think are leading to my problem:
Failures:
1) SessionsController POST 'create' success should sign the user in
Failure/Error: post :create, :session => #attr
NoMethodError:
undefined method `redirect_back_or' for #<SessionsController:0x0000010405adc0>
# ./app/controllers/sessions_controller.rb:16:in `create'
# ./spec/controllers/sessions_controller_spec.rb:51:in `block (4 levels) in <top (required)>'
2) SessionsController POST 'create' success should redirect to the user show page
Failure/Error: post :create, :session => #attr
NoMethodError:
undefined method `redirect_back_or' for #<SessionsController:0x000001030a3c60>
# ./app/controllers/sessions_controller.rb:16:in `create'
# ./spec/controllers/sessions_controller_spec.rb:57:in `block (4 levels) in <top (required)>'
Per the documentation, have you referenced the SessionsHelper in the ApplicationController?
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
end
So I basically backtracked and started the lesson over again and carefully commented out the code on each page that shouldnt be there.
My Saturday update above made me start inspecting what the failure was showing, so I went to each line it mentioned and checked RailsTutorial git repo to see any obvious differences.
This led to the * next to the remember_token
User.authenticate_with_salt(*remember_token)
When adding that * the error changed from
Failures:
1) SessionsController POST 'create' success should sign the user in
Failure/Error: controller.current_user.should == #user
ArgumentError:
wrong number of arguments (1 for 2)
# ./app/models/user.rb:45:in `authenticate_with_salt'
# ./app/helpers/sessions_helper.rb:36:in `user_from_remember_token'
# ./app/helpers/sessions_helper.rb:14:in `current_user'
# ./spec/controllers/sessions_controller_spec.rb:58:in `block (4 levels) in <top (required)>'
Finished in 0.54296 seconds
7 examples, 1 failure
to:
Failures:
1) SessionsController POST 'create' success should sign the user in
Failure/Error: controller.should be_signed_in
NoMethodError:
undefined method `signed_in?' for #<SessionsController:0x00000104086088>
# ./spec/controllers/sessions_controller_spec.rb:59:in `block (4 levels) in <top (required)>'
Finished in 1.73 seconds
63 examples, 1 failure
At which point i checked my code:
def signed_in
!current_user.nil?
end
to the git repoos:
def signed_in?
!current_user.nil?
end
And conveniently saw a '?' missing which I figured I would add and see what happens..
And apparently I'm green now... lets finish this lesson now!
Many thanks to GrahamJRoy for your input!