Sha256: 19e2c87d71188624f5d04bd49d5f6641a160bafa32ee460e7398b84a082ed6a1

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

require "#{File.dirname(__FILE__)}/../test_helper" 
class AuthenticationTest < ActionController::IntegrationTest 
  fixtures :users
  
  def test_successful_login 
    admin = enter_site(:admin) 
    admin.tries_to_go_to_admin 
    admin.logs_in_successfully("admin", "test")
  end 
  
  def test_failing_login
    harry = enter_site(:harry)
    harry.tries_to_go_to_admin
    harry.attempts_login_and_fails("scott", "tiger")
  end
  
  private 
  
  module BrowsingTestDSL 
    include ERB::Util 
    attr_writer :name 
    def tries_to_go_to_admin 
      get "admin/products/new" 
      assert_response :redirect, "Did not redirect after /admin/products/new"
      assert_redirected_to "login", "Did not redirect to the login page"
    end 
    
    def logs_in_successfully(login, password)
      post_login(login, password)
      assert_response :redirect, "Did not redirect after logging in correctly"
      assert_redirected_to "admin/products/new"
    end
    
    def attempts_login_and_fails(login, password)
      post_login(login, password)
      assert_response :success
      assert_template "account/login"
    end
    
    private
    def post_login(login, password)
      post login_path, "login" => login, "password" => password
    end
  end 
  
  def enter_site(name) 
    open_session do |session| 
      session.extend(BrowsingTestDSL) 
      session.name = name 
      yield session if block_given? 
    end 
  end 
end 

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
railscart-0.0.1 starter-app/vendor/plugins/railscart/test/integration/authentication_test.rb
railscart-0.0.2 starter_app/vendor/plugins/railscart/test/integration/authentication_test.rb
railscart-0.0.3 starter_app/vendor/plugins/railscart/test/integration/authentication_test.rb
railscart-0.0.4 starter_app/vendor/plugins/railscart/test/integration/authentication_test.rb
spree-0.0.6 starter-app/vendor/plugins/spree/test/integration/authentication_test.rb
spree-0.0.5 starter-app/vendor/plugins/spree/test/integration/authentication_test.rb
spree-0.0.7 starter-app/vendor/plugins/spree/test/integration/authentication_test.rb
spree-0.0.8 starter-app/vendor/plugins/spree/test/integration/authentication_test.rb