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.

  • Checks that controllers respond as expected to different methods.
  • On create and update tests, confirms that forms in new and edit views contain the correct action, method, and inputs to submit the data that the test wants to submit.
  • Performs AJAX requests instead of standard requests simply by passing the :via_ajax => true option with your test.
  • Accepts blocks with tests to perform additional application specific tests.

Complete API Documentation @

Methods

Classes and Modules

Module ActiveResourceIntegrationDsl::SessionMethods

Public Instance methods

Initiates a new session as a guest user (i.e. not logged in).

Sample

 def test_prepare_for_login
   new_session do |guest|
     guest.shows(new_session_path)
   end
 end

[Source]

    # 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.

Requirements

  • Routes must setup new_session_path and sessions_path helper.
  • new action must provide a login form with a POST method to sessions_path and text fields named user[username] and user[password].
  • create action in controller must accept credentials in the params hash in the following format.
     {:user => {:username => 'user_login_name', :password => 'users_password'}}
    
  • create method must respod with a 304 (Redirect) on a successfull login. It doesn‘t matter where the redirect is to.

Usage Example

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

[Source]

    # 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

[Validate]