diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-01-19 20:16:49 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-01-19 20:16:49 +0000 |
commit | 151a215ea45c1870842de49d0640b1557f712498 (patch) | |
tree | 36750e8c39c1235bf82d1ffb49f4bee3405e99c0 /test/unit | |
parent | df5dba5ddec5f61a2022abcd1789da4604b21055 (diff) | |
download | redmine-151a215ea45c1870842de49d0640b1557f712498.tar.gz redmine-151a215ea45c1870842de49d0640b1557f712498.zip |
Adds updated_by and last_updated_by filters on issues (#17720).
git-svn-id: http://svn.redmine.org/redmine/trunk@16228 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/query_test.rb | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 8b88b11cd..81f62516d 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -719,6 +719,93 @@ class QueryTest < ActiveSupport::TestCase end end + def test_filter_updated_by + user = User.generate! + Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes') + Journal.create!(:user_id => user.id, :journalized => Issue.find(3), :notes => 'Notes') + Journal.create!(:user_id => 2, :journalized => Issue.find(3), :notes => 'Notes') + + query = IssueQuery.new(:name => '_') + filter_name = "updated_by" + assert_include filter_name, query.available_filters.keys + + query.filters = {filter_name => {:operator => '=', :values => [user.id]}} + assert_equal [2, 3], find_issues_with_query(query).map(&:id).sort + + query.filters = {filter_name => {:operator => '!', :values => [user.id]}} + assert_equal (Issue.ids.sort - [2, 3]), find_issues_with_query(query).map(&:id).sort + end + + def test_filter_updated_by_should_ignore_private_notes_that_are_not_visible + user = User.generate! + Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes', :private_notes => true) + Journal.create!(:user_id => user.id, :journalized => Issue.find(3), :notes => 'Notes') + + query = IssueQuery.new(:name => '_') + filter_name = "updated_by" + assert_include filter_name, query.available_filters.keys + + with_current_user User.anonymous do + query.filters = {filter_name => {:operator => '=', :values => [user.id]}} + assert_equal [3], find_issues_with_query(query).map(&:id).sort + end + end + + def test_filter_updated_by_me + user = User.generate! + Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes') + + with_current_user user do + query = IssueQuery.new(:name => '_') + filter_name = "updated_by" + assert_include filter_name, query.available_filters.keys + + query.filters = {filter_name => {:operator => '=', :values => ['me']}} + assert_equal [2], find_issues_with_query(query).map(&:id).sort + end + end + + def test_filter_last_updated_by + user = User.generate! + Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes') + Journal.create!(:user_id => user.id, :journalized => Issue.find(3), :notes => 'Notes') + Journal.create!(:user_id => 2, :journalized => Issue.find(3), :notes => 'Notes') + + query = IssueQuery.new(:name => '_') + filter_name = "last_updated_by" + assert_include filter_name, query.available_filters.keys + + query.filters = {filter_name => {:operator => '=', :values => [user.id]}} + assert_equal [2], find_issues_with_query(query).map(&:id).sort + end + + def test_filter_last_updated_by_should_ignore_private_notes_that_are_not_visible + user1 = User.generate! + user2 = User.generate! + Journal.create!(:user_id => user1.id, :journalized => Issue.find(2), :notes => 'Notes') + Journal.create!(:user_id => user2.id, :journalized => Issue.find(2), :notes => 'Notes', :private_notes => true) + + query = IssueQuery.new(:name => '_') + filter_name = "last_updated_by" + assert_include filter_name, query.available_filters.keys + + with_current_user User.anonymous do + query.filters = {filter_name => {:operator => '=', :values => [user1.id]}} + assert_equal [2], find_issues_with_query(query).map(&:id).sort + + query.filters = {filter_name => {:operator => '=', :values => [user2.id]}} + assert_equal [], find_issues_with_query(query).map(&:id).sort + end + + with_current_user User.find(2) do + query.filters = {filter_name => {:operator => '=', :values => [user1.id]}} + assert_equal [], find_issues_with_query(query).map(&:id).sort + + query.filters = {filter_name => {:operator => '=', :values => [user2.id]}} + assert_equal [2], find_issues_with_query(query).map(&:id).sort + end + end + def test_user_custom_field_filtered_on_me User.current = User.find(2) cf = IssueCustomField.create!(:field_format => 'user', :is_for_all => true, :is_filter => true, :name => 'User custom field', :tracker_ids => [1]) |