diff options
Diffstat (limited to 'test/unit/issue_test.rb')
-rw-r--r-- | test/unit/issue_test.rb | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 3454c71f5..2cf00f5ff 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -204,7 +204,7 @@ class IssueTest < ActiveSupport::TestCase def test_visible_scope_for_anonymous # Anonymous user should see issues of public projects only - issues = Issue.visible(User.anonymous).all + issues = Issue.visible(User.anonymous).to_a assert issues.any? assert_nil issues.detect {|issue| !issue.project.is_public?} assert_nil issues.detect {|issue| issue.is_private?} @@ -214,7 +214,7 @@ class IssueTest < ActiveSupport::TestCase def test_visible_scope_for_anonymous_without_view_issues_permissions # Anonymous user should not see issues without permission Role.anonymous.remove_permission!(:view_issues) - issues = Issue.visible(User.anonymous).all + issues = Issue.visible(User.anonymous).to_a assert issues.empty? assert_visibility_match User.anonymous, issues end @@ -247,7 +247,7 @@ class IssueTest < ActiveSupport::TestCase user = User.find(9) assert user.projects.empty? # Non member user should see issues of public projects only - issues = Issue.visible(user).all + issues = Issue.visible(user).to_a assert issues.any? assert_nil issues.detect {|issue| !issue.project.is_public?} assert_nil issues.detect {|issue| issue.is_private?} @@ -259,7 +259,7 @@ class IssueTest < ActiveSupport::TestCase Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') user = User.find(9) - issues = Issue.visible(user).all + issues = Issue.visible(user).to_a assert issues.any? assert_nil issues.detect {|issue| issue.author != user} assert_visibility_match user, issues @@ -270,7 +270,7 @@ class IssueTest < ActiveSupport::TestCase Role.non_member.remove_permission!(:view_issues) user = User.find(9) assert user.projects.empty? - issues = Issue.visible(user).all + issues = Issue.visible(user).to_a assert issues.empty? assert_visibility_match user, issues end @@ -291,7 +291,7 @@ class IssueTest < ActiveSupport::TestCase # User should see issues of projects for which user has view_issues permissions only Role.non_member.remove_permission!(:view_issues) Member.create!(:principal => user, :project_id => 3, :role_ids => [2]) - issues = Issue.visible(user).all + issues = Issue.visible(user).to_a assert issues.any? assert_nil issues.detect {|issue| issue.project_id != 3} assert_nil issues.detect {|issue| issue.is_private?} @@ -311,12 +311,12 @@ class IssueTest < ActiveSupport::TestCase :is_private => true) Role.find(2).update_attribute :issues_visibility, 'default' - issues = Issue.visible(User.find(8)).all + issues = Issue.visible(User.find(8)).to_a assert issues.any? assert issues.include?(issue) Role.find(2).update_attribute :issues_visibility, 'own' - issues = Issue.visible(User.find(8)).all + issues = Issue.visible(User.find(8)).to_a assert issues.any? assert issues.include?(issue) end @@ -325,7 +325,7 @@ class IssueTest < ActiveSupport::TestCase user = User.find(1) user.members.each(&:destroy) assert user.projects.empty? - issues = Issue.visible(user).all + issues = Issue.visible(user).to_a assert issues.any? # Admin should see issues on private projects that admin does not belong to assert issues.detect {|issue| !issue.project.is_public?} @@ -336,7 +336,7 @@ class IssueTest < ActiveSupport::TestCase def test_visible_scope_with_project project = Project.find(1) - issues = Issue.visible(User.find(2), :project => project).all + issues = Issue.visible(User.find(2), :project => project).to_a projects = issues.collect(&:project).uniq assert_equal 1, projects.size assert_equal project, projects.first @@ -344,7 +344,7 @@ class IssueTest < ActiveSupport::TestCase def test_visible_scope_with_project_and_subprojects project = Project.find(1) - issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all + issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).to_a projects = issues.collect(&:project).uniq assert projects.size > 1 assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} @@ -370,13 +370,20 @@ class IssueTest < ActiveSupport::TestCase assert_equal 2, parent.descendants.visible(user).collect{|i| i}.size end + def test_visible_scope_with_unsaved_user_should_not_raise_an_error + user = User.new + assert_nothing_raised do + Issue.visible(user).to_a + end + end + def test_open_scope - issues = Issue.open.all + issues = Issue.open.to_a assert_nil issues.detect(&:closed?) end def test_open_scope_with_arg - issues = Issue.open(false).all + issues = Issue.open(false).to_a assert_equal issues, issues.select(&:closed?) end @@ -1289,7 +1296,7 @@ class IssueTest < ActiveSupport::TestCase end test "#copy should not create a journal" do - copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) + copy = Issue.find(1).copy({:project_id => 3, :tracker_id => 2, :assigned_to_id => 3}, :link => false) copy.save! assert_equal 0, copy.reload.journals.size end @@ -1325,7 +1332,7 @@ class IssueTest < ActiveSupport::TestCase test "#copy should create a journal with notes" do date = Date.today notes = "Notes added when copying" - copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date) + copy = Issue.find(1).copy({:project_id => 3, :tracker_id => 2, :start_date => date}, :link => false) copy.init_journal(User.current, notes) copy.save! @@ -1619,13 +1626,15 @@ class IssueTest < ActiveSupport::TestCase issue2.reload assert_equal Date.parse('2012-10-18'), issue2.start_date - child = Issue.new(:parent_issue_id => issue2.id, :start_date => '2012-10-16', - :project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Child', :author_id => 1) - assert !child.valid? - assert_include 'Start date cannot be earlier than 10/18/2012 because of preceding issues', child.errors.full_messages - assert_equal Date.parse('2012-10-18'), child.soonest_start - child.start_date = '2012-10-18' - assert child.save + with_settings :date_format => '%m/%d/%Y' do + child = Issue.new(:parent_issue_id => issue2.id, :start_date => '2012-10-16', + :project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Child', :author_id => 1) + assert !child.valid? + assert_include 'Start date cannot be earlier than 10/18/2012 because of preceding issues', child.errors.full_messages + assert_equal Date.parse('2012-10-18'), child.soonest_start + child.start_date = '2012-10-18' + assert child.save + end end def test_setting_parent_to_a_dependent_issue_should_not_validate |