Created
October 18, 2010 10:06
-
-
Save flippingbits/631997 to your computer and use it in GitHub Desktop.
RSpec Macro for testing, if a controller is only available for signed in users
This file contains 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
module RSpec::Core | |
class ExampleGroup | |
class << self | |
# | |
# This macro is available inside of each controller spec: | |
# | |
# describe UsersController do | |
# describe "/users" do | |
# it_should_be_protected :index | |
# end | |
# end | |
# | |
def it_should_be_protected(action) | |
describe "Authentication" do | |
before(:each) do | |
@user = Factory.build(:user, :email => "testerno1@constellationapp.org") | |
@user.save | |
end | |
context "given a signed in user" do | |
it "should be accessible" do | |
sign_in :user, @user | |
get action | |
response.should be_success | |
end | |
end | |
context "given a signed out user" do | |
it "should not be accessible" do | |
sign_out @user | |
get action | |
response.should_not be_success | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment