Commit 36701ca802de0bf16686192016af3bceeae1d888
1 parent
e5dfdd15
Exists in
master
and in
29 other branches
rails3: fix task tests
PS: still failing due to stubbing deliver mail
Showing
1 changed file
with
21 additions
and
21 deletions
Show diff stats
test/unit/task_test.rb
... | ... | @@ -86,7 +86,7 @@ class TaskTest < ActiveSupport::TestCase |
86 | 86 | |
87 | 87 | should 'provide a description method' do |
88 | 88 | requestor = create_user('requestor').person |
89 | - assert_kind_of Hash, Task.new(:requestor => requestor).information | |
89 | + assert_kind_of Hash, build(Task, :requestor => requestor).information | |
90 | 90 | end |
91 | 91 | |
92 | 92 | should 'notify just after the task is created' do |
... | ... | @@ -98,7 +98,7 @@ class TaskTest < ActiveSupport::TestCase |
98 | 98 | end |
99 | 99 | |
100 | 100 | should 'not notify if the task is hidden' do |
101 | - task = Task.new(:status => Task::Status::HIDDEN) | |
101 | + task = build(Task, :status => Task::Status::HIDDEN) | |
102 | 102 | task.requestor = sample_user |
103 | 103 | |
104 | 104 | TaskMailer.expects(:deliver_task_created).never |
... | ... | @@ -112,7 +112,7 @@ class TaskTest < ActiveSupport::TestCase |
112 | 112 | |
113 | 113 | should 'make sure that codes are unique' do |
114 | 114 | task1 = Task.create! |
115 | - task2 = Task.new(:code => task1.code) | |
115 | + task2 = build(Task, :code => task1.code) | |
116 | 116 | |
117 | 117 | assert !task2.valid? |
118 | 118 | assert task2.errors[:code.to_s].present? |
... | ... | @@ -147,8 +147,8 @@ class TaskTest < ActiveSupport::TestCase |
147 | 147 | end |
148 | 148 | |
149 | 149 | should 'be able to limit the length of the generated code' do |
150 | - assert_equal 3, Task.create(:code_length => 3).code.size | |
151 | - assert_equal 7, Task.create(:code_length => 7).code.size | |
150 | + assert_equal 3, Task.create!(:code_length => 3).code.size | |
151 | + assert_equal 7, Task.create!(:code_length => 7).code.size | |
152 | 152 | end |
153 | 153 | |
154 | 154 | should 'throws exception when try to send target_notification_message in Task base class' do |
... | ... | @@ -160,7 +160,7 @@ class TaskTest < ActiveSupport::TestCase |
160 | 160 | |
161 | 161 | should 'send notification to target just after task creation' do |
162 | 162 | task = Task.new |
163 | - target = Profile.new | |
163 | + target = fast_create(Profile) | |
164 | 164 | target.stubs(:notification_emails).returns(['adm@example.com']) |
165 | 165 | task.target = target |
166 | 166 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
... | ... | @@ -169,7 +169,7 @@ class TaskTest < ActiveSupport::TestCase |
169 | 169 | end |
170 | 170 | |
171 | 171 | should 'not send notification to target if the task is hidden' do |
172 | - task = Task.new(:status => Task::Status::HIDDEN) | |
172 | + task = build(Task, :status => Task::Status::HIDDEN) | |
173 | 173 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
174 | 174 | TaskMailer.expects(:deliver_target_notification).never |
175 | 175 | task.save! |
... | ... | @@ -203,7 +203,7 @@ class TaskTest < ActiveSupport::TestCase |
203 | 203 | should 'be destroyed when requestor destroyed' do |
204 | 204 | user = create_user('test_user').person |
205 | 205 | assert_no_difference Task, :count do |
206 | - Task.create(:requestor => user) | |
206 | + create(Task, :requestor => user) | |
207 | 207 | user.destroy |
208 | 208 | end |
209 | 209 | end |
... | ... | @@ -248,7 +248,7 @@ class TaskTest < ActiveSupport::TestCase |
248 | 248 | |
249 | 249 | should 'the task environment method return the target environment' do |
250 | 250 | task = Task.new |
251 | - target = Profile.new(:environment => Environment.new) | |
251 | + target = build(Profile, :environment => Environment.new) | |
252 | 252 | task.target = target |
253 | 253 | assert_equal task.environment, target.environment |
254 | 254 | end |
... | ... | @@ -264,13 +264,13 @@ class TaskTest < ActiveSupport::TestCase |
264 | 264 | end |
265 | 265 | |
266 | 266 | should 'activate task' do |
267 | - task = Task.new(:status => Task::Status::HIDDEN) | |
267 | + task = build(Task, :status => Task::Status::HIDDEN) | |
268 | 268 | task.activate |
269 | 269 | assert_equal Task::Status::ACTIVE, task.status |
270 | 270 | end |
271 | 271 | |
272 | 272 | should 'notify just after the task is activated' do |
273 | - task = Task.new(:status => Task::Status::HIDDEN) | |
273 | + task = build(Task, :status => Task::Status::HIDDEN) | |
274 | 274 | task.requestor = sample_user |
275 | 275 | |
276 | 276 | TaskMailer.expects(:deliver_task_activated).with(task) |
... | ... | @@ -278,8 +278,8 @@ class TaskTest < ActiveSupport::TestCase |
278 | 278 | end |
279 | 279 | |
280 | 280 | should 'send notification message to target just after task activation' do |
281 | - task = Task.new(:status => Task::Status::HIDDEN) | |
282 | - target = Profile.new | |
281 | + task = build(Task, :status => Task::Status::HIDDEN) | |
282 | + target = fast_create(Profile) | |
283 | 283 | target.stubs(:notification_emails).returns(['target@example.com']) |
284 | 284 | task.target = target |
285 | 285 | task.save! |
... | ... | @@ -294,10 +294,10 @@ class TaskTest < ActiveSupport::TestCase |
294 | 294 | another_person = fast_create(Person) |
295 | 295 | environment = Environment.default |
296 | 296 | environment.add_admin(person) |
297 | - t1 = Task.create(:requestor => requestor, :target => person) | |
298 | - t2 = Task.create(:requestor => requestor, :target => person) | |
299 | - t3 = Task.create(:requestor => requestor, :target => environment) | |
300 | - t4 = Task.create(:requestor => requestor, :target => another_person) | |
297 | + t1 = create(Task, :requestor => requestor, :target => person) | |
298 | + t2 = create(Task, :requestor => requestor, :target => person) | |
299 | + t3 = create(Task, :requestor => requestor, :target => environment) | |
300 | + t4 = create(Task, :requestor => requestor, :target => another_person) | |
301 | 301 | |
302 | 302 | assert_includes Task.to(person), t1 |
303 | 303 | assert_includes Task.to(person), t2 |
... | ... | @@ -311,9 +311,9 @@ class TaskTest < ActiveSupport::TestCase |
311 | 311 | class FeedDog < Task; end |
312 | 312 | requestor = fast_create(Person) |
313 | 313 | target = fast_create(Person) |
314 | - t1 = CleanHouse.create(:requestor => requestor, :target => target) | |
315 | - t2 = CleanHouse.create(:requestor => requestor, :target => target) | |
316 | - t3 = FeedDog.create(:requestor => requestor, :target => target) | |
314 | + t1 = create(CleanHouse, :requestor => requestor, :target => target) | |
315 | + t2 = create(CleanHouse, :requestor => requestor, :target => target) | |
316 | + t3 = create(FeedDog, :requestor => requestor, :target => target) | |
317 | 317 | type = t1.type |
318 | 318 | |
319 | 319 | assert_includes Task.of(type), t1 |
... | ... | @@ -375,7 +375,7 @@ class TaskTest < ActiveSupport::TestCase |
375 | 375 | protected |
376 | 376 | |
377 | 377 | def sample_user |
378 | - user = User.new(:login => 'testfindinactivetask', :password => 'test', :password_confirmation => 'test', :email => 'testfindinactivetask@localhost.localdomain') | |
378 | + user = build(User, :login => 'testfindinactivetask', :password => 'test', :password_confirmation => 'test', :email => 'testfindinactivetask@localhost.localdomain') | |
379 | 379 | user.build_person(person_data) |
380 | 380 | user.save |
381 | 381 | user.person | ... | ... |