Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View abstract_controller_spec.rb
1 2 3 4 5
class AdminController < ApplicationController
before_filter do |controller|
controller.redirect_to login_path unless logged_in?
end
end
View abstract_controller_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
require 'spec_helper'
 
class InheritsFromAdminController < AdminController
def show
render :text => "foo"
end
end
 
describe InheritsFromAdminController do
 
before do
Rails.application.routes.draw do
 
# add the route that you need in order to test
match '/foo' => "inherits_from_admin#show"
 
# re-drawing routes means that you lose any routes you defined in routes.rb
# so you have to add those back here if your controller references them
match '/login' => "sessions/new", :as => login
 
end
end
 
after do
 
# be sure to reload routes after the tests run, otherwise all your
# other controller specs will fail
Rails.application.reload_routes!
 
end
 
it "requires logged-in users" do
get :show
response.should redirect_to("/login")
end
end
View abstract_controller_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
require 'spec_helper'
 
class InheritsFromAdminController < AdminController
def show
render :text => "foo"
end
end
 
describe InheritsFromAdminController do
 
def with_admin_routing
with_routing do |map|
map.draw do
match '/some_route' => "inherits_from_admin#show"
resources :users do
get :dashboard, :on => :member
end
end
yield
end
end
 
it "requires logged-in users" do
with_admin_routing do
get :show
response.should redirect_to("/login")
end
end
 
it "does other stuff..." do
with_admin_routing do
get :show
# assert other stuff...
end
end
 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.