diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index ed943d2..2278fc8 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -66,6 +66,21 @@ class TasksControllerTest < ActionController::TestCase assert_not_includes assigns(:tasks), task_spam end + should 'save tasks tags' do + + requestor = fast_create(Person) + + task_one = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Task Test'}) + task_two = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Another Task'}) + + post :save_tags, :task_id => task_one.id, :tag_list => 'noosfero,test' + post :save_tags, :task_id => task_two.id, :tag_list => 'test' + + assert_includes task_one.tags_from(nil), 'test' + assert_not_includes task_two.tags_from(nil), 'noosfero' + + end + should 'be able to finish a task' do t = profile.tasks.build; t.save! @@ -149,7 +164,7 @@ class TasksControllerTest < ActionController::TestCase should 'create a ticket with profile requestor' do post :new, :profile => profile.identifier, :ticket => {:name => 'new task'} - + assert_equal profile, assigns(:ticket).requestor end @@ -381,13 +396,13 @@ class TasksControllerTest < ActionController::TestCase t2 = CleanHouse.create!(:requestor => requestor, :target => profile) t3 = FeedDog.create!(:requestor => requestor, :target => profile) - post :index, :filter_type => t1.type + get :index, :filter_type => t1.type assert_includes assigns(:tasks), t1 assert_includes assigns(:tasks), t2 assert_not_includes assigns(:tasks), t3 - post :index + get :index assert_includes assigns(:tasks), t1 assert_includes assigns(:tasks), t2 @@ -416,6 +431,22 @@ class TasksControllerTest < ActionController::TestCase assert_includes assigns(:tasks), t3 end + should 'filter tasks by tags' do + + requestor = fast_create(Person) + + task_one = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Task Test'}) + task_two = Task.create!(:requestor => requestor, :target => profile, :data => {:name => 'Another Task'}) + + profile.tag(task_one, with: 'noosfero,test', on: :tags) + profile.tag(task_two, with: 'test', on: :tags) + + get :index, :filter_tags => 'noosfero' + + assert_includes assigns(:tasks), task_one + assert_not_includes assigns(:tasks), task_two + end + should 'return tasks ordered accordingly and limited by pages' do time = Time.now person = fast_create(Person) diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb index 16448ff..8253d57 100644 --- a/test/unit/task_test.rb +++ b/test/unit/task_test.rb @@ -317,7 +317,7 @@ class TaskTest < ActiveSupport::TestCase assert_includes Task.to(another_person), t4 end - should 'filter tasks by type with named_scope' do + should 'filter tasks by type with named scope' do class CleanHouse < Task; end class FeedDog < Task; end requestor = fast_create(Person) @@ -333,6 +333,25 @@ class TaskTest < ActiveSupport::TestCase assert_includes Task.of(nil), t3 end + should 'filter tasks by tags with named scope' do + + requestor = fast_create(Person) + target = fast_create(Person) + profile = sample_user + + task_one = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Task Test'}) + task_two = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Another Task'}) + + profile.tag(task_one, with: 'noosfero,test', on: :tags) + profile.tag(task_two, with: 'test', on: :tags) + + data = Task.tagged_with('noosfero', any: true) + + assert_includes data, task_one + assert_not_includes data, task_two + + end + should 'order tasks by some attribute correctly' do Task.destroy_all t1 = fast_create(Task, :status => 4, :created_at => Time.now + 1.hour) @@ -440,6 +459,23 @@ class TaskTest < ActiveSupport::TestCase assert_equal person, task.responsible end + should 'save tasks tags' do + + requestor = fast_create(Person) + target = fast_create(Person) + profile = sample_user + + task_one = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Task Test'}) + task_two = Task.create!(:requestor => requestor, :target => target, :data => {:name => 'Another Task'}) + + profile.tag(task_one, with: 'noosfero,test', on: :tags) + profile.tag(task_two, with: 'test', on: :tags) + + assert_includes task_one.tags_from(nil), 'test' + assert_not_includes task_two.tags_from(nil), 'noosfero' + + end + protected def sample_user -- libgit2 0.21.2