Created
August 22, 2010 04:22
-
-
Save zilkey/543300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdminController < ApplicationController | |
before_filter do |controller| | |
controller.redirect_to login_path unless logged_in? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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