annotate .svn/pristine/73/733ef5f2e7612d0ddf7c032e9fce87a523e4ff33.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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