Rails functional testing on has_and_belongs_to_many issue - ruby-on-rails

I am relatively new to Ruby and rails and am stuck on a issue I cannot get my head around. I have two models PricingRuleType and PricingRule that are set up as shown below.
class PricingRuleType < ActiveRecord::Base
attr_accessible :type_of_rule
has_and_belongs_to_many :product_rules
validates :type_of_rule, :presence => true
end
class ProductRule < ActiveRecord::Base
has_and_belongs_to_many :pricing_rule_types
validates :pricing_rule_type, :discount_per_unit, :number_of_units, :presence => true
validates :discount_per_unit, :numericality => {:greater_than_or_equal_to => 0.01}
end
The functional test for the create and update methods are shown below:
1) Error:
test_should_create_product_rule(ProductRulesControllerTest):
NoMethodError: undefined method `stringify_keys' for "revoo_rule":String
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:69:in `assign_attributes'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/base.rb:495:in `initialize'
/Users/kushaldsouza/Documents/Client Projects/Revoo/app/controllers/product_rules_controller.rb:44:in `new'
/Users/kushaldsouza/Documents/Client Projects/Revoo/app/controllers/product_rules_controller.rb:44:in `create'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/base.rb:167:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:414:in `_run__580034481047679801__process_action__1008436725406406543__callbacks'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `instrument'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/base.rb:121:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/rendering.rb:45:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/test_case.rb:464:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/test_case.rb:49:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/test_case.rb:385:in `post'
/Users/kushaldsouza/Documents/Client Projects/Revoo/test/functional/product_rules_controller_test.rb:27:in `block (2 levels) in <class:ProductRulesControllerTest>'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/testing/assertions.rb:55:in `assert_difference'
/Users/kushaldsouza/Documents/Client Projects/Revoo/test/functional/product_rules_controller_test.rb:26:in `block in <class:ProductRulesControllerTest>'
2) Error:
test_should_update_product_rule(ProductRulesControllerTest):
NoMethodError: undefined method `each' for "1":String
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/associations/collection_association.rb:308:in `replace'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/associations/collection_association.rb:41:in `writer'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/associations/builder/association.rb:51:in `block in define_writers'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:78:in `each'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/persistence.rb:212:in `block in update_attributes'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/persistence.rb:211:in `update_attributes'
/Users/kushaldsouza/Documents/Client Projects/Revoo/app/controllers/product_rules_controller.rb:63:in `block in update'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/mime_responds.rb:269:in `call'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/mime_responds.rb:269:in `retrieve_response_from_mimes'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
/Users/kushaldsouza/Documents/Client Projects/Revoo/app/controllers/product_rules_controller.rb:62:in `update'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/base.rb:167:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:414:in `_run__580034481047679801__process_action__1983642789249364420__callbacks'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `instrument'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/base.rb:121:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/abstract_controller/rendering.rb:45:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/test_case.rb:464:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/test_case.rb:49:in `process'
/Users/kushaldsouza/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_controller/test_case.rb:390:in `put'
/Users/kushaldsouza/Documents/Client Projects/Revoo/test/functional/product_rules_controller_test.rb:44:in `block in <class:ProductRulesControllerTest>'
My test controllers are shown below:
require 'test_helper'
class ProductRulesControllerTest < ActionController::TestCase
fixtures :product_rules
setup do
#product_rule = product_rules(:one)
#update = {
:number_of_units => 3,
:discount_per_unit => 2.3,
:pricing_rule_type => pricing_rule_types(:revoo_pricing_rule)
}
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:product_rules)
end
test "should get new" do
get :new
assert_response :success
end
test "should create product_rule" do
assert_difference('ProductRule.count') do
post :create, :product_rule => :revoo_rule
end
assert_redirected_to product_rule_path(assigns(:product_rule))
end
test "should show product_rule" do
get :show, id: #product_rule
assert_response :success
end
test "should get edit" do
get :edit, id: #product_rule
assert_response :success
end
test "should update product_rule" do
put :update, id: #product_rule.to_param, :product_rule => #update
assert_redirected_to product_rule_path(assigns(:product_rule))
end
test "should destroy product_rule" do
assert_difference('ProductRule.count', -1) do
delete :destroy, id: #product_rule
end
assert_redirected_to product_rules_path
end
end
I am not entirely sure why am I am getting that error and have been stuck on it for a while. Could this for any reason be due to the fact that I have included a has_and_belongs_to_many relationship. I have other models that are set up in a similar way to the above two but without this relationship and they don't seem to throw any errors.Any help is much appreciated.

In test "should create product_rule" what is :revoo_rule ?
Should it be:
post :create, :product_rule => #product_rule.to_param
And in test "should update product_rule" you have :product_rule => #update
In setup it should be defined as:
:pricing_rule_type_ids => pricing_rule_types(:revoo_pricing_rule).id

Related

ActionController::UnknownFormat on rails tests when passing json to controller

I am writing some tests for one of my controllers, and all of them are passing except the test for my #create method.
I cannot seem to get this test to pass. I understand that the UnknownFormat error is related to which format I am using (and the respond_to) to post to my controller, but even when I add a json or html format to the post - I still get the error.
Pulling my hair out over this test - would love some guidance on how best to rewrite this test for the best outcome.
The test
test "should create captable" do
sign_in #user
post company_captables_url(#company, #captable), params: { captable: { company_id: #captable.company_id, name: "Great captable!", version: #captable.version } }, as: :json
assert_response :success
end
The method from the controller:
def create
#captable = #company.captables.new(captable_params)
respond_to do |format|
if #captable.save
format.html { redirect_to [#company, #captable], notice: 'Captable was successfully created.' }
format.json { render :show, status: :created, location: [#company, #captable] }
else
format.html { render :new }
format.json { render json: #captable.errors, status: :unprocessable_entity }
end
end
end
The full backtrace on the error :
Error:
CaptablesControllerTest#test_should_create_captable:
ActionController::UnknownFormat: ActionController::UnknownFormat
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/mime_responds.rb:205:in `respond_to'
/Users/jamespember/calmcap/app/controllers/captables_controller.rb:24:in `create'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:194:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:132:in `run_callbacks'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/rescue.rb:22:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in `block in instrument'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in `instrument'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:134:in `process'
/usr/local/lib/ruby/gems/2.5.0/gems/actionview-5.2.1/lib/action_view/rendering.rb:32:in `process'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal.rb:191:in `dispatch'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_controller/metal.rb:252:in `dispatch'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:34:in `serve'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:52:in `block in serve'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:35:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:35:in `serve'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:840:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/warden-1.2.7/lib/warden/manager.rb:36:in `block in call'
/usr/local/lib/ruby/gems/2.5.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in `catch'
/usr/local/lib/ruby/gems/2.5.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/tempfile_reaper.rb:15:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/etag.rb:25:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/conditional_get.rb:38:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/head.rb:12:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:232:in `context'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:226:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/cookies.rb:670:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
/usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `block in call'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:28:in `tagged'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `tagged'
/usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
/usr/local/lib/ruby/gems/2.5.0/gems/rack-test-1.1.0/lib/rack/test.rb:119:in `request'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/testing/integration.rb:263:in `process'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/testing/integration.rb:24:in `post'
/usr/local/lib/ruby/gems/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/testing/integration.rb:350:in `block (2 levels) in <module:Runner>'
/Users/jamespember/calmcap/test/controllers/captables_controller_test.rb:39:in `block in <class:CaptablesControllerTest>'
You should change the test, because you're creating a new Captable entity. You don't need #captable variable here. And you don't need company_id inside the params - it is already in the url.
test "should create captable" do
sign_in #user
assert_difference '#company.captables.count', 1 do # it is good idea to check it was really created
post company_captables_url(#company), params: { captable: { name: "Great captable!", version: 'version_name' } }, as: :json
end
assert_redirected_to company_captable_url(#company, Captable.last)
end

Rake Task w/ ActionMailer - Undefined Method Error

I have a custom rake task and I am using a mailer with this task. I have an agent table with all of an agent's info. I also have an agent_card table that houses all of their license data. The agent_card table also has an agent_id column to identify which card goes with which agent. When trying to run the rake task and send out the mailer, I keep getting "ActionView::Template::Error: undefined method `name' for nil:NilClass." I can't figure out how to get the name, email, and phone through the agent_card table. I have included all the code below. Please and thank you!
Error:
rake aborted!
ActionView::Template::Error: undefined method `name' for nil:NilClass
/Users/michaelwiesenhart/Code/app/views/license_expire_mailer/license_expi re_mgr.html.erb:7:in `_app_views_license_expire_mailer_license_expire_mgr_html_erb___944550213720770297_70323524541360'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/template.rb:145:in `block in render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:166:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/template.rb:333:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/template.rb:143:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:14:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/renderer.rb:46:in `render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/renderer.rb:27:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/rendering.rb:100:in `_render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/rendering.rb:83:in `render_to_body'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/rendering.rb:25:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:904:in `block in collect_responses'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:918:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:918:in `each_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:900:in `collect_responses'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:829:in `mail'
/Users/michaelwiesenhart/Code/app/mailers/license_expire_mailer.rb:14:in `license_expire_mgr'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:198:in `process_action'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:19:in `process_action'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:137:in `process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/rendering.rb:30:in `process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:596:in `block in process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:593:in `process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:584:in `initialize'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:25:in `new'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:25:in `__getobj__'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:34:in `message'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:85:in `deliver_now'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:17:in `block (3 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:15:in `block (2 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#/bin/ruby_executable_hooks:15:in `eval'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#/bin/ruby_executable_hooks:15:in `<main>'
Agent Model:
has_one :agent_card
AgentCard Model:
belongs_to :agent
license_expire_mgr.html.erb
Hiya, <br><br>
The agent listed below has a license that will expire one week from today. Please make sure they renew before it expires!<br><br>
<strong>Name:</strong> <%= #agent.name %><br>
<strong>Phone:</strong> <%= #agent.phone %><br>
<strong>Email:</strong> <%= #agent.email %><br><br>
license_expire_mailer.rb
class LicenseExpireMailer < ActionMailer::Base
default from: "Mike <help#mike.com>"
def license_expire_mgr(agent_card, agent)
#agent_cards = agent_card
#agent = agent
mail to: "mike#mike.com", subject: "Agent License Expiring"
end
end
#agent is not being passed through to the mailer or the value of it is being evaluated as nil.
The problem is not with your rake task or your mailer, figure out why the param is nil and that will solve your problem.
I figured it out. I was trying to use agent_card and didn't need it. Once I removed it, it works just fine!

ruby Class.new returning nil in rspec

We are trying to test that our controller is calling a class a given number of times based on a param we have, but our test is failing in rspec, saying that the initialize method on our class is returning a nil.
We have this controller:
class ProcessFaxesController < ApplicationController
def create
email = params["From"]
attachment_count = params["attachment-count"].to_i
head :ok
if attachment_count > 0
attachment_count.times do |document_index|
FaxedDocumentProcessor.new(params, document_index+1).perform
end
else
DocumentProcessingMailer.delay.failure_notification(email, "No attachment found.")
end
end
end
The external class:
class FaxedDocumentProcessor
def initialize(params, document_index)
#params = params
#attachment = #params["attachment-#{document_index}"]
#email = #params['From']
end
def perform
# some stuff here
end
end
With this spec:
require 'rails_helper'
RSpec.describe ProcessFaxesController, type: :controller do
context "#create" do
context 'with attachments' do
before { allow_any_instance_of(FaxedDocumentProcessor).to receive(:perform).and_return(true) }
it 'calls the FaxedDocumentProcessor attachment-count times' do
expect(FaxedDocumentProcessor).to receive(:new).twice
post :create, 'email' => 'test#example.com', 'attachment-count' => 2)
end
end
end
end
This is the error we are getting from our test:
Failures:
1) ProcessFaxesController#create with attachments calls the FaxedDocumentProcessor attachment-count times
Failure/Error: FaxedDocumentProcessor.new(params, document_index+1).perform
NoMethodError:
undefined method `perform' for nil:NilClass
# ./app/controllers/process_faxes_controller.rb:20:in `block in create'
# ./app/controllers/process_faxes_controller.rb:19:in `times'
# ./app/controllers/process_faxes_controller.rb:19:in `create'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:198:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:117:in `call'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/activerecord-4.2.6/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:137:in `process'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionview-4.2.6/lib/action_view/rendering.rb:30:in `process'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/test_case.rb:639:in `process'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/test_case.rb:67:in `process'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/devise-3.5.6/lib/devise/test_helpers.rb:19:in `block in process'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/devise-3.5.6/lib/devise/test_helpers.rb:72:in `catch'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/devise-3.5.6/lib/devise/test_helpers.rb:72:in `_catch_warden'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/devise-3.5.6/lib/devise/test_helpers.rb:19:in `process'
# /Users/mary/.rvm/gems/ruby-2.3.0#website/gems/actionpack-4.2.6/lib/action_controller/test_case.rb:520:in `post'
# ./spec/controllers/process_faxes_controller_spec.rb:22:in `block (4 levels) in <top (required)>'
We've tried inserting binding.pry into the controller method to poke around ourselves, but whenever we try the call that's blowing up, we don't get any errors.
What could be causing FaxedDocumentProcessor.new to return a nil? And why can't we reproduce the error in pry?
This is caused by this:
expect(FaxedDocumentProcessor).to receive(:new).twice
The line above completely stubs new method. To make it calling original method, do:
expect(FaxedDocumentProcessor).to receive(:new).twice.and_call_original
Documentation: https://www.relishapp.com/rspec/rspec-mocks/v/2-14/docs/message-expectations/calling-the-original-method

Controller HTTP methods not working with rspec due to I18n.locale error?

So I'm trying to test controller methods with rspec tests, but they aren't working due to some issue with I18n? I'm getting this error message:
masonscott#amory:~/Workspace/cs169/cs169-smileygo$ rspec spec/controllers/reviews_controller_spec.rb
F..
Failures:
1) ReviewsController POST #create Review can be created
Failure/Error: I18n.locale = env.http_accept_language.preferred_language_from(available)
NoMethodError:
undefined method `http_accept_language' for {}:Hash
# ./app/controllers/application_controller.rb:22:in `set_locale'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:424:in `block in make_lambda'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:160:in `block in halting'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:229:in `block in halting'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:229:in `block in halting'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:86:in `run_callbacks'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/notifications.rb:159:in `block in instrument'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activesupport-4.1.4/lib/active_support/notifications.rb:159:in `instrument'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/activerecord-4.1.4/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:136:in `process'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionview-4.1.4/lib/action_view/rendering.rb:30:in `process'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/test_case.rb:595:in `process'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/test_case.rb:64:in `process'
# /home/masonscott/.rvm/gems/ruby-2.3.0/gems/actionpack-4.1.4/lib/action_controller/test_case.rb:501:in `post'
# ./spec/controllers/reviews_controller_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.01243 seconds (files took 1.96 seconds to load)
3 examples, 1 failure
Failed examples:
rspec ./spec/controllers/reviews_controller_spec.rb:6 # ReviewsController POST #create Review can be created
Coverage report generated for RSpec to /home/masonscott/Workspace/cs169/cs169-smileygo/coverage. 5 / 18 LOC (27.78%) covered.
What might be the issue here?
What might be the issue here?
The issue would seem to be that you're calling ActionController::Metal#env, an #_env variable hasn't been set, and you're being returned an empty hash, which doesn't respond to the http_accept_language method, but I don't think that knowledge will solve your problem.
It looks like you're using the HttpAcceptLanguage gem, and looking at its README file, it looks like that if you're going to use the http_accept_language method in a controller, you don't need to use it against env unless you're writing Rack middleware. Here is the example from the README file:
class SomeController < ApplicationController
before_filter :set_locale
private
def set_locale
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales)
end
end
Try changing your code to be like the example (ie removing env) and see if that works.

How to call predicate method in controller of rails 4?

I am new to rails and am trying to get the following bit of rspec to pass that will enable calling a path to flag a course as hidden:
describe 'PATCH hide_course' do
before :each do
#course = create(:course)
end
it 'marks the course as hidden' do
patch :hide_course, id: #course
expect(#course.reload.hidden?).to be_true
end
it 'redirects to courses#index' do
patch :hide_course, id: #course
expect(response).to redirect_to course_url
end
end
I then set the following route with no problems:
resources :courses
put '/courses/:id/hide_course', to: 'courses#hide_course'
My problem is in setting the controller action. Here is the bit I wrote in my CoursesController:
def hide_course
#course = Course.find(params[:id])
#course.hide
end
private
def course_params
params.require(:course).permit(:name,:description,:department,:hidden,
:lecture_attributes => [:name,:description,:level])
end
My model then looks like this:
def hide
update!(:hidden => true)
end
What is the best way for me to set up this method in rails 4? I keep getting errors about the hidden attribute not existing even though it is in my schema. Thanks!
PS- The backtrace I get for the first spec is this:
1) CoursesController PATCH hide_course marks the course as hidden
Failure/Error: patch :hide_course, id: #course
ActiveRecord::UnknownAttributeError:
unknown attribute: hidden
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/attribute_assignment.rb:59:in `rescue in _assign_attribute'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/attribute_assignment.rb:35:in `each'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/persistence.rb:262:in `block in update!'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/transactions.rb:218:in `transaction'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/transactions.rb:342:in `with_transaction_returning_status'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/persistence.rb:261:in `update!'
# ./app/models/course.rb:13:in `hide'
# ./app/controllers/courses_controller.rb:60:in `hide_course'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/abstract_controller/base.rb:198:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:114:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:114:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:231:in `block in halting'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:231:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:231:in `block in halting'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:166:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:166:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:231:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:231:in `block in halting'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:166:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:87:in `call'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/callbacks.rb:87:in `run_callbacks'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/notifications.rb:164:in `block in instrument'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.0.beta2/lib/active_support/notifications.rb:164:in `instrument'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.0.beta2/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/abstract_controller/base.rb:137:in `process'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionview-4.2.0.beta2/lib/action_view/rendering.rb:30:in `process'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/test_case.rb:628:in `process'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/test_case.rb:64:in `process'
# /Users/sjensen/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0.beta2/lib/action_controller/test_case.rb:516:in `patch'
# ./spec/controllers/courses_controller_spec.rb:171:in `block (3 levels) in <top (required)>'
Make sure your test db is setup correctly. Try running rake db:test:prepare

Resources