Commit 7e162ba303c9d8674c6104c8e9e1a7843b772cf7
Committed by
Leandro Santos
1 parent
20e322c5
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Added unit and functional tests of tags in tasks
Showing
2 changed files
with
71 additions
and
4 deletions
Show diff stats
test/functional/tasks_controller_test.rb
... | ... | @@ -66,6 +66,21 @@ class TasksControllerTest < ActionController::TestCase |
66 | 66 | assert_not_includes assigns(:tasks), task_spam |
67 | 67 | end |
68 | 68 | |
69 | + should 'save tasks tags' do | |
70 | + | |
71 | + requestor = fast_create(Person) | |
72 | + | |
73 | + task_one = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Task Test'}) | |
74 | + task_two = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Another Task'}) | |
75 | + | |
76 | + post :save_tags, :task_id => task_one.id, :tag_list => 'noosfero,test' | |
77 | + post :save_tags, :task_id => task_two.id, :tag_list => 'test' | |
78 | + | |
79 | + assert_includes task_one.tags_from(nil), 'test' | |
80 | + assert_not_includes task_two.tags_from(nil), 'noosfero' | |
81 | + | |
82 | + end | |
83 | + | |
69 | 84 | should 'be able to finish a task' do |
70 | 85 | t = profile.tasks.build; t.save! |
71 | 86 | |
... | ... | @@ -149,7 +164,7 @@ class TasksControllerTest < ActionController::TestCase |
149 | 164 | |
150 | 165 | should 'create a ticket with profile requestor' do |
151 | 166 | post :new, :profile => profile.identifier, :ticket => {:name => 'new task'} |
152 | - | |
167 | + | |
153 | 168 | assert_equal profile, assigns(:ticket).requestor |
154 | 169 | end |
155 | 170 | |
... | ... | @@ -381,13 +396,13 @@ class TasksControllerTest < ActionController::TestCase |
381 | 396 | t2 = CleanHouse.create!(:requestor => requestor, :target => profile) |
382 | 397 | t3 = FeedDog.create!(:requestor => requestor, :target => profile) |
383 | 398 | |
384 | - post :index, :filter_type => t1.type | |
399 | + get :index, :filter_type => t1.type | |
385 | 400 | |
386 | 401 | assert_includes assigns(:tasks), t1 |
387 | 402 | assert_includes assigns(:tasks), t2 |
388 | 403 | assert_not_includes assigns(:tasks), t3 |
389 | 404 | |
390 | - post :index | |
405 | + get :index | |
391 | 406 | |
392 | 407 | assert_includes assigns(:tasks), t1 |
393 | 408 | assert_includes assigns(:tasks), t2 |
... | ... | @@ -416,6 +431,22 @@ class TasksControllerTest < ActionController::TestCase |
416 | 431 | assert_includes assigns(:tasks), t3 |
417 | 432 | end |
418 | 433 | |
434 | + should 'filter tasks by tags' do | |
435 | + | |
436 | + requestor = fast_create(Person) | |
437 | + | |
438 | + task_one = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Task Test'}) | |
439 | + task_two = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Another Task'}) | |
440 | + | |
441 | + profile.tag(task_one, with: 'noosfero,test', on: :tags) | |
442 | + profile.tag(task_two, with: 'test', on: :tags) | |
443 | + | |
444 | + get :index, :filter_tags => 'noosfero' | |
445 | + | |
446 | + assert_includes assigns(:tasks), task_one | |
447 | + assert_not_includes assigns(:tasks), task_two | |
448 | + end | |
449 | + | |
419 | 450 | should 'return tasks ordered accordingly and limited by pages' do |
420 | 451 | time = Time.now |
421 | 452 | person = fast_create(Person) | ... | ... |
test/unit/task_test.rb
... | ... | @@ -317,7 +317,7 @@ class TaskTest < ActiveSupport::TestCase |
317 | 317 | assert_includes Task.to(another_person), t4 |
318 | 318 | end |
319 | 319 | |
320 | - should 'filter tasks by type with named_scope' do | |
320 | + should 'filter tasks by type with named scope' do | |
321 | 321 | class CleanHouse < Task; end |
322 | 322 | class FeedDog < Task; end |
323 | 323 | requestor = fast_create(Person) |
... | ... | @@ -333,6 +333,25 @@ class TaskTest < ActiveSupport::TestCase |
333 | 333 | assert_includes Task.of(nil), t3 |
334 | 334 | end |
335 | 335 | |
336 | + should 'filter tasks by tags with named scope' do | |
337 | + | |
338 | + requestor = fast_create(Person) | |
339 | + target = fast_create(Person) | |
340 | + profile = sample_user | |
341 | + | |
342 | + task_one = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Task Test'}) | |
343 | + task_two = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Another Task'}) | |
344 | + | |
345 | + profile.tag(task_one, with: 'noosfero,test', on: :tags) | |
346 | + profile.tag(task_two, with: 'test', on: :tags) | |
347 | + | |
348 | + data = Task.tagged_with('noosfero', any: true) | |
349 | + | |
350 | + assert_includes data, task_one | |
351 | + assert_not_includes data, task_two | |
352 | + | |
353 | + end | |
354 | + | |
336 | 355 | should 'order tasks by some attribute correctly' do |
337 | 356 | Task.destroy_all |
338 | 357 | t1 = fast_create(Task, :status => 4, :created_at => Time.now + 1.hour) |
... | ... | @@ -440,6 +459,23 @@ class TaskTest < ActiveSupport::TestCase |
440 | 459 | assert_equal person, task.responsible |
441 | 460 | end |
442 | 461 | |
462 | + should 'save tasks tags' do | |
463 | + | |
464 | + requestor = fast_create(Person) | |
465 | + target = fast_create(Person) | |
466 | + profile = sample_user | |
467 | + | |
468 | + task_one = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Task Test'}) | |
469 | + task_two = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Another Task'}) | |
470 | + | |
471 | + profile.tag(task_one, with: 'noosfero,test', on: :tags) | |
472 | + profile.tag(task_two, with: 'test', on: :tags) | |
473 | + | |
474 | + assert_includes task_one.tags_from(nil), 'test' | |
475 | + assert_not_includes task_two.tags_from(nil), 'noosfero' | |
476 | + | |
477 | + end | |
478 | + | |
443 | 479 | protected |
444 | 480 | |
445 | 481 | def sample_user | ... | ... |