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.
Related
I'm Trying to build a simple Blog using rails 4 and For authentication I'm using Devise.
The blog is simple and it will only have one registered user which is the admin. so the registration page should be available when there are no users in the database else it will redirect to the home page.
I'm trying to learn testing in the process. So I started testing the RegistrationContrroler However it doesn't seem to pass.
class RegistrationsController < Devise::RegistrationsController
before_action :one_user_registered?, only: [:new, :create]
protected
def one_user_registered?
if ((User.count == 1) & (user_signed_in?))
redirect_to root_path
elsif User.count == 1
redirect_to new_user_session_path
end
end
end
Specs:
RSpec.describe RegistrationsController, type: :controller do
context "Admin already registred" do
it "cannot create new user" do
#user_attr = FactoryGirl.attributes_for(:user)
# Create Admin
User.create!(#user_attr)
#request.env["devise.mapping"] = Devise.mappings[:user]
post :create, user: #user_attr
User.count should eq_to(1)
end
end
end
spec/factories.rb :
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user#{n}#example.com" }
password "secure"
end
factory :post do
sequence(:id){ |n| n }
sequence(:title) { |n| "Post title #{n}" }
body "Post body"
sequence(:slug) { |n| "Post title #{n}" }
end
end
routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: "registrations" }
authenticated :user do
resources :posts
end
unauthenticated :user do
resources :posts, only: [:show, :index]
end
root 'posts#index'
end
Stacktrace :
F
Failures:
1) RegistrationsController Admin already registred cannot create new user
Failure/Error: User.count should eq_to(1)
expected: 1
got: #<RegistrationsController:0x00000003a413b8 #_action_has_layout=true, #_routes=nil, #_headers={"Conten...enticatable]>, #req touest_format=:html, #marked_for_same_origin_verification=false, #current_user=nil>
(compared using ==)
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:87:in `block in <module:Support>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:96:in `notify_failure'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/fail_with.rb:27:in `fail_with'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:38:in `handle_failure'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:27:in `with_matcher'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/memoized_helpers.rb:81:in `should'
# ./spec/controllers/registrations_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:252:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:252:in `block in run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:494:in `block in with_around_and_singleton_context_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:451:in `block in with_around_example_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:471:in `block in run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:611:in `block in run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:336:in `call'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-rails-3.5.1/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:382:in `execute_with'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:613:in `block (2 levels) in run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:336:in `call'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-rails-3.5.1/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:382:in `execute_with'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:613:in `block (2 levels) in run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:336:in `call'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:614:in `run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:471:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:451:in `with_around_example_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:494:in `with_around_and_singleton_context_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:249:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:623:in `map'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:623:in `run_examples'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:589:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:590:in `block in run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:590:in `map'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:590:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:113:in `map'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:1836:in `with_suite_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/reporter.rb:77:in `report'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:111:in `run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:87:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:71:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:45:in `invoke'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/exe/rspec:4:in `<top (required)>'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `load'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `<main>'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Finished in 0.08188 seconds (files took 1.95 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/registrations_controller_spec.rb:7 # RegistrationsController Admin already registred cannot create new user
You're missing a dot!
User.count.should eq_to(1)
Adding a should method is the way rspec patches all objects to support the should comparisons.
Preferable would be...
expect(User.count).to eq(1)
The error showed that the should by itself was received by the RegistrationsController, not by the User.count... and of course the RegistrationsController doesn't equal 1.
This test gives no reason as to why it fails:
it "saves the new job in the database" do
expect{
post :create, booking: FactoryGirl.attributes_for(:booking)
}.to change(Booking,:count).by(1)
end
The test seems simple enough, and the functionality works in the site.
UPD For reference, here's the controller it's testing:
def create
#booking = Booking.new(booking_params)
#booking.save
respond_with(#booking)
end
And the factory:
FactoryGirl.define do
factory :booking do
employer
vehicle
job_type
location
start "2015-04-23 09:00"
ending "2015-04-23 15:00"
end
end
UPD Here's the rspec log, with -b:
BookingsController
as employer
GET #new
renders the :new template (PENDING: Not yet implemented)
assigns a new job to #job (PENDING: Not yet implemented)
GET #create
with invalid attributes
re-renders the :new template (PENDING: Not yet implemented)
does not save in the database (PENDING: Not yet implemented)
with valid attributes
redirects to the show page (PENDING: Not yet implemented)
in populate_times
saves the new job in the database (FAILED - 1)
GET #create
with invalid attributes
re-renders the :new template (PENDING: Not yet implemented)
does not save in the database (PENDING: Not yet implemented)
with valid attributes
redirects to the show page (PENDING: Not yet implemented)
saves the new job in the database (PENDING: Not yet implemented)
GET new
renders the new template
GET #show
renders the :show template (PENDING: Not yet implemented)
assigns the requested booking to #booking (PENDING: Not yet implemented)
as visitor
GET new
redirects to new_employer_path
Pending: (Failures listed here are expected and do not affect your suite's status)
1) BookingsController as employer GET #new renders the :new template
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:60
2) BookingsController as employer GET #new assigns a new job to #job
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:59
3) BookingsController as employer GET #create with invalid attributes re-renders the :new template
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:38
4) BookingsController as employer GET #create with invalid attributes does not save in the database
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:37
5) BookingsController as employer GET #create with valid attributes redirects to the show page
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:33
6) BookingsController as employer GET #create with invalid attributes re-renders the :new template
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:71
7) BookingsController as employer GET #create with invalid attributes does not save in the database
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:70
8) BookingsController as employer GET #create with valid attributes redirects to the show page
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:66
9) BookingsController as employer GET #create with valid attributes saves the new job in the database
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:65
10) BookingsController as employer GET #show renders the :show template
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:55
11) BookingsController as employer GET #show assigns the requested booking to #booking
# Not yet implemented
# ./spec/controllers/booking_controller_spec.rb:43
Failures:
1) BookingsController as employer GET #create with valid attributes saves the new job in the database
Failure/Error: expect{
expected #count to have changed by 1, but was changed by 0
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:40:in `handle_failure'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:27:in `with_matcher'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/expectation_target.rb:54:in `to'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/expectation_target.rb:87:in `to'
# ./spec/controllers/booking_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:177:in `instance_exec'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:177:in `block in run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:385:in `block in with_around_and_singleton_context_hooks'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:343:in `block in with_around_example_hooks'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:474:in `block in run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:614:in `block in run_around_example_hooks_for'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-rails-3.2.1/lib/rspec/rails/example/controller_example_group.rb:179:in `block (2 levels) in <module:ControllerExampleGroup>'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:387:in `execute_with'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-rails-3.2.1/lib/rspec/rails/adapters.rb:113:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:387:in `execute_with'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:617:in `run_around_example_hooks_for'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:474:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:343:in `with_around_example_hooks'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:385:in `with_around_and_singleton_context_hooks'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:174:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:549:in `block in run_examples'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:545:in `map'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:545:in `run_examples'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:512:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `block in run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `map'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `block in run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `map'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `block in run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `map'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `block (3 levels) in run_specs'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `map'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `block (2 levels) in run_specs'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1526:in `with_suite_hooks'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:109:in `block in run_specs'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/reporter.rb:62:in `report'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:108:in `run_specs'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:86:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/bin/rspec:23:in `load'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/bin/rspec:23:in `<main>'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
# /Users/Will/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'
I can't add comments cause of my reputation ... but maybe u shoud try to run rspec with -b option to see full backtraces. And detect the error
I have two methods in my Designer class (in my rails app):
def add_specialty(specialty)
specialty_list.add(specialty)
save
end
def add_qualification(qualification)
qualification_list.add(qualification)
save
end
Here are specs I have for them that are passing:
context 'adding specialties' do
it "can add a new specialty" do
expect { designer.add_specialty("interior design") }.to change {designer.specialty_list.count}.by(1)
expect(designer.specialty_list).to include("interior design")
end
end
context 'adding qualifications' do
it "can add a new qualification" do
expect { designer.add_qualification("architect") }.to change {designer.qualification_list.count}.by(1)
expect(designer.qualification_list).to include("architect")
end
end
Now I want to refactor to this implementation:
["specialty", "qualification"].each do |attr|
define_method("add_#{attr}") do |arg|
"#{attr}_list".add(arg)
save
end
end
This fails. I get failures:
1) Designer adding qualifications can add a new qualification
Failure/Error: expect { designer.add_qualification("architect") }.to change {designer.qualification_list.count}.by(1)
NoMethodError:
undefined method `add' for "qualification_list":String
# ./app/models/designer.rb:93:in `block (2 levels) in <class:Designer>'
# ./spec/models/designer_spec.rb:79:in `block (4 levels) in <top (required)>'
# ./spec/models/designer_spec.rb:79:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
2) Designer adding specialties can add a new specialty
Failure/Error: expect { designer.add_specialty("interior design") }.to change {designer.specialty_list.count}.by(1)
NoMethodError:
undefined method `add' for "specialty_list":String
# ./app/models/designer.rb:93:in `block (2 levels) in <class:Designer>'
# ./spec/models/designer_spec.rb:72:in `block (4 levels) in <top (required)>'
# ./spec/models/designer_spec.rb:72:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
What am I doing wrong in my define_method implementation?
"#{attr}_list" by itself is just the string "specialty_list" or "qualification_list", and strings don't have an add method. I think you want to the send the specialty_list method e.g.
%w{ specialty qualification }.each do |attr|
define_method("add_#{attr}") do |arg|
send("#{attr}_list").add(arg)
save
end
end
Ok: I got it working like this:
["specialty", "qualification"].each do |attr|
define_method("add_#{attr}") do |arg|
instance_eval("#{attr}_list").send(:add, arg)
save
end
end
Not sure why this worked though or if its the right way to do it. Would anyone care to contribute towards a better understanding?
I'm following a clickatell tutorial and my code looks as follows. However I get the error
uninitialized constant ActionDispatch::Routing::Routes (NameError)
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:258:in `instance_exec'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:258:in `eval_block'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:235:in `draw'
from /Users/user1/Desktop/rails_projects/clickatellsms/config/routes.rb:1
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `load_paths'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `each'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `load_paths'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:13:in `reload!'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:7:in `initialize'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb:32:in `call'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/finisher.rb:63
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/finisher.rb:64:in `call'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application/finisher.rb:64
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `run_initializers'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `send'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/user1/Desktop/rails_projects/clickatellsms/config/environment.rb:5
from /Users/user1/Desktop/rails_projects/clickatellsms/config.ru:4:in `require'
from /Users/user1/Desktop/rails_projects/clickatellsms/config.ru:4
from /Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/builder.rb:51:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/builder.rb:51:in `initialize'
from /Users/user1/Desktop/rails_projects/clickatellsms/config.ru:1:in `new'
from /Users/user1/Desktop/rails_projects/clickatellsms/config.ru:1
My code looks like this -
# controllers/sms.rb:
require 'clickatell'
class SMS
def initialize(config)
#config = config
end
def create(recipient, message_text)
api.send_message(recipient, message_text)
end
private
def api
#api ||= Clickatell::API.authenticate(
#config[:api_key],
#config[:username],
#config[:password])
end
end
# config/clickatell.yml:
api_key: 9999999
username: abcdefg
password: hijklmno
# config/environments/development.rb
CLICKATELL_CONFIG = YAML.load(File.open(File.join(RAILS_ROOT,
'config', 'clickatell.yml')))
# config/routes.rb:
ActionController::Routing::Routes.draw do |map|
map.resource :sms
end
# app/views/sms/new.html.erb:
<% form_tag '/sms', :method => :post do -%>
<label>Enter the recipients mobile number:</label>
<%= text_field_tag "recipient" %>
<label>Enter your message:</label>
<%= text_area_tag "message_text" %>
<%= submit_tag "Send SMS" %>
<% end %>
# controllers/sms_controller.rb:
class SmsController < ApplicationController
def create
sms = SMS.new(CLICKATELL_CONFIG)
sms.create(params[:recipient], params[:message_text])
flash[:notice] = "Message sent succesfully!"
redirect_to :back
rescue Clickatell::API::Error => e
flash[:error] = "Clickatell API error: #{e.message}"
redirect_to :back
end
end
That's your routes.rb which is non sense:
ActionController::Routing::Routes.draw do |map|
map.resource :sms
end
It should rather be:
APP_NAME_HERE_CAMEL_CASE_STYLE::Application.routes.draw do
resource :sms
end
Looks like you copy/pasted old Rails 2 code within a Rails 3 app.
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.