Note that there are some explanatory texts on larger screens.

plurals
  1. PORSpec tests failing for Application Controller
    text
    copied!<p>I am trying to test the behavior of my ApplicationController, yet I keep running into an error. Below are my specs:</p> <pre><code>describe ApplicationController do #Base class should be inferred controller do def not_found raise ActiveRecord::RecordNotFound end end # Routing #---------------------------------------------------------------------------- def with_error_routing with_routing do |map| map.draw do get '/not_found' =&gt; "anonymous#not_found", :as =&gt; :not_found get '/home' =&gt; "anonymous#home", :as =&gt; :home end yield end end describe "handling ActiveRecord::RecordNotFound" do it "renders the 404 template", :failing =&gt; true do with_error_routing do @request.env['HTTPS'] = 'on' get :not_found, :format =&gt; 'html' response.should redirect_to(home_path) end end end end </code></pre> <p>The error message that I keep getting is this: <code>ActionController::RoutingError: No route matches {:controller=&gt;"anonymous"}</code></p> <p>Has anyone else faced this issue? I feel like my examples match other examples out there of testing the ApplicationController.</p> <p>Here’s the backtrace:</p> <pre class="lang-none prettyprint-override"><code>Failures: 1) ApplicationController handling ActiveRecord::RecordNotFound Failure/Error: get :not_found ActionController::RoutingError: No route matches {:controller=&gt;"anonymous", :action=&gt;"not_found"} # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:544:in `raise_routing_error' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:540:in `rescue in generate' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:532:in `generate' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:573:in `generate' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:598:in `url_for' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/url_for.rb:148:in `url_for' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/redirecting.rb:105:in `_compute_redirect_to_location' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/redirecting.rb:74:in `redirect_to' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/flash.rb:25:in `redirect_to' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:60:in `block in redirect_to' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:59:in `redirect_to' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/gritter-1.0.3/lib/gritter/gflash.rb:8:in `redirect_to' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/force_ssl.rb:33:in `block in force_ssl' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in `_run__1662327083837902210__process_action__2977905806469662832__callbacks' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:17:in `process_action' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/rescue.rb:29:in `process_action' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:29:in `process_action' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/params_wrapper.rb:207:in `process_action' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:18:in `process_action' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:475:in `process' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:49:in `process' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:19:in `block in process' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:72:in `catch' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:72:in `_catch_warden' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:19:in `process' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:392:in `get' # ./spec/controllers/application_controller_spec.rb:19:in `block (2 levels) in &lt;top (required)&gt;' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `instance_eval' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `block in run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-rails-2.13.2/lib/rspec/rails/example/controller_example_group.rb:160:in `call' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-rails-2.13.2/lib/rspec/rails/example/controller_example_group.rb:160:in `block (2 levels) in &lt;module:ControllerExampleGroup&gt;' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:247:in `instance_eval_with_args' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:87:in `block (2 levels) in run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in `call' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in `run_hook' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:329:in `run_around_each_hooks' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:256:in `with_around_each_hooks' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in `block in run_examples' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `map' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `run_examples' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/commands.rb:110:in `call' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:71:in `block in serve' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:66:in `fork' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:66:in `serve' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:49:in `block in run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:43:in `loop' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:43:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:37:in `start' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:95:in `block in start_child' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:82:in `fork' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:82:in `start_child' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:27:in `start' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:54:in `block in with_child' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:21:in `synchronize' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:43:in `with_child' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:62:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:47:in `serve' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:35:in `block in boot' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:35:in `loop' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:35:in `boot' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:15:in `boot' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/client/start.rb:13:in `call' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/client/command.rb:7:in `call' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/client.rb:23:in `run' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/bin/spring:4:in `&lt;top (required)&gt;' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/spring:19:in `load' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/spring:19:in `&lt;main&gt;' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `eval' # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `&lt;main&gt;' Finished in 0.54729 seconds 1 example, 1 failure </code></pre> <p>Adding ApplicationController class:</p> <pre><code>class ApplicationController &lt; ActionController::Base force_ssl check_authorization :unless =&gt; :devise_controller? respond_to :html respond_to :js respond_to :json, :xml, :except =&gt; [:edit, :update] respond_to :atom, :csv, :rss, :only =&gt; :index rescue_from ActiveRecord::RecordNotFound, :with =&gt; :respond_to_not_found rescue_from CanCan::AccessDenied, :with =&gt; :respond_to_access_denied # SECURITY - Protect Form IDs from forgery #---------------------------------------------------------------------------- protect_from_forgery # Helpers helper_method :current_user def current_user begin return current_customer unless current_customer.nil? return current_store unless current_store.nil? rescue return nil end end private def current_ability Ability.new(current_user) end #---------------------------------------------------------------------------- def respond_to_not_found FlashSetter.new.set(flash, nil, nil, {:flash_key =&gt; :alert, :message_key =&gt; :msg_not_found}) respond_to do |format| format.html { redirect_to user_home_path } end end #---------------------------------------------------------------------------- def respond_to_access_denied FlashSetter.new.set(flash, nil, nil, {:flash_key =&gt; :alert, :message_key =&gt; :msg_not_authorized}) respond_to do |format| format.html { redirect_to home_path } end end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload