| Module | ActiveResourceIntegrationDsl |
| In: |
lib/active_resource_integration_dsl.rb
|
ARID provides a simple & DRY method of writing intergration tests for RESTful controllers and views that follow standard conventions.
Complete API Documentation @
Initiates a new session as a guest user (i.e. not logged in).
def test_prepare_for_login
new_session do |guest|
guest.shows(new_session_path)
end
end
# File lib/active_resource_integration_dsl.rb, line 68
68: def new_session
69: open_session do |sess|
70: sess.extend(SessionMethods)
71: yield sess if block_given?
72: end
73: end
Logs in a user to the application via a SessionsController. Assumes that you have a RESTful SessionsController with routes setup accordingly and that this is how users are expected to login to your application. Pass a block to perform additional tests as the newly logged in user.
{:user => {:username => 'user_login_name', :password => 'users_password'}}
The following will test a user loging in to the application and then performing a GET on the UsersController index action.
def test_read_users_index
new_session_as('admin','password') do |admin|
admin.lists_users
end
end
# File lib/active_resource_integration_dsl.rb, line 45
45: def new_session_as(user,pass)
46: new_session do |guest|
47: guest.creates_session(
48: :params => {
49: :user => {
50: :username => user,
51: :password => pass
52: }
53: }
54: )
55: yield guest if block_given?
56: guest.destroys_session('this')
57: end
58: end