Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.dirname(__FILE__) + '/../test_helper'
require 'user_controller'

# Re-raise errors caught by the controller.
class UserController; def rescue_action(e) raise e end; end

class UserControllerTest < Test::Unit::TestCase
  def setup
    @controller = UserController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  # Replace this with your real tests.
  def test_user_apply_with_no_email
    post :apply, :user => {:login => 'winson',
                           :name => 'Winson'}
    assert_tag :tag => 'div', :attributes => {:class => 'errorExplanation'}, :content => "Email can't be blank"
  end
  
  def test_user_apply_not_meet_password_confirmation
    post :apply, :user => {:login => 'winson',
                           :name => 'Winson',
                           :email => 'winson@pbg4.org',
                           :password => '123',
                           :password_confirmation => '456'}
    assert_tag :tag => 'div', :attributes => {:class => 'errorExplanation'}, :content => "Password doesn't match confirmation"
  end
  
  def test_user_login
    assert_diff(User, :count) do
      post :apply, :user => {:login => 'winson',
                             :name => 'Winson',
                             :email => 'winson@pbg4.org',
                             :password => '123',
                             :password_confirmation => '123'}
      assert_response :redirect
      assert_redirected_to :action => 'show'
    end
    post :login, :user => {:login => 'winson', :password => '123'}
    assert_equal 'Login successfully.', flash[:notice]
  end
end