To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 73 / 733ef5f2e7612d0ddf7c032e9fce87a523e4ff33.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (3.13 KB)

1 1296:038ba2d95de8 Chris
require File.expand_path('../../test_helper', __FILE__)
2
require 'issue_statuses_controller'
3
4
# Re-raise errors caught by the controller.
5
class IssueStatusesController; def rescue_action(e) raise e end; end
6
7
8
class IssueStatusesControllerTest < ActionController::TestCase
9
  fixtures :issue_statuses, :issues, :users
10
11
  def setup
12
    @controller = IssueStatusesController.new
13
    @request    = ActionController::TestRequest.new
14
    @response   = ActionController::TestResponse.new
15
    User.current = nil
16
    @request.session[:user_id] = 1 # admin
17
  end
18
19
  def test_index
20
    get :index
21
    assert_response :success
22
    assert_template 'index'
23
  end
24
25
  def test_index_by_anonymous_should_redirect_to_login_form
26
    @request.session[:user_id] = nil
27
    get :index
28
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fissue_statuses'
29
  end
30
31
  def test_index_by_user_should_respond_with_406
32
    @request.session[:user_id] = 2
33
    get :index
34
    assert_response 406
35
  end
36
37
  def test_new
38
    get :new
39
    assert_response :success
40
    assert_template 'new'
41
  end
42
43
  def test_create
44
    assert_difference 'IssueStatus.count' do
45
      post :create, :issue_status => {:name => 'New status'}
46
    end
47
    assert_redirected_to :action => 'index'
48
    status = IssueStatus.find(:first, :order => 'id DESC')
49
    assert_equal 'New status', status.name
50
  end
51
52
  def test_create_with_failure
53
    post :create, :issue_status => {:name => ''}
54
    assert_response :success
55
    assert_template 'new'
56
    assert_error_tag :content => /name can&#x27;t be blank/i
57
  end
58
59
  def test_edit
60
    get :edit, :id => '3'
61
    assert_response :success
62
    assert_template 'edit'
63
  end
64
65
  def test_update
66
    put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
67
    assert_redirected_to :action => 'index'
68
    status = IssueStatus.find(3)
69
    assert_equal 'Renamed status', status.name
70
  end
71
72
  def test_update_with_failure
73
    put :update, :id => '3', :issue_status => {:name => ''}
74
    assert_response :success
75
    assert_template 'edit'
76
    assert_error_tag :content => /name can&#x27;t be blank/i
77
  end
78
79
  def test_destroy
80
    Issue.delete_all("status_id = 1")
81
82
    assert_difference 'IssueStatus.count', -1 do
83
      delete :destroy, :id => '1'
84
    end
85
    assert_redirected_to :action => 'index'
86
    assert_nil IssueStatus.find_by_id(1)
87
  end
88
89
  def test_destroy_should_block_if_status_in_use
90
    assert_not_nil Issue.find_by_status_id(1)
91
92
    assert_no_difference 'IssueStatus.count' do
93
      delete :destroy, :id => '1'
94
    end
95
    assert_redirected_to :action => 'index'
96
    assert_not_nil IssueStatus.find_by_id(1)
97
  end
98
99
  def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
100
    with_settings :issue_done_ratio => 'issue_field' do
101
      post :update_issue_done_ratio
102
      assert_match /not updated/, flash[:error].to_s
103
      assert_redirected_to '/issue_statuses'
104
    end
105
  end
106
107
  def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
108
    with_settings :issue_done_ratio => 'issue_status' do
109
      post :update_issue_done_ratio
110
      assert_match /Issue done ratios updated/, flash[:notice].to_s
111
      assert_redirected_to '/issue_statuses'
112
    end
113
  end
114
end