You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time_entry_query_test.rb 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class TimeEntryQueryTest < ActiveSupport::TestCase
  19. fixtures :issues, :projects, :users,
  20. :members, :roles, :member_roles,
  21. :trackers, :issue_statuses,
  22. :projects_trackers,
  23. :journals, :journal_details,
  24. :issue_categories, :enumerations,
  25. :groups_users,
  26. :enabled_modules
  27. def test_cross_project_activity_filter_should_propose_non_active_activities
  28. activity = TimeEntryActivity.create!(:name => 'Disabled', :active => false)
  29. assert !activity.active?
  30. query = TimeEntryQuery.new(:name => '_')
  31. assert options = query.available_filters['activity_id']
  32. assert values = options[:values]
  33. assert_include ["Disabled", activity.id.to_s], values
  34. end
  35. def test_activity_filter_should_consider_system_and_project_activities
  36. TimeEntry.delete_all
  37. system = TimeEntryActivity.create!(:name => 'Foo')
  38. TimeEntry.generate!(:activity => system, :hours => 1.0)
  39. override = TimeEntryActivity.create!(:name => 'Foo', :parent_id => system.id, :project_id => 1)
  40. other = TimeEntryActivity.create!(:name => 'Bar')
  41. TimeEntry.generate!(:activity => override, :hours => 2.0)
  42. TimeEntry.generate!(:activity => other, :hours => 4.0)
  43. query = TimeEntryQuery.new(:name => '_')
  44. query.add_filter('activity_id', '=', [system.id.to_s])
  45. assert_equal 3.0, query.results_scope.sum(:hours)
  46. query = TimeEntryQuery.new(:name => '_')
  47. query.add_filter('activity_id', '!', [system.id.to_s])
  48. assert_equal 4.0, query.results_scope.sum(:hours)
  49. end
  50. end