Should Require Login plugin
Plugin details
Documentation
ruby script/plugin install git://github.com/nbibler/should_require_login.git
What's it do?
===============
This plugin adds a method to your functional tests which is creatively named should_require_login. This assertion will verify that the given list of views (with optional request parameters) requires that a user be authenticated prior to successful access.
How's it do that?
===============
To verify that authentication is required, the assertion will check that accessing each given view, when no user is signed in, will result in a redirection to your sign in page (oh, by the way, you are required to have a named route called login_url).
The encapsulation of the assertion logic is written for Shoulda[http://www.thoughtbot.com/projects/shoulda], and so using Shoulda is required. (opinionated, remember?)
While I'm mentioning these nuances, I should also mention that you're required to also have the following methods available:
login_as(user/nil):To set the user with whom the test should login. This method should also accept nil to log in as nobody.
Example
===========
Since this plugin will really only work with Shoulda (you read that already, right?), here you go:
class FoosControllerTest < ActionController::TestCase
context 'FooController' do
should_require_login :new, :edit
should_require_login :create, :method => :post, :params => {:name => 'bar'}
should_require_login :update, :method => :put, :params => { :id => 1 }, :with_user => lambda { users(:foo) }
should_require_login :destroy, :method => :delete
end
end
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | (0 older versions) | Last edited by: hardway, 2 months ago

