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