Permalink
Browse files

Anonymous controllers define `_routes`

* To support redirection and generation of URLs from other contexts
* Fixes #573
  • Loading branch information...
1 parent 5f9b55e commit 648ba097eced24f5bbf70dd0d97b02ad6464f19e @alindeman alindeman committed Dec 12, 2012
@@ -351,3 +351,35 @@ Feature: anonymous controller
"""
When I run `rspec spec`
Then the examples should all pass
+
+ Scenario: redirecting via a before_filter in ApplicationController
+ Given a file named "spec/controllers/application_controller_spec.rb" with:
+ """ruby
+ require "spec_helper"
+
+ class ApplicationController < ActionController::Base
+ private
+
+ def redirect_to_index
+ redirect_to(:action => :index)
+ end
+ end
+
+ describe ApplicationController do
+ controller do
+ before_filter :redirect_to_index, :only => :show
+
+ def show
+ end
+ end
+
+ context "GET #show" do
+ it "redirects to the index page" do
+ get :show, :id => 1
+ expect(response).to redirect_to(:action => :index)
+ end
+ end
+ end
+ """
+ When I run `rspec spec`
+ Then the examples should all pass
@@ -66,6 +66,9 @@ def self.name; "AnonymousController"; end
before do
@orig_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new
@routes.draw { resources :anonymous }
+
+ routes = @routes
+ described_class.send(:define_method, :_routes) { routes }
end
after do

0 comments on commit 648ba09

Please sign in to comment.