summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-07-06 06:01:50 +0000
committerGo MAEDA <maeda@farend.jp>2021-07-06 06:01:50 +0000
commit7f965286ed6b1d7e906e8662daba0d49b1cf7666 (patch)
treeaea4a14340b1e4ec29743bddf2cdef5f9b643206 /test
parent1b0bf2880374307e9669cfd4ed32cfe6677a3503 (diff)
downloadredmine-7f965286ed6b1d7e906e8662daba0d49b1cf7666.tar.gz
redmine-7f965286ed6b1d7e906e8662daba0d49b1cf7666.zip
Default issue query (#7360).
Patch by Katsuya HIDAKA (the author of https://github.com/hidakatsuya/redmine_default_custom_query), Takenori TAKAKI, Olivier Chabert, and Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@21061 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/issues_controller_test.rb72
-rw-r--r--test/unit/project_copy_test.rb13
-rw-r--r--test/unit/query_test.rb61
3 files changed, 146 insertions, 0 deletions
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index ccebb4311..87a6ec704 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -8225,4 +8225,76 @@ class IssuesControllerTest < Redmine::ControllerTest
end
end
end
+
+ def test_index_should_retrieve_default_query
+ query = IssueQuery.find(4)
+ IssueQuery.stubs(:default).returns query
+
+ [nil, 1].each do |user_id|
+ @request.session[:user_id] = user_id
+ get :index
+ assert_select 'h2', text: query.name
+
+ get :index, params: { project_id: 1 }
+ assert_select 'h2', text: query.name
+ end
+ end
+
+ def test_index_should_ignore_default_query_with_without_default
+ query = IssueQuery.find(4)
+ IssueQuery.stubs(:default).returns query
+
+ [nil, 1].each do |user_id|
+ @request.session[:user_id] = user_id
+ get :index, params: { set_filter: '1', without_default: '1' }
+ assert_select 'h2', text: I18n.t(:label_issue_plural)
+
+ get :index, params: { project_id: 1, set_filter: '1', without_default: '1' }
+ assert_select 'h2', text: I18n.t(:label_issue_plural)
+ end
+ end
+
+ def test_index_should_ignore_default_query_with_session_query
+ query = IssueQuery.find 4
+ IssueQuery.stubs(:default).returns query
+ session_query = IssueQuery.find 1
+
+ @request.session[:issue_query] = { id: 1, project_id: 1}
+ @request.session[:user_id] = 1
+ get :index, params: { project_id: '1' }
+ assert_select 'h2', text: session_query.name
+ end
+
+ def test_index_global_should_ignore_default_query_with_session_query
+ query = IssueQuery.find 4
+ IssueQuery.stubs(:default).returns query
+ session_query = IssueQuery.find 5
+
+ @request.session[:issue_query] = { id: 5, project_id: nil}
+ @request.session[:user_id] = 1
+ get :index
+ assert_select 'h2', text: session_query.name
+ end
+
+ def test_index_should_use_default_query_with_invalid_session_query
+ query = IssueQuery.find 4
+ IssueQuery.stubs(:default).returns query
+
+ @request.session[:issue_query] = { id: 1, project_id: 1}
+ @request.session[:user_id] = 1
+ get :index
+ assert_select 'h2', text: query.name
+ end
+
+ def test_index_should_not_load_default_query_for_api_request
+ query = IssueQuery.find 4
+ IssueQuery.stubs(:default).returns query
+
+ @request.session[:user_id] = 1
+ get :index, params: { format: 'json' }
+
+ assert results = JSON.parse(@response.body)['issues']
+ # query filters for tracker_id == 3
+ assert results.detect{ |i| i['tracker_id'] != 3 }
+ end
end
diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb
index aca9cbf3f..50cc1c9c9 100644
--- a/test/unit/project_copy_test.rb
+++ b/test/unit/project_copy_test.rb
@@ -283,6 +283,19 @@ class ProjectCopyTest < ActiveSupport::TestCase
assert_equal [1, 3], query.role_ids.sort
end
+ test "#copy should copy default issue query assignment" do
+ source = Project.generate!
+ query = IssueQuery.generate!(:project => source, :user => User.find(2))
+ source.update_column :default_issue_query_id, query.id
+
+ target = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
+ assert target.copy(source)
+
+ assert target.default_issue_query.present?
+ assert_equal 1, target.queries.size
+ assert_equal query.name, target.default_issue_query.name
+ end
+
test "#copy should copy versions" do
@source_project.versions << Version.generate!
@source_project.versions << Version.generate!
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 07921a951..ccf30f477 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -2750,4 +2750,65 @@ class QueryTest < ActiveSupport::TestCase
# Non-paginated issue ids and paginated issue ids should be in the same order.
assert_equal issue_ids, paginated_issue_ids
end
+
+ def test_destruction_of_default_query_should_remove_reference_from_project
+ project = Project.find('ecookbook')
+ project_query = IssueQuery.find(1)
+ project.update_column :default_issue_query_id, project_query.id
+
+ project_query.destroy
+ project.reload
+ assert_nil project.default_issue_query_id
+ end
+
+ def test_should_determine_default_issue_query
+ project = Project.find('ecookbook')
+ user = project.users.first
+
+ project_query = IssueQuery.find(1)
+ query = IssueQuery.find(4)
+ user_query = IssueQuery.find(3)
+ user_query.update_column :user_id, user.id
+
+ [nil, user, User.anonymous].each do |u|
+ [nil, project].each do |p|
+ assert_nil IssueQuery.default(project: p, user: u)
+ end
+ end
+
+ # only global default is set
+ with_settings :default_issue_query => query.id do
+ [nil, user, User.anonymous].each do |u|
+ [nil, project].each do |p|
+ assert_equal query, IssueQuery.default(project: p, user: u)
+ end
+ end
+ end
+
+ # with project default
+ assert_equal project.id, project_query.project_id
+ project.update_column :default_issue_query_id, project_query.id
+ [nil, user, User.anonymous].each do |u|
+ assert_nil IssueQuery.default(project: nil, user: u)
+ assert_equal project_query, IssueQuery.default(project: project, user: u)
+ end
+
+ # project default should override global default
+ with_settings :default_issue_query => query.id do
+ [nil, user, User.anonymous].each do |u|
+ assert_equal query, IssueQuery.default(project: nil, user: u)
+ assert_equal project_query, IssueQuery.default(project: project, user: u)
+ end
+ end
+
+ # user default, overrides project and global default
+ user.pref.default_issue_query = user_query.id
+ user.pref.save
+ with_settings :default_issue_query => query.id do
+ [nil, project].each do |p|
+ assert_equal user_query, IssueQuery.default(project: p, user: user)
+ assert_equal user_query, IssueQuery.default(project: p, user: user)
+ end
+ end
+ end
end