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