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 / 69 / 6975387439910072689171fac66ca5755876b0a7.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.8 KB)

1
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
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_edit
53
    get :edit, :id => '3'
54
    assert_response :success
55
    assert_template 'edit'
56
  end
57

    
58
  def test_update
59
    put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
60
    assert_redirected_to :action => 'index'
61
    status = IssueStatus.find(3)
62
    assert_equal 'Renamed status', status.name
63
  end
64

    
65
  def test_destroy
66
    Issue.delete_all("status_id = 1")
67

    
68
    assert_difference 'IssueStatus.count', -1 do
69
      delete :destroy, :id => '1'
70
    end
71
    assert_redirected_to :action => 'index'
72
    assert_nil IssueStatus.find_by_id(1)
73
  end
74

    
75
  def test_destroy_should_block_if_status_in_use
76
    assert_not_nil Issue.find_by_status_id(1)
77

    
78
    assert_no_difference 'IssueStatus.count' do
79
      delete :destroy, :id => '1'
80
    end
81
    assert_redirected_to :action => 'index'
82
    assert_not_nil IssueStatus.find_by_id(1)
83
  end
84

    
85
  context "on POST to :update_issue_done_ratio" do
86
    context "with Setting.issue_done_ratio using the issue_field" do
87
      setup do
88
        Setting.issue_done_ratio = 'issue_field'
89
        post :update_issue_done_ratio
90
      end
91

    
92
      should_set_the_flash_to /not updated/
93
      should_redirect_to('the index') { '/issue_statuses' }
94
    end
95

    
96
    context "with Setting.issue_done_ratio using the issue_status" do
97
      setup do
98
        Setting.issue_done_ratio = 'issue_status'
99
        post :update_issue_done_ratio
100
      end
101

    
102
      should_set_the_flash_to /Issue done ratios updated/
103
      should_redirect_to('the index') { '/issue_statuses' }
104
    end
105
  end
106

    
107
end