Using Rails 5.1.4, Ruby 2.4
I am attempting to connect to an API using Faraday which I've done before without issue, but I'm getting the following error when I run RSpec:
SearchController GET #index returns http success
Failure/Error: response = #conn.get("/congress/v1/members/house/#{state}/current.json")
NoMethodError:
undefined method `get' for nil:NilClass
Did you mean? gem
# ./app/controllers/search_controller.rb:9:in `block in index'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/faraday-0.13.1/lib/faraday/connection.rb:88:in `initialize'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/faraday-0.13.1/lib/faraday.rb:67:in `new'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/faraday-0.13.1/lib/faraday.rb:67:in `new'
# ./app/controllers/search_controller.rb:5:in `index'
# ./spec/controllers/search_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
2) user can search for house members user submits a valid state name
Failure/Error: response = #conn.get("/congress/v1/members/house/#{state}/current.json")
NoMethodError:
undefined method `get' for nil:NilClass
Did you mean? gem
# ./app/controllers/search_controller.rb:9:in `block in index'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/faraday-0.13.1/lib/faraday/connection.rb:88:in `initialize'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/faraday-0.13.1/lib/faraday.rb:67:in `new'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/faraday-0.13.1/lib/faraday.rb:67:in `new'
# ./app/controllers/search_controller.rb:5:in `index'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/etag.rb:25:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/conditional_get.rb:25:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:232:in `context'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/rack/logger.rb:36:in `call_app'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/rack/logger.rb:24:in `block in call'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/rack/logger.rb:24:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:522:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
# /Users/user/.rvm/gems/ruby-2.4.0#global/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/rack-test-0.7.0/lib/rack/mock_session.rb:30:in `request'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/rack-test-0.7.0/lib/rack/test.rb:249:in `process_request'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/rack-test-0.7.0/lib/rack/test.rb:59:in `get'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/rack_test/browser.rb:69:in `process'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/rack_test/browser.rb:41:in `process_and_follow_redirects'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/rack_test/browser.rb:32:in `submit'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/rack_test/form.rb:78:in `submit'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/rack_test/node.rb:64:in `click'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/node/element.rb:143:in `block in click'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/node/base.rb:85:in `synchronize'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/node/element.rb:143:in `click'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/node/actions.rb:25:in `click_link_or_button'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/session.rb:776:in `block (2 levels) in <class:Session>'
# /Users/user/.rvm/gems/ruby-2.4.0/gems/capybara-2.15.1/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
# ./spec/features/user_can_search_by_state_spec.rb:11:in `block (2 levels) in <top (required)>'
Here is my Search controller, where the logic resides until I can fix this error and extract it elsewhere:
class SearchController < ApplicationController
def index
state = params[:state]
#conn = Faraday.new(url: "https://api.propublica.org") do |faraday|
faraday.headers["X-API-KEY"] = "<$MY-API-KEY>"
faraday.adapter Faraday.default_adapter
response = #conn.get("/congress/v1/members/house/#{state}/current.json")
results = JSON.parse(response.body, symbolize_names: true)[:results]
#members = results.map do |result|
Member.new(result)
end
end
end
end
And to be thorough, here is my Member model:
class Member
attr_reader :name,
:role,
:party,
:district,
:seniority
def initialize(attributes = {})
#name = attributes[:name]
#role = attributes[:role]
#party = attributes[:party]
#district = attributes[:district]
#seniority = attributes[:seniority]
end
end
#conn is not being properly defined, so when it tries to call #conn.get it's really calling nil.get which raises undefined method get for nil. Ensure you have defined #conn before you try to reference it. I have cleaned up your example to show the issue:
class SearchController < ApplicationController
def index
state = params[:state]
#conn = Faraday.new(url: "https://api.propublica.org") do |faraday|
faraday.headers["X-API-KEY"] = "<$MY-API-KEY>"
faraday.adapter Faraday.default_adapter
# you are trying to reference #conn here
response = #conn.get("/congress/v1/members/house/#{state}/current.json")
results = JSON.parse(response.body, symbolize_names: true)[:results]
#members = results.map do |result|
Member.new(result)
end
end # but #conn is not defined until you get here
end
end
If you refactor your code, it should look something more like this:
class SearchController < ApplicationController
def index
state = params[:state]
# fully define your #conn object
#conn = Faraday.new(url: "https://api.propublica.org") do |faraday|
faraday.headers["X-API-KEY"] = "<$MY-API-KEY>"
faraday.adapter Faraday.default_adapter
end
# now you can reference it
response = #conn.get("/congress/v1/members/house/#{state}/current.json")
results = JSON.parse(response.body, symbolize_names: true)[:results]
#members = results.map do |result|
Member.new(result)
end
end
end
Related
I recently ran into an issue with an integration test using rspec.
RSpec.describe "Images", type: :request do
before(:each) do
#user = User.create(username: "sam", password: "password")
#tag = #user.tags.create(name: "outdoors")
post login_path, params: { username: "sam", password: "password" }
expect(session[:user_id]).to eql #user.id
#file = fixture_file_upload("/dingo.jpeg", "image/jpeg")
end
it "can show images" do
#image = #user.images.create(caption: "hello", image_file: #image)
get user_image_path(#user, #image)
expect(response).to be_success
end
end
The before each creates a valid user, tag and logs the user in. Then it loads an image file.
The test it's self creates a new image for the #user and assigns it a value for caption and the loaded file for its :image_file.
The Image model uses has_one_attached :image_file to associate an uploaded image with an image record
class Image < ApplicationRecord
belongs_to :user
has_and_belongs_to_many :tags
has_one_attached :image_file
end
the controller and action as follows:
class ImageController < ApplicationController
before_action :unauthorized_redirect
def show
#user = current_user
#image = Image.find(params[:id])
#tags = #user.tags.all
authorize #image, :show?
end
private
def image_params
params.require(:image).permit(:caption, :image_file, tag_ids: [])
end
end
When I run the test I get an error:
Failures:
1) Images can show images
Failure/Error: <%= image_tag #image.image_file, class: "img-fluid show-image" %>
ActionView::Template::Error:
Can't resolve image into URL: undefined method `persisted?' for nil:NilClass
# ./app/views/image/show.html.erb:7:in `_app_views_image_show_html_erb__3727703739275822003_20580'
# <internal:kernel>:90:in `tap'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/actiontext-6.1.4.1/lib/action_text/rendering.rb:20:in `with_renderer'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/actiontext-6.1.4.1/lib/action_text/engine.rb:59:in `block (4 levels) in <class:Engine>'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/railties-6.1.4.1/lib/rails/rack/logger.rb:37:in `call_app'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/railties-6.1.4.1/lib/rails/rack/logger.rb:26:in `block in call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/railties-6.1.4.1/lib/rails/rack/logger.rb:26:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/railties-6.1.4.1/lib/rails/engine.rb:539:in `call'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rack-test-1.1.0/lib/rack/test.rb:119:in `request'
# /home/sam/.rvm/gems/ruby-3.0.0/gems/rails-controller-testing-1.0.5/lib/rails/controller/testing/integration.rb:16:in `block (2 levels) in <module:Integration>'
# ./spec/requests/images_spec.rb:38:in `block (2 levels) in <main>'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `persisted?' for nil:NilClass
# ./app/views/image/show.html.erb:7:in `_app_views_image_show_html_erb__3727703739275822003_20580'
Finished in 0.79372 seconds (files took 0.46552 seconds to load)
30 examples, 1 failure
Failed examples:
rspec ./spec/requests/images_spec.rb:36 # Images can show images
I have debugged this issue with breakpoints everywhere and I just don't understand why it's not working in test when it works in production. I hope I've provided enough information this bug has been driving me crazy for the past two days.
Thank you!
Versions:
rails: 6.1.4.1
rspec: 5.0.2
Changed one line and fixed it
it "can show images" do
#image = #user.images.create(caption: "hello", image_file: #image)
get user_image_path(#user, #image)
*expect(response).to be_success ----REMOVE*
expect(response.successful?).to eql true
end
Using Rails 5.2.1,
I am adding a customization possibility to my app which is basically a blog...
The app has a landing page that could be customized, the blog owner could change the images, colors etc...
So I've created a customization controller, model plus uploaders for each images that can be personalised.
Customization has only one instance.
So Locally everything works like a charm.
Rspec fails since I am calling #customization in the landing page...
It's not possible anymore to add or edit images in the Article
rspec failures
Failures:
1) managing article The admin is logged in edit a article text
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/images/fallback/default.png"
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:28:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:68:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `each'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/capybara-3.7.2/lib/capybara/server/middleware.rb:48:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ------------------
# --- Caused by: ---
# Capybara::CapybaraError:
# Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/capybara-3.7.2/lib/capybara/session.rb:144:in `raise_server_error!'
2) managing article The admin is logged in add images for an article
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/images/fallback/default.png"
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:28:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:68:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `each'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/capybara-3.7.2/lib/capybara/server/middleware.rb:48:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ------------------
# --- Caused by: ---
# Capybara::ElementNotFound:
# Unable to find visible css "#label_uploader_2"
# ./spec/features/managing_article_spec.rb:51:in `block (3 levels) in <top (required)>'
customization_controller.rb
class CustomizationController < ApplicationController
before_action :authorize
def show
#customization = Customization.instance
end
def update
#customization = Customization.instance
if #customization.update(customization_params)
redirect_to customization_path, notice: "Successfully updated"
end
end
private
def customization_params
params.require(:customization).permit(
:main_image,
:first_section_image,
:second_section_image,
:third_section_image,
:menu_color,
:body_color,
:icon_color,
:about,
:avatar
)
end
end
customization.rb
class Customization < ApplicationRecord
mount_uploader :avatar, AvatarUploader
mount_uploader :main_image, MainImageUploader
mount_uploader :first_section_image, FirstSectionImageUploader
mount_uploader :second_section_image, SecondSectionImageUploader
mount_uploader :third_section_image, ThirdSectionImageUploader
INSTANCE_ID = 87
def self.instance
Customization.find_or_create_by(id: INSTANCE_ID)
end
end
the uploader
class ThirdSectionImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
if Rails.env.production?
storage :fog
else
storage :file
end
version :thumb do
process resize_to_fill: [280, 280]
end
def default_url(*args)
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
home_controller.rb
class HomeController < ApplicationController
def index
#customization = Customization.instance
end
end
home/index.html.rb - aka landing page
<%= link_to videos_path do %>
<figure class="figure">
<%= image_tag(#customization.third_section_image_url.present? ? #customization.third_section_image_url : "https://s3-eu-west-1.amazonaws.com/beehappy/images_site/bibi.jpg", class: 'figure-img img-fluid') %>
<figcaption class="figure-caption text-gold">Media</figcaption>
</figure>
<% end %>
UPDATE
articles_spec.rb
require "rails_helper"
RSpec.feature "managing articles" do
fixtures :articles, :user
context "The admin is logged in" do
before :each do
login_as :admin
end
scenario "edit an article text", :js do
guitar = articles(:fender)
visit article_path(guitar)
find(".edit_link").click
fill_in "article[title]", with: "Fender Telecaster"
click_on "Update Me"
expect(page).to have_content("Article was successfully updated")
end
scenario "add images for a guitar" do
guitar = articles(:gibson)
visit article_path(guitar)
find(".edit_link").click
click_on "Add pictures"
within "#label_uploader_2" do
within "#span_uploader_2" do
attach_file("article[attachments][]" , Rails.root.join("spec/assets/images/img_2.jpg"))
end
end
click_on "Update"
expect(page).to have_content("Successfully added")
end
end
end
The actual error is No route matches [GET] "/images/fallback/default.png". You are setting a default path on your carrierwave uploader but it looks like the image is missing. Where's that image? for that route to work it should be in /public/images/fallback/default.png
it "renders index page" do
projects_user = FactoryGirl.create(:projects_user)
get :index, id: projects_user.id
expect(response).to render_template :index
end
this is my controller test, when i run it it says: Validation failed: Countries can't be blank
I am new to stackoverflow and ruby soo any help i get is great
FilesController:
class FilesController < ApplicationController
before_filter :authenticate_user!
def index
#pu = ProjectsUser.find(params[:id])
debugger
#files = UserFile.includes(:user).where(project_id: #pu.id)
end
def new
#file = UserFile.new
end
def create
#file = UserFile.new(file_params)
if #file.save
flash[:success] = "File successfully uploaded!"
redirect_to files_path
else
#files = UserFile.includes(:user).where(user_id: current_user.id)
render :index
end
end
def destroy
#file = UserFile.find(params[:file_id])
if #file.destroy
flash[:success] = "File successfully deleted!"
redirect_to files_path
else
flash[:error] = "File could not be deleted."
redirect_to files_path
end
end
protected
def file_params
params.require(:user_file).permit(:file, :user_id, :created_at, :updated_at, :project_id)
end
end
Country controller:
class CountriesController < ApplicationController
def states
#states = State.where(country_id: params[:id]).all
return render :json => {success: true, status: 200, data: #states}
end
end
Country model:
class Country < ActiveRecord::Base
validates :name, presence: true
has_many :states
has_many :users
has_and_belongs_to_many :projects
validates :name, presence: true
end
Factory for country:
require 'ffaker'
FactoryGirl.define do
factory :country do
name {FFaker::AddressUS.country}
end
end
output of error:
ActiveRecord::RecordInvalid:
Validation failed: Countries can't be blank
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib /factory_girl/configuration.rb:18:in `block in initialize'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:15:in `[]'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:15:in `create'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `tap'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:5:in `association'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluator.rb:33:in `association'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute/association.rb:19:in `block in to_proc'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluator.rb:77:in `instance_exec'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluator.rb:77:in `block in define_attribute'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:56:in `get'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:12:in `object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/controllers/files_controllers_spec.rb:31:in `block (3 levels) in <top (required)>'
UPDATE:
Factory for project, project has_and_belongs_to_many countries
require 'ffaker'
FactoryGirl.define do
factory :project do
sponsor_name "John Pare"
title "Anea"
start_date Date.new(2016, 5, 7)
end_date Date.new(2017, 3, 6)
description {FFaker::Lorem.paragraph}
number_of_sites_planned "5"
estimated_enrollment "24"
feasibility_questionnaire File.open("#{Rails.root}/spec/internal_spec_files/app.pdf")
association :disease_type
association :disease_condition
association :user
association :project_category
association :project_subcategory
after(:create) do |m|
m.countries << build(:country)
end
end
end
The problem is within the
projects_user = FactoryGirl.create(:projects_user)
the creation code (where you defined this factory) does not set a country and this is why you get an error.
I have a resource called "parameters" that is nested under "tests" in my API. There relation is as follows: "A test has many parameters". I've structured my routes as follows
tests/:test_id/parameters/:parameter_id
and my rake routes gives:
test_parameters GET /tests/:test_id/parameters(.:format) parameters#index {:format=>:json}
POST /tests/:test_id/parameters(.:format) parameters#create {:format=>:json}
new_test_parameter GET /tests/:test_id/parameters/new(.:format) parameters#new {:format=>:json}
edit_test_parameter GET /tests/:test_id/parameters/:id/edit(.:format) parameters#edit {:format=>:json}
test_parameter GET /tests/:test_id/parameters/:id(.:format) parameters#show {:format=>:json}
PATCH /tests/:test_id/parameters/:id(.:format) parameters#update {:format=>:json}
PUT /tests/:test_id/parameters/:id(.:format) parameters#update {:format=>:json}
DELETE /tests/:test_id/parameters/:id(.:format) parameters#destroy {:format=>:json}
I'm writing simple rspec tests to test all the typical actions of my API. Right now, my POST/CREATE is giving me a very puzzling error.
Failures:
1) ParametersController POST create a new parameter with valid attributes successfully with name and times
Failure/Error: post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
NoMethodError:
undefined method `parameter_url' for #<ParametersController:0x000001072b4280>
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/polymorphic_routes.rb:220:in `polymorphic_method'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/url_for.rb:163:in `url_for'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rendering.rb:95:in `_process_options'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/streaming.rb:200:in `_process_options'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/renderers.rb:43:in `block in _render_to_body_with_renderer'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/renderers.rb:41:in `_render_to_body_with_renderer'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/rendering.rb:25:in `render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rendering.rb:16:in `render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/core_ext/benchmark.rb:12:in `ms'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.2/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:43:in `render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:258:in `display'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:214:in `api_behavior'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:191:in `rescue in to_format'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:185:in `to_format'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:163:in `respond'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:156:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/respond_with.rb:203:in `respond_with'
# ./app/controllers/parameters_controller.rb:13:in `create'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/base.rb:198:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:117:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:117:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:505:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:505:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:92:in `_run_callbacks'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `block in instrument'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `instrument'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.2/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/base.rb:137:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionview-4.2.2/lib/action_view/rendering.rb:30:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/test_case.rb:632:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/test_case.rb:65:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/test_case.rb:514:in `post'
# ./spec/controllers/parameters_controller_spec.rb:34:in `block (5 levels) in <top (required)>'
# ./spec/controllers/parameters_controller_spec.rb:33:in `block (4 levels) in <top (required)>'
I've tried changing the formats in how I'm submitting the POST but that hadn't changed anything. For now, my rspec test looks like this:
"spec/controllers/parameters_controller_spec.rb"
require 'spec_helper'
describe ParametersController do
before :each do
#test = FactoryGirl.create(:test, id: 1, name: 'Eccentric Tech')
#test.save
end
# ...
describe 'POST create a new parameter' do
context 'with valid attributes' do
it 'successfully with name and times' do
parameter = FactoryGirl.build(:parameter)
expect {
post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
}.to change(Parameter, :count).by(1)
end
end
context 'with invalid attributes' do
it 'fails without a name' do
parameter = FactoryGirl.build(:no_name_parameter)
expect {
post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
}.to change(Parameter, :count).by(0)
end
it 'fails without belonging to a test' do
parameter = FactoryGirl.build(:no_test_parameter)
expect {
post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
}.to change(Parameter, :count).by(0)
end
end
end
# ...
end
My Factory:
"spec/factories/parameters.rb"
require 'faker'
FactoryGirl.define do
factory :parameter do |f|
f.name { "#{Faker::Hacker.noun}" }
f.value { Faker::Number.number(2) }
f.test_id { 1 }
end
factory :no_name_parameter, parent: :parameter do |f|
f.name nil
f.value { Faker::Number.number(2) }
f.test_id { 1 }
end
factory :no_test_parameter, parent: :parameter do |f|
f.name { "#{Faker::Hacker.noun}" }
f.value { Faker::Number.number(2) }
f.test_id nil
end
end
And finally, my controller:
class ParametersController < ApplicationController
respond_to :json
def index
respond_with Parameter.all
end
def show
respond_with Parameter.find(params[:id])
end
def create
respond_with Parameter.create(parameter_params)
end
def update
respond_with Parameter.update(params[:id], parameter_params)
end
def destroy
respond_with Parameter.destroy(params[:id])
end
private
def parameter_params
params.require(:parameter).permit(:name, :value, :test_id)
end
end
routes.rb:
Rails.application.routes.draw do
scope :defaults => { :format => :json } do
resources :services do
resources :tests
end
resources :tests do
resources :parameters
resources :singular_results
resources :dataset_results
end
end
end
I solved this myself but I have nooooo idea why it works. If someone could explain it please do :)
All I did was make this small change to my controller:
def create
respond_with Parameter.create(parameter_params), location: nil
end
Found a good explanation: Rails: NoMethodError (Undefined method _url for _controller. I can't seem to respond_with json properly after my create. Why?
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