##// END OF EJS Templates
code layout clean up of 'should "allow changing the issue's attributes"' at test/functional/issue_moves_controller_test.rb...
Toshi MARUYAMA -
r7411:c01d94203b3c
parent child
Show More
@@ -1,167 +1,171
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2
2
3 class IssueMovesControllerTest < ActionController::TestCase
3 class IssueMovesControllerTest < ActionController::TestCase
4 fixtures :projects, :trackers, :issue_statuses, :issues,
4 fixtures :projects, :trackers, :issue_statuses, :issues,
5 :enumerations, :users, :issue_categories,
5 :enumerations, :users, :issue_categories,
6 :projects_trackers,
6 :projects_trackers,
7 :roles,
7 :roles,
8 :member_roles,
8 :member_roles,
9 :members,
9 :members,
10 :enabled_modules,
10 :enabled_modules,
11 :workflows,
11 :workflows,
12 :journals, :journal_details
12 :journals, :journal_details
13
13
14 def setup
14 def setup
15 User.current = nil
15 User.current = nil
16 end
16 end
17
17
18 def test_get_issue_moves_new
18 def test_get_issue_moves_new
19 @request.session[:user_id] = 2
19 @request.session[:user_id] = 2
20 get :new, :id => 1
20 get :new, :id => 1
21
21
22 assert_tag :tag => 'option', :content => 'eCookbook',
22 assert_tag :tag => 'option', :content => 'eCookbook',
23 :attributes => { :value => '1', :selected => 'selected' }
23 :attributes => { :value => '1', :selected => 'selected' }
24 %w(new_tracker_id status_id priority_id assigned_to_id).each do |field|
24 %w(new_tracker_id status_id priority_id assigned_to_id).each do |field|
25 assert_tag :tag => 'option', :content => '(No change)', :attributes => { :value => '' },
25 assert_tag :tag => 'option', :content => '(No change)', :attributes => { :value => '' },
26 :parent => {:tag => 'select', :attributes => {:id => field}}
26 :parent => {:tag => 'select', :attributes => {:id => field}}
27 assert_no_tag :tag => 'option', :attributes => {:selected => 'selected'},
27 assert_no_tag :tag => 'option', :attributes => {:selected => 'selected'},
28 :parent => {:tag => 'select', :attributes => {:id => field}}
28 :parent => {:tag => 'select', :attributes => {:id => field}}
29 end
29 end
30
30
31 # Be sure we don't include inactive enumerations
31 # Be sure we don't include inactive enumerations
32 assert ! IssuePriority.find(15).active?
32 assert ! IssuePriority.find(15).active?
33 assert_no_tag :option, :attributes => {:value => '15'},
33 assert_no_tag :option, :attributes => {:value => '15'},
34 :parent => {:tag => 'select', :attributes => {:id => 'priority_id'} }
34 :parent => {:tag => 'select', :attributes => {:id => 'priority_id'} }
35 end
35 end
36
36
37 def test_create_one_issue_to_another_project
37 def test_create_one_issue_to_another_project
38 @request.session[:user_id] = 2
38 @request.session[:user_id] = 2
39 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
39 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
40 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
40 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
41 assert_equal 2, Issue.find(1).project_id
41 assert_equal 2, Issue.find(1).project_id
42 end
42 end
43
43
44 def test_create_one_issue_to_another_project_should_follow_when_needed
44 def test_create_one_issue_to_another_project_should_follow_when_needed
45 @request.session[:user_id] = 2
45 @request.session[:user_id] = 2
46 post :create, :id => 1, :new_project_id => 2, :follow => '1'
46 post :create, :id => 1, :new_project_id => 2, :follow => '1'
47 assert_redirected_to '/issues/1'
47 assert_redirected_to '/issues/1'
48 end
48 end
49
49
50 def test_bulk_create_to_another_project
50 def test_bulk_create_to_another_project
51 @request.session[:user_id] = 2
51 @request.session[:user_id] = 2
52 post :create, :ids => [1, 2], :new_project_id => 2
52 post :create, :ids => [1, 2], :new_project_id => 2
53 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
53 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
54 # Issues moved to project 2
54 # Issues moved to project 2
55 assert_equal 2, Issue.find(1).project_id
55 assert_equal 2, Issue.find(1).project_id
56 assert_equal 2, Issue.find(2).project_id
56 assert_equal 2, Issue.find(2).project_id
57 # No tracker change
57 # No tracker change
58 assert_equal 1, Issue.find(1).tracker_id
58 assert_equal 1, Issue.find(1).tracker_id
59 assert_equal 2, Issue.find(2).tracker_id
59 assert_equal 2, Issue.find(2).tracker_id
60 end
60 end
61
61
62 def test_bulk_create_to_another_tracker
62 def test_bulk_create_to_another_tracker
63 @request.session[:user_id] = 2
63 @request.session[:user_id] = 2
64 post :create, :ids => [1, 2], :new_tracker_id => 2
64 post :create, :ids => [1, 2], :new_tracker_id => 2
65 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
65 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
66 assert_equal 2, Issue.find(1).tracker_id
66 assert_equal 2, Issue.find(1).tracker_id
67 assert_equal 2, Issue.find(2).tracker_id
67 assert_equal 2, Issue.find(2).tracker_id
68 end
68 end
69
69
70 context "#create via bulk move" do
70 context "#create via bulk move" do
71 setup do
71 setup do
72 @request.session[:user_id] = 2
72 @request.session[:user_id] = 2
73 end
73 end
74
74
75 should "allow changing the issue priority" do
75 should "allow changing the issue priority" do
76 post :create, :ids => [1, 2], :priority_id => 6
76 post :create, :ids => [1, 2], :priority_id => 6
77
77
78 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
78 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
79 assert_equal 6, Issue.find(1).priority_id
79 assert_equal 6, Issue.find(1).priority_id
80 assert_equal 6, Issue.find(2).priority_id
80 assert_equal 6, Issue.find(2).priority_id
81
81
82 end
82 end
83
83
84 should "allow adding a note when moving" do
84 should "allow adding a note when moving" do
85 post :create, :ids => [1, 2], :notes => 'Moving two issues'
85 post :create, :ids => [1, 2], :notes => 'Moving two issues'
86
86
87 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
87 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
88 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
88 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
89 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
89 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
90
90
91 end
91 end
92
92
93 end
93 end
94
94
95 def test_bulk_copy_to_another_project
95 def test_bulk_copy_to_another_project
96 @request.session[:user_id] = 2
96 @request.session[:user_id] = 2
97 assert_difference 'Issue.count', 2 do
97 assert_difference 'Issue.count', 2 do
98 assert_no_difference 'Project.find(1).issues.count' do
98 assert_no_difference 'Project.find(1).issues.count' do
99 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
99 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
100 end
100 end
101 end
101 end
102 assert_redirected_to '/projects/ecookbook/issues'
102 assert_redirected_to '/projects/ecookbook/issues'
103 end
103 end
104
104
105 context "#create via bulk copy" do
105 context "#create via bulk copy" do
106 should "allow not changing the issue's attributes" do
106 should "allow not changing the issue's attributes" do
107 @request.session[:user_id] = 2
107 @request.session[:user_id] = 2
108 issue_before_move = Issue.find(1)
108 issue_before_move = Issue.find(1)
109 assert_difference 'Issue.count', 1 do
109 assert_difference 'Issue.count', 1 do
110 assert_no_difference 'Project.find(1).issues.count' do
110 assert_no_difference 'Project.find(1).issues.count' do
111 post :create, :ids => [1], :new_project_id => 2,
111 post :create, :ids => [1], :new_project_id => 2,
112 :copy_options => {:copy => '1'}, :new_tracker_id => '',
112 :copy_options => {:copy => '1'}, :new_tracker_id => '',
113 :assigned_to_id => '', :status_id => '',
113 :assigned_to_id => '', :status_id => '',
114 :start_date => '', :due_date => ''
114 :start_date => '', :due_date => ''
115 end
115 end
116 end
116 end
117 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
117 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
118 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
118 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
119 assert_equal issue_before_move.status_id, issue_after_move.status_id
119 assert_equal issue_before_move.status_id, issue_after_move.status_id
120 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
120 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
121 end
121 end
122
122
123 should "allow changing the issue's attributes" do
123 should "allow changing the issue's attributes" do
124 # Fixes random test failure with Mysql
124 # Fixes random test failure with Mysql
125 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
125 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
126 # doesn't return the expected results
126 Issue.delete_all("project_id=2")
127 Issue.delete_all("project_id=2")
127
128
128 @request.session[:user_id] = 2
129 @request.session[:user_id] = 2
129 assert_difference 'Issue.count', 2 do
130 assert_difference 'Issue.count', 2 do
130 assert_no_difference 'Project.find(1).issues.count' do
131 assert_no_difference 'Project.find(1).issues.count' do
131 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
132 post :create, :ids => [1, 2], :new_project_id => 2,
133 :copy_options => {:copy => '1'}, :new_tracker_id => '',
134 :assigned_to_id => 4, :status_id => 3,
135 :start_date => '2009-12-01', :due_date => '2009-12-31'
132 end
136 end
133 end
137 end
134
138
135 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
139 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
136 assert_equal 2, copied_issues.size
140 assert_equal 2, copied_issues.size
137 copied_issues.each do |issue|
141 copied_issues.each do |issue|
138 assert_equal 2, issue.project_id, "Project is incorrect"
142 assert_equal 2, issue.project_id, "Project is incorrect"
139 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
143 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
140 assert_equal 3, issue.status_id, "Status is incorrect"
144 assert_equal 3, issue.status_id, "Status is incorrect"
141 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
145 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
142 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
146 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
143 end
147 end
144 end
148 end
145
149
146 should "allow adding a note when copying" do
150 should "allow adding a note when copying" do
147 @request.session[:user_id] = 2
151 @request.session[:user_id] = 2
148 assert_difference 'Issue.count', 1 do
152 assert_difference 'Issue.count', 1 do
149 post :create, :ids => [1], :copy_options => {:copy => '1'}, :notes => 'Copying one issue', :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
153 post :create, :ids => [1], :copy_options => {:copy => '1'}, :notes => 'Copying one issue', :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
150 end
154 end
151
155
152 issue = Issue.first(:order => 'id DESC')
156 issue = Issue.first(:order => 'id DESC')
153 assert_equal 1, issue.journals.size
157 assert_equal 1, issue.journals.size
154 journal = issue.journals.first
158 journal = issue.journals.first
155 assert_equal 0, journal.details.size
159 assert_equal 0, journal.details.size
156 assert_equal 'Copying one issue', journal.notes
160 assert_equal 'Copying one issue', journal.notes
157 end
161 end
158 end
162 end
159
163
160 def test_copy_to_another_project_should_follow_when_needed
164 def test_copy_to_another_project_should_follow_when_needed
161 @request.session[:user_id] = 2
165 @request.session[:user_id] = 2
162 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
166 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
163 issue = Issue.first(:order => 'id DESC')
167 issue = Issue.first(:order => 'id DESC')
164 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
168 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
165 end
169 end
166
170
167 end
171 end
General Comments 0
You need to be logged in to leave comments. Login now