##// END OF EJS Templates
Refactor: Merged IssueStatusesController#list and #index....
Eric Davis -
r3301:c18f8d34fb3d
parent child
Show More
@@ -1,80 +1,75
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssueStatusesController < ApplicationController
19 19 layout 'admin'
20 20
21 21 before_filter :require_admin
22 22
23 23 verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ],
24 :redirect_to => { :action => :list }
24 :redirect_to => { :action => :index }
25 25
26 26 def index
27 list
28 render :action => 'list' unless request.xhr?
29 end
30
31 def list
32 27 @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
33 render :action => "list", :layout => false if request.xhr?
28 render :action => "index", :layout => false if request.xhr?
34 29 end
35 30
36 31 def new
37 32 @issue_status = IssueStatus.new
38 33 end
39 34
40 35 def create
41 36 @issue_status = IssueStatus.new(params[:issue_status])
42 37 if @issue_status.save
43 38 flash[:notice] = l(:notice_successful_create)
44 redirect_to :action => 'list'
39 redirect_to :action => 'index'
45 40 else
46 41 render :action => 'new'
47 42 end
48 43 end
49 44
50 45 def edit
51 46 @issue_status = IssueStatus.find(params[:id])
52 47 end
53 48
54 49 def update
55 50 @issue_status = IssueStatus.find(params[:id])
56 51 if @issue_status.update_attributes(params[:issue_status])
57 52 flash[:notice] = l(:notice_successful_update)
58 redirect_to :action => 'list'
53 redirect_to :action => 'index'
59 54 else
60 55 render :action => 'edit'
61 56 end
62 57 end
63 58
64 59 def destroy
65 60 IssueStatus.find(params[:id]).destroy
66 redirect_to :action => 'list'
61 redirect_to :action => 'index'
67 62 rescue
68 63 flash[:error] = "Unable to delete issue status"
69 redirect_to :action => 'list'
64 redirect_to :action => 'index'
70 65 end
71 66
72 67 def update_issue_done_ratio
73 68 if IssueStatus.update_issue_done_ratios
74 69 flash[:notice] = l(:notice_issue_done_ratios_updated)
75 70 else
76 71 flash[:error] = l(:error_issue_done_ratios_not_updated)
77 72 end
78 redirect_to :action => 'list'
73 redirect_to :action => 'index'
79 74 end
80 75 end
1 NO CONTENT: file renamed from app/views/issue_statuses/list.rhtml to app/views/issue_statuses/index.html.erb
@@ -1,96 +1,95
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2 require 'issue_statuses_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class IssueStatusesController; def rescue_action(e) raise e end; end
6 6
7 7
8 8 class IssueStatusesControllerTest < ActionController::TestCase
9 9 fixtures :issue_statuses, :issues
10 10
11 11 def setup
12 12 @controller = IssueStatusesController.new
13 13 @request = ActionController::TestRequest.new
14 14 @response = ActionController::TestResponse.new
15 15 User.current = nil
16 16 @request.session[:user_id] = 1 # admin
17 17 end
18 18
19 19 def test_index
20 # TODO: unify with #list
21 20 get :index
22 21 assert_response :success
23 assert_template 'list'
22 assert_template 'index'
24 23 end
25 24
26 25 def test_new
27 26 get :new
28 27 assert_response :success
29 28 assert_template 'new'
30 29 end
31 30
32 31 def test_create
33 32 assert_difference 'IssueStatus.count' do
34 33 post :create, :issue_status => {:name => 'New status'}
35 34 end
36 assert_redirected_to 'issue_statuses/list'
35 assert_redirected_to :action => 'index'
37 36 status = IssueStatus.find(:first, :order => 'id DESC')
38 37 assert_equal 'New status', status.name
39 38 end
40 39
41 40 def test_edit
42 41 get :edit, :id => '3'
43 42 assert_response :success
44 43 assert_template 'edit'
45 44 end
46 45
47 46 def test_update
48 47 post :update, :id => '3', :issue_status => {:name => 'Renamed status'}
49 assert_redirected_to 'issue_statuses/list'
48 assert_redirected_to :action => 'index'
50 49 status = IssueStatus.find(3)
51 50 assert_equal 'Renamed status', status.name
52 51 end
53 52
54 53 def test_destroy
55 54 Issue.delete_all("status_id = 1")
56 55
57 56 assert_difference 'IssueStatus.count', -1 do
58 57 post :destroy, :id => '1'
59 58 end
60 assert_redirected_to 'issue_statuses/list'
59 assert_redirected_to :action => 'index'
61 60 assert_nil IssueStatus.find_by_id(1)
62 61 end
63 62
64 63 def test_destroy_should_block_if_status_in_use
65 64 assert_not_nil Issue.find_by_status_id(1)
66 65
67 66 assert_no_difference 'IssueStatus.count' do
68 67 post :destroy, :id => '1'
69 68 end
70 assert_redirected_to 'issue_statuses/list'
69 assert_redirected_to :action => 'index'
71 70 assert_not_nil IssueStatus.find_by_id(1)
72 71 end
73 72
74 73 context "on POST to :update_issue_done_ratio" do
75 74 context "with Setting.issue_done_ratio using the issue_field" do
76 75 setup do
77 76 Setting.issue_done_ratio = 'issue_field'
78 77 post :update_issue_done_ratio
79 78 end
80 79
81 80 should_set_the_flash_to /not updated/
82 should_redirect_to('the list') { '/issue_statuses/list' }
81 should_redirect_to('the index') { '/issue_statuses' }
83 82 end
84 83
85 84 context "with Setting.issue_done_ratio using the issue_status" do
86 85 setup do
87 86 Setting.issue_done_ratio = 'issue_status'
88 87 post :update_issue_done_ratio
89 88 end
90 89
91 90 should_set_the_flash_to /Issue done ratios updated/
92 should_redirect_to('the list') { '/issue_statuses/list' }
91 should_redirect_to('the index') { '/issue_statuses' }
93 92 end
94 93 end
95 94
96 95 end
General Comments 0
You need to be logged in to leave comments. Login now