Create a gist now

Instantly share code, notes, and snippets.

class AdminController < ApplicationController
before_filter do |controller|
controller.redirect_to login_path unless logged_in?
end
end
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
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