diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/project_copy_test.rb | 13 | ||||
-rw-r--r-- | test/unit/query_test.rb | 61 |
2 files changed, 74 insertions, 0 deletions
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 |