Skip to content

Instantly share code, notes, and snippets.

@flippingbits
Created October 18, 2010 10:06
Show Gist options
  • Save flippingbits/631997 to your computer and use it in GitHub Desktop.
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
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