Revision 441:cbce1fd3b1b7 test/unit/.svn/text-base
| test/unit/.svn/text-base/activity_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 24 | 24 |
def setup |
| 25 | 25 |
@project = Project.find(1) |
| 26 | 26 |
end |
| 27 |
|
|
| 27 |
|
|
| 28 | 28 |
def test_activity_without_subprojects |
| 29 | 29 |
events = find_events(User.anonymous, :project => @project) |
| 30 | 30 |
assert_not_nil events |
| 31 |
|
|
| 31 |
|
|
| 32 | 32 |
assert events.include?(Issue.find(1)) |
| 33 | 33 |
assert !events.include?(Issue.find(4)) |
| 34 | 34 |
# subproject issue |
| ... | ... | |
| 38 | 38 |
def test_activity_with_subprojects |
| 39 | 39 |
events = find_events(User.anonymous, :project => @project, :with_subprojects => 1) |
| 40 | 40 |
assert_not_nil events |
| 41 |
|
|
| 41 |
|
|
| 42 | 42 |
assert events.include?(Issue.find(1)) |
| 43 | 43 |
# subproject issue |
| 44 | 44 |
assert events.include?(Issue.find(5)) |
| 45 | 45 |
end |
| 46 |
|
|
| 46 |
|
|
| 47 | 47 |
def test_global_activity_anonymous |
| 48 | 48 |
events = find_events(User.anonymous) |
| 49 | 49 |
assert_not_nil events |
| 50 |
|
|
| 50 |
|
|
| 51 | 51 |
assert events.include?(Issue.find(1)) |
| 52 | 52 |
assert events.include?(Message.find(5)) |
| 53 | 53 |
# Issue of a private project |
| 54 | 54 |
assert !events.include?(Issue.find(4)) |
| 55 |
# Private issue and comment |
|
| 56 |
assert !events.include?(Issue.find(14)) |
|
| 57 |
assert !events.include?(Journal.find(5)) |
|
| 55 | 58 |
end |
| 56 |
|
|
| 59 |
|
|
| 57 | 60 |
def test_global_activity_logged_user |
| 58 | 61 |
events = find_events(User.find(2)) # manager |
| 59 | 62 |
assert_not_nil events |
| 60 |
|
|
| 63 |
|
|
| 61 | 64 |
assert events.include?(Issue.find(1)) |
| 62 | 65 |
# Issue of a private project the user belongs to |
| 63 | 66 |
assert events.include?(Issue.find(4)) |
| 64 | 67 |
end |
| 65 |
|
|
| 68 |
|
|
| 66 | 69 |
def test_user_activity |
| 67 | 70 |
user = User.find(2) |
| 68 | 71 |
events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10) |
| 69 |
|
|
| 72 |
|
|
| 70 | 73 |
assert(events.size > 0) |
| 71 | 74 |
assert(events.size <= 10) |
| 72 | 75 |
assert_nil(events.detect {|e| e.event_author != user})
|
| 73 | 76 |
end |
| 74 |
|
|
| 77 |
|
|
| 75 | 78 |
def test_files_activity |
| 76 | 79 |
f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1)) |
| 77 | 80 |
f.scope = ['files'] |
| 78 | 81 |
events = f.events |
| 79 |
|
|
| 82 |
|
|
| 80 | 83 |
assert_kind_of Array, events |
| 81 | 84 |
assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
|
| 82 | 85 |
assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
|
| 83 | 86 |
assert_equal [Attachment], events.collect(&:class).uniq |
| 84 | 87 |
assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort |
| 85 | 88 |
end |
| 86 |
|
|
| 89 |
|
|
| 87 | 90 |
private |
| 88 |
|
|
| 91 |
|
|
| 89 | 92 |
def find_events(user, options={})
|
| 90 | 93 |
Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1) |
| 91 | 94 |
end |
| test/unit/.svn/text-base/attachment_test.rb.svn-base | ||
|---|---|---|
| 1 | 1 |
# encoding: utf-8 |
| 2 | 2 |
# |
| 3 |
# redMine - project management software
|
|
| 4 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
| 3 |
# Redmine - project management software
|
|
| 4 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 5 | 5 |
# |
| 6 | 6 |
# This program is free software; you can redistribute it and/or |
| 7 | 7 |
# modify it under the terms of the GNU General Public License |
| 8 | 8 |
# as published by the Free Software Foundation; either version 2 |
| 9 | 9 |
# of the License, or (at your option) any later version. |
| 10 |
#
|
|
| 10 |
# |
|
| 11 | 11 |
# This program is distributed in the hope that it will be useful, |
| 12 | 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | 14 |
# GNU General Public License for more details. |
| 15 |
#
|
|
| 15 |
# |
|
| 16 | 16 |
# You should have received a copy of the GNU General Public License |
| 17 | 17 |
# along with this program; if not, write to the Free Software |
| 18 | 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 21 | 21 |
|
| 22 | 22 |
class AttachmentTest < ActiveSupport::TestCase |
| 23 | 23 |
fixtures :issues, :users |
| 24 |
|
|
| 24 |
|
|
| 25 | 25 |
def setup |
| 26 | 26 |
end |
| 27 | 27 |
|
| ... | ... | |
| 37 | 37 |
assert_equal '1478adae0d4eb06d35897518540e25d6', a.digest |
| 38 | 38 |
assert File.exist?(a.diskfile) |
| 39 | 39 |
end |
| 40 |
|
|
| 40 |
|
|
| 41 | 41 |
def test_create_should_auto_assign_content_type |
| 42 | 42 |
a = Attachment.new(:container => Issue.find(1), |
| 43 | 43 |
:file => uploaded_test_file("testfile.txt", ""),
|
| ... | ... | |
| 45 | 45 |
assert a.save |
| 46 | 46 |
assert_equal 'text/plain', a.content_type |
| 47 | 47 |
end |
| 48 |
|
|
| 48 |
|
|
| 49 | 49 |
def test_identical_attachments_at_the_same_time_should_not_overwrite |
| 50 | 50 |
a1 = Attachment.create!(:container => Issue.find(1), |
| 51 | 51 |
:file => uploaded_test_file("testfile.txt", ""),
|
| ... | ... | |
| 55 | 55 |
:author => User.find(1)) |
| 56 | 56 |
assert a1.disk_filename != a2.disk_filename |
| 57 | 57 |
end |
| 58 |
|
|
| 58 |
|
|
| 59 | 59 |
def test_diskfilename |
| 60 | 60 |
assert Attachment.disk_filename("test_file.txt") =~ /^\d{12}_test_file.txt$/
|
| 61 | 61 |
assert_equal 'test_file.txt', Attachment.disk_filename("test_file.txt")[13..-1]
|
| test/unit/.svn/text-base/calendar_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software |
|
| 2 |
# Copyright (C) 2006-2007 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 |
|
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class CalendarTest < ActiveSupport::TestCase |
|
| 21 |
|
|
| 22 |
def test_monthly |
|
| 23 |
c = Redmine::Helpers::Calendar.new(Date.today, :fr, :month) |
|
| 24 |
assert_equal [1, 7], [c.startdt.cwday, c.enddt.cwday] |
|
| 25 |
|
|
| 26 |
c = Redmine::Helpers::Calendar.new('2007-07-14'.to_date, :fr, :month)
|
|
| 27 |
assert_equal ['2007-06-25'.to_date, '2007-08-05'.to_date], [c.startdt, c.enddt] |
|
| 28 |
|
|
| 29 |
c = Redmine::Helpers::Calendar.new(Date.today, :en, :month) |
|
| 30 |
assert_equal [7, 6], [c.startdt.cwday, c.enddt.cwday] |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
def test_weekly |
|
| 34 |
c = Redmine::Helpers::Calendar.new(Date.today, :fr, :week) |
|
| 35 |
assert_equal [1, 7], [c.startdt.cwday, c.enddt.cwday] |
|
| 36 |
|
|
| 37 |
c = Redmine::Helpers::Calendar.new('2007-07-14'.to_date, :fr, :week)
|
|
| 38 |
assert_equal ['2007-07-09'.to_date, '2007-07-15'.to_date], [c.startdt, c.enddt] |
|
| 39 |
|
|
| 40 |
c = Redmine::Helpers::Calendar.new(Date.today, :en, :week) |
|
| 41 |
assert_equal [7, 6], [c.startdt.cwday, c.enddt.cwday] |
|
| 42 |
end |
|
| 43 |
end |
|
| test/unit/.svn/text-base/changeset_test.rb.svn-base | ||
|---|---|---|
| 20 | 20 |
require File.expand_path('../../test_helper', __FILE__)
|
| 21 | 21 |
|
| 22 | 22 |
class ChangesetTest < ActiveSupport::TestCase |
| 23 |
fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers |
|
| 23 |
fixtures :projects, :repositories, |
|
| 24 |
:issues, :issue_statuses, :issue_categories, |
|
| 25 |
:changesets, :changes, |
|
| 26 |
:enumerations, |
|
| 27 |
:custom_fields, :custom_values, |
|
| 28 |
:users, :members, :member_roles, :trackers, |
|
| 29 |
:enabled_modules, :roles |
|
| 24 | 30 |
|
| 25 | 31 |
def setup |
| 26 | 32 |
end |
| 27 |
|
|
| 33 |
|
|
| 28 | 34 |
def test_ref_keywords_any |
| 29 | 35 |
ActionMailer::Base.deliveries.clear |
| 30 |
Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
| 36 |
Setting.commit_fix_status_id = IssueStatus.find( |
|
| 37 |
:first, :conditions => ["is_closed = ?", true]).id |
|
| 31 | 38 |
Setting.commit_fix_done_ratio = '90' |
| 32 | 39 |
Setting.commit_ref_keywords = '*' |
| 33 | 40 |
Setting.commit_fix_keywords = 'fixes , closes' |
| 34 |
|
|
| 35 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 41 |
|
|
| 42 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 36 | 43 |
:committed_on => Time.now, |
| 37 |
:comments => 'New commit (#2). Fixes #1') |
|
| 44 |
:comments => 'New commit (#2). Fixes #1')
|
|
| 38 | 45 |
c.scan_comment_for_issue_ids |
| 39 |
|
|
| 46 |
|
|
| 40 | 47 |
assert_equal [1, 2], c.issue_ids.sort |
| 41 | 48 |
fixed = Issue.find(1) |
| 42 | 49 |
assert fixed.closed? |
| 43 | 50 |
assert_equal 90, fixed.done_ratio |
| 44 | 51 |
assert_equal 1, ActionMailer::Base.deliveries.size |
| 45 | 52 |
end |
| 46 |
|
|
| 53 |
|
|
| 47 | 54 |
def test_ref_keywords |
| 48 | 55 |
Setting.commit_ref_keywords = 'refs' |
| 49 | 56 |
Setting.commit_fix_keywords = '' |
| 50 |
|
|
| 51 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 57 |
|
|
| 58 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 52 | 59 |
:committed_on => Time.now, |
| 53 |
:comments => 'Ignores #2. Refs #1') |
|
| 60 |
:comments => 'Ignores #2. Refs #1')
|
|
| 54 | 61 |
c.scan_comment_for_issue_ids |
| 55 | 62 |
|
| 56 | 63 |
assert_equal [1], c.issue_ids.sort |
| 57 | 64 |
end |
| 58 |
|
|
| 65 |
|
|
| 59 | 66 |
def test_ref_keywords_any_only |
| 60 | 67 |
Setting.commit_ref_keywords = '*' |
| 61 | 68 |
Setting.commit_fix_keywords = '' |
| 62 | 69 |
|
| 63 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 70 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 64 | 71 |
:committed_on => Time.now, |
| 65 |
:comments => 'Ignores #2. Refs #1') |
|
| 72 |
:comments => 'Ignores #2. Refs #1')
|
|
| 66 | 73 |
c.scan_comment_for_issue_ids |
| 67 |
|
|
| 74 |
|
|
| 68 | 75 |
assert_equal [1, 2], c.issue_ids.sort |
| 69 | 76 |
end |
| 70 |
|
|
| 77 |
|
|
| 71 | 78 |
def test_ref_keywords_any_with_timelog |
| 72 | 79 |
Setting.commit_ref_keywords = '*' |
| 73 | 80 |
Setting.commit_logtime_enabled = '1' |
| ... | ... | |
| 87 | 94 |
'3,25' => 3.25, |
| 88 | 95 |
'3,25h' => 3.25, |
| 89 | 96 |
}.each do |syntax, expected_hours| |
| 90 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 97 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 91 | 98 |
:committed_on => 24.hours.ago, |
| 92 |
:comments => "Worked on this issue #1 @#{syntax}",
|
|
| 93 |
:revision => '520', |
|
| 94 |
:user => User.find(2)) |
|
| 99 |
:comments => "Worked on this issue #1 @#{syntax}",
|
|
| 100 |
:revision => '520',
|
|
| 101 |
:user => User.find(2))
|
|
| 95 | 102 |
assert_difference 'TimeEntry.count' do |
| 96 | 103 |
c.scan_comment_for_issue_ids |
| 97 | 104 |
end |
| 98 | 105 |
assert_equal [1], c.issue_ids.sort |
| 99 |
|
|
| 106 |
|
|
| 100 | 107 |
time = TimeEntry.first(:order => 'id desc') |
| 101 | 108 |
assert_equal 1, time.issue_id |
| 102 | 109 |
assert_equal 1, time.project_id |
| 103 | 110 |
assert_equal 2, time.user_id |
| 104 |
assert_equal expected_hours, time.hours, "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
|
|
| 111 |
assert_equal expected_hours, time.hours, |
|
| 112 |
"@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
|
|
| 105 | 113 |
assert_equal Date.yesterday, time.spent_on |
| 106 | 114 |
assert time.activity.is_default? |
| 107 |
assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
|
|
| 115 |
assert time.comments.include?('r520'),
|
|
| 116 |
"r520 was expected in time_entry comments: #{time.comments}"
|
|
| 108 | 117 |
end |
| 109 | 118 |
end |
| 110 |
|
|
| 119 |
|
|
| 111 | 120 |
def test_ref_keywords_closing_with_timelog |
| 112 |
Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
| 121 |
Setting.commit_fix_status_id = IssueStatus.find( |
|
| 122 |
:first, :conditions => ["is_closed = ?", true]).id |
|
| 113 | 123 |
Setting.commit_ref_keywords = '*' |
| 114 | 124 |
Setting.commit_fix_keywords = 'fixes , closes' |
| 115 | 125 |
Setting.commit_logtime_enabled = '1' |
| 116 | 126 |
|
| 117 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 127 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 118 | 128 |
:committed_on => Time.now, |
| 119 |
:comments => 'This is a comment. Fixes #1 @4.5, #2 @1', |
|
| 120 |
:user => User.find(2)) |
|
| 129 |
:comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
|
|
| 130 |
:user => User.find(2))
|
|
| 121 | 131 |
assert_difference 'TimeEntry.count', 2 do |
| 122 | 132 |
c.scan_comment_for_issue_ids |
| 123 | 133 |
end |
| 124 |
|
|
| 134 |
|
|
| 125 | 135 |
assert_equal [1, 2], c.issue_ids.sort |
| 126 | 136 |
assert Issue.find(1).closed? |
| 127 | 137 |
assert Issue.find(2).closed? |
| ... | ... | |
| 129 | 139 |
times = TimeEntry.all(:order => 'id desc', :limit => 2) |
| 130 | 140 |
assert_equal [1, 2], times.collect(&:issue_id).sort |
| 131 | 141 |
end |
| 132 |
|
|
| 142 |
|
|
| 133 | 143 |
def test_ref_keywords_any_line_start |
| 134 | 144 |
Setting.commit_ref_keywords = '*' |
| 135 | 145 |
|
| 136 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 146 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 137 | 147 |
:committed_on => Time.now, |
| 138 |
:comments => '#1 is the reason of this commit') |
|
| 148 |
:comments => '#1 is the reason of this commit')
|
|
| 139 | 149 |
c.scan_comment_for_issue_ids |
| 140 | 150 |
|
| 141 | 151 |
assert_equal [1], c.issue_ids.sort |
| ... | ... | |
| 144 | 154 |
def test_ref_keywords_allow_brackets_around_a_issue_number |
| 145 | 155 |
Setting.commit_ref_keywords = '*' |
| 146 | 156 |
|
| 147 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 157 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 148 | 158 |
:committed_on => Time.now, |
| 149 |
:comments => '[#1] Worked on this issue') |
|
| 159 |
:comments => '[#1] Worked on this issue')
|
|
| 150 | 160 |
c.scan_comment_for_issue_ids |
| 151 | 161 |
|
| 152 | 162 |
assert_equal [1], c.issue_ids.sort |
| ... | ... | |
| 155 | 165 |
def test_ref_keywords_allow_brackets_around_multiple_issue_numbers |
| 156 | 166 |
Setting.commit_ref_keywords = '*' |
| 157 | 167 |
|
| 158 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 168 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 159 | 169 |
:committed_on => Time.now, |
| 160 |
:comments => '[#1 #2, #3] Worked on these') |
|
| 170 |
:comments => '[#1 #2, #3] Worked on these')
|
|
| 161 | 171 |
c.scan_comment_for_issue_ids |
| 162 | 172 |
|
| 163 | 173 |
assert_equal [1,2,3], c.issue_ids.sort |
| 164 | 174 |
end |
| 165 |
|
|
| 175 |
|
|
| 166 | 176 |
def test_commit_referencing_a_subproject_issue |
| 167 |
c = Changeset.new(:repository => Project.find(1).repository, |
|
| 177 |
c = Changeset.new(:repository => Project.find(1).repository,
|
|
| 168 | 178 |
:committed_on => Time.now, |
| 169 |
:comments => 'refs #5, a subproject issue') |
|
| 179 |
:comments => 'refs #5, a subproject issue')
|
|
| 170 | 180 |
c.scan_comment_for_issue_ids |
| 171 |
|
|
| 181 |
|
|
| 172 | 182 |
assert_equal [5], c.issue_ids.sort |
| 173 | 183 |
assert c.issues.first.project != c.project |
| 174 | 184 |
end |
| 175 | 185 |
|
| 176 | 186 |
def test_commit_referencing_a_parent_project_issue |
| 177 | 187 |
# repository of child project |
| 178 |
r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test') |
|
| 179 |
|
|
| 180 |
c = Changeset.new(:repository => r, |
|
| 188 |
r = Repository::Subversion.create!( |
|
| 189 |
:project => Project.find(3), |
|
| 190 |
:url => 'svn://localhost/test') |
|
| 191 |
|
|
| 192 |
c = Changeset.new(:repository => r, |
|
| 181 | 193 |
:committed_on => Time.now, |
| 182 |
:comments => 'refs #2, an issue of a parent project') |
|
| 194 |
:comments => 'refs #2, an issue of a parent project')
|
|
| 183 | 195 |
c.scan_comment_for_issue_ids |
| 184 |
|
|
| 196 |
|
|
| 185 | 197 |
assert_equal [2], c.issue_ids.sort |
| 186 | 198 |
assert c.issues.first.project != c.project |
| 187 | 199 |
end |
| ... | ... | |
| 192 | 204 |
end |
| 193 | 205 |
|
| 194 | 206 |
def test_text_tag_hash |
| 195 |
c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
| 207 |
c = Changeset.new( |
|
| 208 |
:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
| 209 |
:revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
| 196 | 210 |
assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag |
| 197 | 211 |
end |
| 198 | 212 |
|
| ... | ... | |
| 222 | 236 |
end |
| 223 | 237 |
|
| 224 | 238 |
def test_comments_should_be_converted_to_utf8 |
| 225 |
proj = Project.find(3) |
|
| 226 |
str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
|
| 227 |
r = Repository::Bazaar.create!( |
|
| 228 |
:project => proj, :url => '/tmp/test/bazaar', |
|
| 239 |
proj = Project.find(3) |
|
| 240 |
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
|
| 241 |
str = "Texte encod\xe9 en ISO-8859-1." |
|
| 242 |
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
|
|
| 243 |
r = Repository::Bazaar.create!( |
|
| 244 |
:project => proj, |
|
| 245 |
:url => '/tmp/test/bazaar', |
|
| 229 | 246 |
:log_encoding => 'ISO-8859-1' ) |
| 230 |
assert r |
|
| 231 |
c = Changeset.new(:repository => r, |
|
| 232 |
:committed_on => Time.now, |
|
| 233 |
:revision => '123', |
|
| 234 |
:scmid => '12345', |
|
| 235 |
:comments => str) |
|
| 236 |
assert( c.save ) |
|
| 237 |
assert_equal "Texte encodé en ISO-8859-1.", c.comments |
|
| 247 |
assert r |
|
| 248 |
c = Changeset.new(:repository => r, |
|
| 249 |
:committed_on => Time.now, |
|
| 250 |
:revision => '123', |
|
| 251 |
:scmid => '12345', |
|
| 252 |
:comments => str) |
|
| 253 |
assert( c.save ) |
|
| 254 |
str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1." |
|
| 255 |
str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
|
|
| 256 |
assert_equal str_utf8, c.comments |
|
| 238 | 257 |
end |
| 239 | 258 |
|
| 240 |
def test_invalid_utf8_sequences_in_comments_should_be_stripped |
|
| 241 |
proj = Project.find(3) |
|
| 242 |
str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
|
| 243 |
r = Repository::Bazaar.create!( |
|
| 244 |
:project => proj, :url => '/tmp/test/bazaar', |
|
| 259 |
def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1 |
|
| 260 |
proj = Project.find(3) |
|
| 261 |
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
|
| 262 |
str1 = "Texte encod\xe9 en ISO-8859-1." |
|
| 263 |
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
|
| 264 |
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
|
| 265 |
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
|
| 266 |
r = Repository::Bazaar.create!( |
|
| 267 |
:project => proj, |
|
| 268 |
:url => '/tmp/test/bazaar', |
|
| 245 | 269 |
:log_encoding => 'UTF-8' ) |
| 246 |
assert r |
|
| 247 |
c = Changeset.new(:repository => r, |
|
| 248 |
:committed_on => Time.now, |
|
| 249 |
:revision => '123', |
|
| 250 |
:scmid => '12345', |
|
| 251 |
:comments => str) |
|
| 252 |
assert( c.save ) |
|
| 253 |
if str.respond_to?(:force_encoding) |
|
| 254 |
assert_equal "Texte encod? en ISO-8859-1.", c.comments |
|
| 255 |
else |
|
| 256 |
assert_equal "Texte encod en ISO-8859-1.", c.comments |
|
| 257 |
end |
|
| 270 |
assert r |
|
| 271 |
c = Changeset.new(:repository => r, |
|
| 272 |
:committed_on => Time.now, |
|
| 273 |
:revision => '123', |
|
| 274 |
:scmid => '12345', |
|
| 275 |
:comments => str1, |
|
| 276 |
:committer => str2) |
|
| 277 |
assert( c.save ) |
|
| 278 |
assert_equal "Texte encod? en ISO-8859-1.", c.comments |
|
| 279 |
assert_equal "?a?b?c?d?e test", c.committer |
|
| 280 |
end |
|
| 281 |
|
|
| 282 |
def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis |
|
| 283 |
proj = Project.find(3) |
|
| 284 |
str = "test\xb5\xfetest\xb5\xfe" |
|
| 285 |
if str.respond_to?(:force_encoding) |
|
| 286 |
str.force_encoding('ASCII-8BIT')
|
|
| 287 |
end |
|
| 288 |
r = Repository::Bazaar.create!( |
|
| 289 |
:project => proj, |
|
| 290 |
:url => '/tmp/test/bazaar', |
|
| 291 |
:log_encoding => 'ISO-2022-JP' ) |
|
| 292 |
assert r |
|
| 293 |
c = Changeset.new(:repository => r, |
|
| 294 |
:committed_on => Time.now, |
|
| 295 |
:revision => '123', |
|
| 296 |
:scmid => '12345', |
|
| 297 |
:comments => str) |
|
| 298 |
assert( c.save ) |
|
| 299 |
assert_equal "test??test??", c.comments |
|
| 258 | 300 |
end |
| 259 | 301 |
|
| 260 | 302 |
def test_comments_should_be_converted_all_latin1_to_utf8 |
| 261 |
s1 = "\xC2\x80" |
|
| 262 |
s2 = "\xc3\x82\xc2\x80" |
|
| 263 |
if s1.respond_to?(:force_encoding) |
|
| 264 |
s3 = s1 |
|
| 265 |
s4 = s2 |
|
| 266 |
s1.force_encoding('ASCII-8BIT')
|
|
| 267 |
s2.force_encoding('ASCII-8BIT')
|
|
| 268 |
s3.force_encoding('ISO-8859-1')
|
|
| 269 |
s4.force_encoding('UTF-8')
|
|
| 270 |
assert_equal s3.encode('UTF-8'), s4
|
|
| 271 |
end |
|
| 272 |
proj = Project.find(3) |
|
| 273 |
r = Repository::Bazaar.create!( |
|
| 274 |
:project => proj, :url => '/tmp/test/bazaar', |
|
| 303 |
s1 = "\xC2\x80" |
|
| 304 |
s2 = "\xc3\x82\xc2\x80" |
|
| 305 |
s4 = s2.dup |
|
| 306 |
if s1.respond_to?(:force_encoding) |
|
| 307 |
s3 = s1.dup |
|
| 308 |
s1.force_encoding('ASCII-8BIT')
|
|
| 309 |
s2.force_encoding('ASCII-8BIT')
|
|
| 310 |
s3.force_encoding('ISO-8859-1')
|
|
| 311 |
s4.force_encoding('UTF-8')
|
|
| 312 |
assert_equal s3.encode('UTF-8'), s4
|
|
| 313 |
end |
|
| 314 |
proj = Project.find(3) |
|
| 315 |
r = Repository::Bazaar.create!( |
|
| 316 |
:project => proj, |
|
| 317 |
:url => '/tmp/test/bazaar', |
|
| 275 | 318 |
:log_encoding => 'ISO-8859-1' ) |
| 276 |
assert r |
|
| 277 |
c = Changeset.new(:repository => r, |
|
| 278 |
:committed_on => Time.now, |
|
| 279 |
:revision => '123', |
|
| 280 |
:scmid => '12345', |
|
| 281 |
:comments => s1) |
|
| 282 |
assert( c.save ) |
|
| 283 |
assert_equal s2, c.comments |
|
| 319 |
assert r |
|
| 320 |
c = Changeset.new(:repository => r, |
|
| 321 |
:committed_on => Time.now, |
|
| 322 |
:revision => '123', |
|
| 323 |
:scmid => '12345', |
|
| 324 |
:comments => s1) |
|
| 325 |
assert( c.save ) |
|
| 326 |
assert_equal s4, c.comments |
|
| 327 |
end |
|
| 328 |
|
|
| 329 |
def test_invalid_utf8_sequences_in_paths_should_be_replaced |
|
| 330 |
proj = Project.find(3) |
|
| 331 |
str1 = "Texte encod\xe9 en ISO-8859-1" |
|
| 332 |
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
|
| 333 |
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
|
| 334 |
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
|
| 335 |
r = Repository::Bazaar.create!( |
|
| 336 |
:project => proj, |
|
| 337 |
:url => '/tmp/test/bazaar', |
|
| 338 |
:log_encoding => 'UTF-8' ) |
|
| 339 |
assert r |
|
| 340 |
cs = Changeset.new( |
|
| 341 |
:repository => r, |
|
| 342 |
:committed_on => Time.now, |
|
| 343 |
:revision => '123', |
|
| 344 |
:scmid => '12345', |
|
| 345 |
:comments => "test") |
|
| 346 |
assert(cs.save) |
|
| 347 |
ch = Change.new( |
|
| 348 |
:changeset => cs, |
|
| 349 |
:action => "A", |
|
| 350 |
:path => str1, |
|
| 351 |
:from_path => str2, |
|
| 352 |
:from_revision => "345") |
|
| 353 |
assert(ch.save) |
|
| 354 |
assert_equal "Texte encod? en ISO-8859-1", ch.path |
|
| 355 |
assert_equal "?a?b?c?d?e test", ch.from_path |
|
| 356 |
end |
|
| 357 |
|
|
| 358 |
def test_comments_nil |
|
| 359 |
proj = Project.find(3) |
|
| 360 |
r = Repository::Bazaar.create!( |
|
| 361 |
:project => proj, |
|
| 362 |
:url => '/tmp/test/bazaar', |
|
| 363 |
:log_encoding => 'ISO-8859-1' ) |
|
| 364 |
assert r |
|
| 365 |
c = Changeset.new(:repository => r, |
|
| 366 |
:committed_on => Time.now, |
|
| 367 |
:revision => '123', |
|
| 368 |
:scmid => '12345', |
|
| 369 |
:comments => nil, |
|
| 370 |
:committer => nil) |
|
| 371 |
assert( c.save ) |
|
| 372 |
assert_equal "", c.comments |
|
| 373 |
assert_equal nil, c.committer |
|
| 374 |
if c.comments.respond_to?(:force_encoding) |
|
| 375 |
assert_equal "UTF-8", c.comments.encoding.to_s |
|
| 376 |
end |
|
| 377 |
end |
|
| 378 |
|
|
| 379 |
def test_comments_empty |
|
| 380 |
proj = Project.find(3) |
|
| 381 |
r = Repository::Bazaar.create!( |
|
| 382 |
:project => proj, |
|
| 383 |
:url => '/tmp/test/bazaar', |
|
| 384 |
:log_encoding => 'ISO-8859-1' ) |
|
| 385 |
assert r |
|
| 386 |
c = Changeset.new(:repository => r, |
|
| 387 |
:committed_on => Time.now, |
|
| 388 |
:revision => '123', |
|
| 389 |
:scmid => '12345', |
|
| 390 |
:comments => "", |
|
| 391 |
:committer => "") |
|
| 392 |
assert( c.save ) |
|
| 393 |
assert_equal "", c.comments |
|
| 394 |
assert_equal "", c.committer |
|
| 395 |
if c.comments.respond_to?(:force_encoding) |
|
| 396 |
assert_equal "UTF-8", c.comments.encoding.to_s |
|
| 397 |
assert_equal "UTF-8", c.committer.encoding.to_s |
|
| 398 |
end |
|
| 284 | 399 |
end |
| 285 | 400 |
|
| 286 | 401 |
def test_identifier |
| test/unit/.svn/text-base/comment_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| ... | ... | |
| 31 | 31 |
@news.reload |
| 32 | 32 |
assert_equal 2, @news.comments_count |
| 33 | 33 |
end |
| 34 |
|
|
| 35 |
def test_create_should_send_notification |
|
| 36 |
Setting.notified_events << 'news_comment_added' |
|
| 37 |
Watcher.create!(:watchable => @news, :user => @jsmith) |
|
| 38 |
|
|
| 39 |
assert_difference 'ActionMailer::Base.deliveries.size' do |
|
| 40 |
Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment") |
|
| 41 |
end |
|
| 42 |
end |
|
| 34 | 43 |
|
| 35 | 44 |
def test_validate |
| 36 | 45 |
comment = Comment.new(:commented => @news) |
| test/unit/.svn/text-base/default_data_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 20 | 20 |
class DefaultDataTest < ActiveSupport::TestCase |
| 21 | 21 |
include Redmine::I18n |
| 22 | 22 |
fixtures :roles |
| 23 |
|
|
| 23 |
|
|
| 24 | 24 |
def test_no_data |
| 25 | 25 |
assert !Redmine::DefaultData::Loader::no_data? |
| 26 | 26 |
Role.delete_all("builtin = 0")
|
| ... | ... | |
| 29 | 29 |
Enumeration.delete_all |
| 30 | 30 |
assert Redmine::DefaultData::Loader::no_data? |
| 31 | 31 |
end |
| 32 |
|
|
| 32 |
|
|
| 33 | 33 |
def test_load |
| 34 | 34 |
valid_languages.each do |lang| |
| 35 | 35 |
begin |
| test/unit/.svn/text-base/document_category_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 23 | 23 |
def test_should_be_an_enumeration |
| 24 | 24 |
assert DocumentCategory.ancestors.include?(Enumeration) |
| 25 | 25 |
end |
| 26 |
|
|
| 26 |
|
|
| 27 | 27 |
def test_objects_count |
| 28 | 28 |
assert_equal 2, DocumentCategory.find_by_name("Uncategorized").objects_count
|
| 29 | 29 |
assert_equal 0, DocumentCategory.find_by_name("User documentation").objects_count
|
| ... | ... | |
| 33 | 33 |
assert_equal :enumeration_doc_categories, DocumentCategory.new.option_name |
| 34 | 34 |
end |
| 35 | 35 |
end |
| 36 |
|
|
| test/unit/.svn/text-base/document_test.rb.svn-base | ||
|---|---|---|
| 1 | 1 |
# Redmine - project management software |
| 2 |
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 24 | 24 |
doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
|
| 25 | 25 |
assert doc.save |
| 26 | 26 |
end |
| 27 |
|
|
| 27 |
|
|
| 28 | 28 |
def test_create_should_send_email_notification |
| 29 | 29 |
ActionMailer::Base.deliveries.clear |
| 30 | 30 |
Setting.notified_events << 'document_added' |
| ... | ... | |
| 38 | 38 |
# Sets a default category |
| 39 | 39 |
e = Enumeration.find_by_name('Technical documentation')
|
| 40 | 40 |
e.update_attributes(:is_default => true) |
| 41 |
|
|
| 41 |
|
|
| 42 | 42 |
doc = Document.new(:project => Project.find(1), :title => 'New document') |
| 43 | 43 |
assert_equal e, doc.category |
| 44 | 44 |
assert doc.save |
| 45 | 45 |
end |
| 46 |
|
|
| 46 |
|
|
| 47 | 47 |
def test_updated_on_with_attachments |
| 48 | 48 |
d = Document.find(1) |
| 49 | 49 |
assert d.attachments.any? |
| 50 | 50 |
assert_equal d.attachments.map(&:created_on).max, d.updated_on |
| 51 | 51 |
end |
| 52 |
|
|
| 52 |
|
|
| 53 | 53 |
def test_updated_on_without_attachments |
| 54 | 54 |
d = Document.find(2) |
| 55 | 55 |
assert d.attachments.empty? |
| test/unit/.svn/text-base/enabled_module_test.rb.svn-base | ||
|---|---|---|
| 1 | 1 |
# Redmine - project management software |
| 2 |
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 19 | 19 |
|
| 20 | 20 |
class EnabledModuleTest < ActiveSupport::TestCase |
| 21 | 21 |
fixtures :projects, :wikis |
| 22 |
|
|
| 22 |
|
|
| 23 | 23 |
def test_enabling_wiki_should_create_a_wiki |
| 24 | 24 |
CustomField.delete_all |
| 25 | 25 |
project = Project.create!(:name => 'Project with wiki', :identifier => 'wikiproject') |
| ... | ... | |
| 29 | 29 |
assert_not_nil project.wiki |
| 30 | 30 |
assert_equal 'Wiki', project.wiki.start_page |
| 31 | 31 |
end |
| 32 |
|
|
| 32 |
|
|
| 33 | 33 |
def test_reenabling_wiki_should_not_create_another_wiki |
| 34 | 34 |
project = Project.find(1) |
| 35 | 35 |
assert_not_nil project.wiki |
| test/unit/.svn/text-base/issue_nested_set_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 21 | 21 |
fixtures :projects, :users, :members, :member_roles, :roles, |
| 22 | 22 |
:trackers, :projects_trackers, |
| 23 | 23 |
:versions, |
| 24 |
:issue_statuses, :issue_categories, :issue_relations, :workflows,
|
|
| 24 |
:issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
| 25 | 25 |
:enumerations, |
| 26 | 26 |
:issues, |
| 27 | 27 |
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
| 28 | 28 |
:time_entries |
| 29 | 29 |
|
| 30 | 30 |
self.use_transactional_fixtures = false |
| 31 |
|
|
| 31 |
|
|
| 32 | 32 |
def test_create_root_issue |
| 33 | 33 |
issue1 = create_issue! |
| 34 | 34 |
issue2 = create_issue! |
| 35 | 35 |
issue1.reload |
| 36 | 36 |
issue2.reload |
| 37 |
|
|
| 37 |
|
|
| 38 | 38 |
assert_equal [issue1.id, nil, 1, 2], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt] |
| 39 | 39 |
assert_equal [issue2.id, nil, 1, 2], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt] |
| 40 | 40 |
end |
| 41 |
|
|
| 41 |
|
|
| 42 | 42 |
def test_create_child_issue |
| 43 | 43 |
parent = create_issue! |
| 44 | 44 |
child = create_issue!(:parent_issue_id => parent.id) |
| 45 | 45 |
parent.reload |
| 46 | 46 |
child.reload |
| 47 |
|
|
| 47 |
|
|
| 48 | 48 |
assert_equal [parent.id, nil, 1, 4], [parent.root_id, parent.parent_id, parent.lft, parent.rgt] |
| 49 | 49 |
assert_equal [parent.id, parent.id, 2, 3], [child.root_id, child.parent_id, child.lft, child.rgt] |
| 50 | 50 |
end |
| 51 |
|
|
| 51 |
|
|
| 52 | 52 |
def test_creating_a_child_in_different_project_should_not_validate |
| 53 | 53 |
issue = create_issue! |
| 54 | 54 |
child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, :subject => 'child', :parent_issue_id => issue.id) |
| 55 | 55 |
assert !child.save |
| 56 | 56 |
assert_not_nil child.errors.on(:parent_issue_id) |
| 57 | 57 |
end |
| 58 |
|
|
| 58 |
|
|
| 59 | 59 |
def test_move_a_root_to_child |
| 60 | 60 |
parent1 = create_issue! |
| 61 | 61 |
parent2 = create_issue! |
| 62 | 62 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 63 |
|
|
| 63 |
|
|
| 64 | 64 |
parent2.parent_issue_id = parent1.id |
| 65 | 65 |
parent2.save! |
| 66 | 66 |
child.reload |
| 67 | 67 |
parent1.reload |
| 68 | 68 |
parent2.reload |
| 69 |
|
|
| 69 |
|
|
| 70 | 70 |
assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt] |
| 71 | 71 |
assert_equal [parent1.id, 4, 5], [parent2.root_id, parent2.lft, parent2.rgt] |
| 72 | 72 |
assert_equal [parent1.id, 2, 3], [child.root_id, child.lft, child.rgt] |
| 73 | 73 |
end |
| 74 |
|
|
| 74 |
|
|
| 75 | 75 |
def test_move_a_child_to_root |
| 76 | 76 |
parent1 = create_issue! |
| 77 | 77 |
parent2 = create_issue! |
| 78 | 78 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 79 |
|
|
| 79 |
|
|
| 80 | 80 |
child.parent_issue_id = nil |
| 81 | 81 |
child.save! |
| 82 | 82 |
child.reload |
| 83 | 83 |
parent1.reload |
| 84 | 84 |
parent2.reload |
| 85 |
|
|
| 85 |
|
|
| 86 | 86 |
assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] |
| 87 | 87 |
assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt] |
| 88 | 88 |
assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt] |
| 89 | 89 |
end |
| 90 |
|
|
| 90 |
|
|
| 91 | 91 |
def test_move_a_child_to_another_issue |
| 92 | 92 |
parent1 = create_issue! |
| 93 | 93 |
parent2 = create_issue! |
| 94 | 94 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 95 |
|
|
| 95 |
|
|
| 96 | 96 |
child.parent_issue_id = parent2.id |
| 97 | 97 |
child.save! |
| 98 | 98 |
child.reload |
| 99 | 99 |
parent1.reload |
| 100 | 100 |
parent2.reload |
| 101 |
|
|
| 101 |
|
|
| 102 | 102 |
assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] |
| 103 | 103 |
assert_equal [parent2.id, 1, 4], [parent2.root_id, parent2.lft, parent2.rgt] |
| 104 | 104 |
assert_equal [parent2.id, 2, 3], [child.root_id, child.lft, child.rgt] |
| 105 | 105 |
end |
| 106 |
|
|
| 106 |
|
|
| 107 | 107 |
def test_move_a_child_with_descendants_to_another_issue |
| 108 | 108 |
parent1 = create_issue! |
| 109 | 109 |
parent2 = create_issue! |
| 110 | 110 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 111 | 111 |
grandchild = create_issue!(:parent_issue_id => child.id) |
| 112 |
|
|
| 112 |
|
|
| 113 | 113 |
parent1.reload |
| 114 | 114 |
parent2.reload |
| 115 | 115 |
child.reload |
| 116 | 116 |
grandchild.reload |
| 117 |
|
|
| 117 |
|
|
| 118 | 118 |
assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt] |
| 119 | 119 |
assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt] |
| 120 | 120 |
assert_equal [parent1.id, 2, 5], [child.root_id, child.lft, child.rgt] |
| 121 | 121 |
assert_equal [parent1.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt] |
| 122 |
|
|
| 122 |
|
|
| 123 | 123 |
child.reload.parent_issue_id = parent2.id |
| 124 | 124 |
child.save! |
| 125 | 125 |
child.reload |
| 126 | 126 |
grandchild.reload |
| 127 | 127 |
parent1.reload |
| 128 | 128 |
parent2.reload |
| 129 |
|
|
| 129 |
|
|
| 130 | 130 |
assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] |
| 131 | 131 |
assert_equal [parent2.id, 1, 6], [parent2.root_id, parent2.lft, parent2.rgt] |
| 132 | 132 |
assert_equal [parent2.id, 2, 5], [child.root_id, child.lft, child.rgt] |
| 133 | 133 |
assert_equal [parent2.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt] |
| 134 | 134 |
end |
| 135 |
|
|
| 135 |
|
|
| 136 | 136 |
def test_move_a_child_with_descendants_to_another_project |
| 137 | 137 |
parent1 = create_issue! |
| 138 | 138 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 139 | 139 |
grandchild = create_issue!(:parent_issue_id => child.id) |
| 140 |
|
|
| 140 |
|
|
| 141 | 141 |
assert child.reload.move_to_project(Project.find(2)) |
| 142 | 142 |
child.reload |
| 143 | 143 |
grandchild.reload |
| 144 | 144 |
parent1.reload |
| 145 |
|
|
| 145 |
|
|
| 146 | 146 |
assert_equal [1, parent1.id, 1, 2], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
| 147 | 147 |
assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt] |
| 148 | 148 |
assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] |
| 149 | 149 |
end |
| 150 |
|
|
| 150 |
|
|
| 151 | 151 |
def test_invalid_move_to_another_project |
| 152 | 152 |
parent1 = create_issue! |
| 153 | 153 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 154 | 154 |
grandchild = create_issue!(:parent_issue_id => child.id, :tracker_id => 2) |
| 155 | 155 |
Project.find(2).tracker_ids = [1] |
| 156 |
|
|
| 156 |
|
|
| 157 | 157 |
parent1.reload |
| 158 | 158 |
assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
| 159 |
|
|
| 159 |
|
|
| 160 | 160 |
# child can not be moved to Project 2 because its child is on a disabled tracker |
| 161 | 161 |
assert_equal false, Issue.find(child.id).move_to_project(Project.find(2)) |
| 162 | 162 |
child.reload |
| 163 | 163 |
grandchild.reload |
| 164 | 164 |
parent1.reload |
| 165 |
|
|
| 165 |
|
|
| 166 | 166 |
# no change |
| 167 | 167 |
assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
| 168 | 168 |
assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt] |
| 169 | 169 |
assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] |
| 170 | 170 |
end |
| 171 |
|
|
| 171 |
|
|
| 172 | 172 |
def test_moving_an_issue_to_a_descendant_should_not_validate |
| 173 | 173 |
parent1 = create_issue! |
| 174 | 174 |
parent2 = create_issue! |
| 175 | 175 |
child = create_issue!(:parent_issue_id => parent1.id) |
| 176 | 176 |
grandchild = create_issue!(:parent_issue_id => child.id) |
| 177 |
|
|
| 177 |
|
|
| 178 | 178 |
child.reload |
| 179 | 179 |
child.parent_issue_id = grandchild.id |
| 180 | 180 |
assert !child.save |
| 181 | 181 |
assert_not_nil child.errors.on(:parent_issue_id) |
| 182 | 182 |
end |
| 183 |
|
|
| 183 |
|
|
| 184 | 184 |
def test_moving_an_issue_should_keep_valid_relations_only |
| 185 | 185 |
issue1 = create_issue! |
| 186 | 186 |
issue2 = create_issue! |
| ... | ... | |
| 196 | 196 |
assert !IssueRelation.exists?(r2.id) |
| 197 | 197 |
assert IssueRelation.exists?(r3.id) |
| 198 | 198 |
end |
| 199 |
|
|
| 199 |
|
|
| 200 | 200 |
def test_destroy_should_destroy_children |
| 201 | 201 |
issue1 = create_issue! |
| 202 | 202 |
issue2 = create_issue! |
| 203 | 203 |
issue3 = create_issue!(:parent_issue_id => issue2.id) |
| 204 | 204 |
issue4 = create_issue!(:parent_issue_id => issue1.id) |
| 205 |
|
|
| 205 |
|
|
| 206 | 206 |
issue3.init_journal(User.find(2)) |
| 207 | 207 |
issue3.subject = 'child with journal' |
| 208 | 208 |
issue3.save! |
| 209 |
|
|
| 209 |
|
|
| 210 | 210 |
assert_difference 'Issue.count', -2 do |
| 211 | 211 |
assert_difference 'Journal.count', -1 do |
| 212 | 212 |
assert_difference 'JournalDetail.count', -1 do |
| ... | ... | |
| 214 | 214 |
end |
| 215 | 215 |
end |
| 216 | 216 |
end |
| 217 |
|
|
| 217 |
|
|
| 218 | 218 |
issue1.reload |
| 219 | 219 |
issue4.reload |
| 220 | 220 |
assert !Issue.exists?(issue2.id) |
| ... | ... | |
| 222 | 222 |
assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt] |
| 223 | 223 |
assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt] |
| 224 | 224 |
end |
| 225 |
|
|
| 225 |
|
|
| 226 |
def test_destroy_parent_issue_updated_during_children_destroy |
|
| 227 |
parent = create_issue! |
|
| 228 |
create_issue!(:start_date => Date.today, :parent_issue_id => parent.id) |
|
| 229 |
create_issue!(:start_date => 2.days.from_now, :parent_issue_id => parent.id) |
|
| 230 |
|
|
| 231 |
assert_difference 'Issue.count', -3 do |
|
| 232 |
Issue.find(parent.id).destroy |
|
| 233 |
end |
|
| 234 |
end |
|
| 235 |
|
|
| 226 | 236 |
def test_destroy_child_issue_with_children |
| 227 | 237 |
root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root') |
| 228 | 238 |
child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id) |
| ... | ... | |
| 230 | 240 |
leaf.init_journal(User.find(2)) |
| 231 | 241 |
leaf.subject = 'leaf with journal' |
| 232 | 242 |
leaf.save! |
| 233 |
|
|
| 243 |
|
|
| 234 | 244 |
assert_difference 'Issue.count', -2 do |
| 235 | 245 |
assert_difference 'Journal.count', -1 do |
| 236 | 246 |
assert_difference 'JournalDetail.count', -1 do |
| ... | ... | |
| 238 | 248 |
end |
| 239 | 249 |
end |
| 240 | 250 |
end |
| 241 |
|
|
| 251 |
|
|
| 242 | 252 |
root = Issue.find(root.id) |
| 243 | 253 |
assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
|
| 244 | 254 |
end |
| 245 |
|
|
| 255 |
|
|
| 246 | 256 |
def test_parent_priority_should_be_the_highest_child_priority |
| 247 | 257 |
parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
|
| 248 | 258 |
# Create children |
| ... | ... | |
| 261 | 271 |
child3.save! |
| 262 | 272 |
assert_equal 'Normal', parent.reload.priority.name |
| 263 | 273 |
end |
| 264 |
|
|
| 274 |
|
|
| 265 | 275 |
def test_parent_dates_should_be_lowest_start_and_highest_due_dates |
| 266 | 276 |
parent = create_issue! |
| 267 | 277 |
create_issue!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id) |
| ... | ... | |
| 271 | 281 |
assert_equal Date.parse('2010-01-25'), parent.start_date
|
| 272 | 282 |
assert_equal Date.parse('2010-02-22'), parent.due_date
|
| 273 | 283 |
end |
| 274 |
|
|
| 284 |
|
|
| 275 | 285 |
def test_parent_done_ratio_should_be_average_done_ratio_of_leaves |
| 276 | 286 |
parent = create_issue! |
| 277 | 287 |
create_issue!(:done_ratio => 20, :parent_issue_id => parent.id) |
| 278 | 288 |
assert_equal 20, parent.reload.done_ratio |
| 279 | 289 |
create_issue!(:done_ratio => 70, :parent_issue_id => parent.id) |
| 280 | 290 |
assert_equal 45, parent.reload.done_ratio |
| 281 |
|
|
| 291 |
|
|
| 282 | 292 |
child = create_issue!(:done_ratio => 0, :parent_issue_id => parent.id) |
| 283 | 293 |
assert_equal 30, parent.reload.done_ratio |
| 284 |
|
|
| 294 |
|
|
| 285 | 295 |
create_issue!(:done_ratio => 30, :parent_issue_id => child.id) |
| 286 | 296 |
assert_equal 30, child.reload.done_ratio |
| 287 | 297 |
assert_equal 40, parent.reload.done_ratio |
| 288 | 298 |
end |
| 289 |
|
|
| 299 |
|
|
| 290 | 300 |
def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any |
| 291 | 301 |
parent = create_issue! |
| 292 | 302 |
create_issue!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id) |
| ... | ... | |
| 294 | 304 |
create_issue!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id) |
| 295 | 305 |
assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio |
| 296 | 306 |
end |
| 297 |
|
|
| 307 |
|
|
| 298 | 308 |
def test_parent_estimate_should_be_sum_of_leaves |
| 299 | 309 |
parent = create_issue! |
| 300 | 310 |
create_issue!(:estimated_hours => nil, :parent_issue_id => parent.id) |
| ... | ... | |
| 328 | 338 |
parent.reload |
| 329 | 339 |
assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date]
|
| 330 | 340 |
end |
| 331 |
|
|
| 341 |
|
|
| 332 | 342 |
def test_project_copy_should_copy_issue_tree |
| 333 | 343 |
p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) |
| 334 | 344 |
i1 = create_issue!(:project_id => p.id, :subject => 'i1') |
| ... | ... | |
| 339 | 349 |
c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) |
| 340 | 350 |
c.copy(p, :only => 'issues') |
| 341 | 351 |
c.reload |
| 342 |
|
|
| 352 |
|
|
| 343 | 353 |
assert_equal 5, c.issues.count |
| 344 | 354 |
ic1, ic2, ic3, ic4, ic5 = c.issues.find(:all, :order => 'subject') |
| 345 | 355 |
assert ic1.root? |
| ... | ... | |
| 348 | 358 |
assert_equal ic2, ic4.parent |
| 349 | 359 |
assert ic5.root? |
| 350 | 360 |
end |
| 351 |
|
|
| 361 |
|
|
| 352 | 362 |
# Helper that creates an issue with default attributes |
| 353 | 363 |
def create_issue!(attributes={})
|
| 354 | 364 |
Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes))
|
| test/unit/.svn/text-base/issue_test.rb.svn-base | ||
|---|---|---|
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 22 | 22 |
:trackers, :projects_trackers, |
| 23 | 23 |
:enabled_modules, |
| 24 | 24 |
:versions, |
| 25 |
:issue_statuses, :issue_categories, :issue_relations, :workflows,
|
|
| 25 |
:issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
| 26 | 26 |
:enumerations, |
| 27 | 27 |
:issues, |
| 28 | 28 |
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
| ... | ... | |
| 34 | 34 |
issue.reload |
| 35 | 35 |
assert_equal 1.5, issue.estimated_hours |
| 36 | 36 |
end |
| 37 |
|
|
| 37 |
|
|
| 38 | 38 |
def test_create_minimal |
| 39 | 39 |
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create') |
| 40 | 40 |
assert issue.save |
| 41 | 41 |
assert issue.description.nil? |
| 42 | 42 |
end |
| 43 |
|
|
| 43 |
|
|
| 44 | 44 |
def test_create_with_required_custom_field |
| 45 | 45 |
field = IssueCustomField.find_by_name('Database')
|
| 46 | 46 |
field.update_attribute(:is_required, true) |
| 47 |
|
|
| 47 |
|
|
| 48 | 48 |
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
| 49 | 49 |
assert issue.available_custom_fields.include?(field) |
| 50 | 50 |
# No value for the custom field |
| ... | ... | |
| 64 | 64 |
issue.reload |
| 65 | 65 |
assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
| 66 | 66 |
end |
| 67 |
|
|
| 67 |
|
|
| 68 |
def assert_visibility_match(user, issues) |
|
| 69 |
assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort
|
|
| 70 |
end |
|
| 71 |
|
|
| 68 | 72 |
def test_visible_scope_for_anonymous |
| 69 | 73 |
# Anonymous user should see issues of public projects only |
| 70 | 74 |
issues = Issue.visible(User.anonymous).all |
| 71 | 75 |
assert issues.any? |
| 72 | 76 |
assert_nil issues.detect {|issue| !issue.project.is_public?}
|
| 77 |
assert_nil issues.detect {|issue| issue.is_private?}
|
|
| 78 |
assert_visibility_match User.anonymous, issues |
|
| 79 |
end |
|
| 80 |
|
|
| 81 |
def test_visible_scope_for_anonymous_with_own_issues_visibility |
|
| 82 |
Role.anonymous.update_attribute :issues_visibility, 'own' |
|
| 83 |
Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => User.anonymous.id, :subject => 'Issue by anonymous') |
|
| 84 |
|
|
| 85 |
issues = Issue.visible(User.anonymous).all |
|
| 86 |
assert issues.any? |
|
| 87 |
assert_nil issues.detect {|issue| issue.author != User.anonymous}
|
|
| 88 |
assert_visibility_match User.anonymous, issues |
|
| 89 |
end |
|
| 90 |
|
|
| 91 |
def test_visible_scope_for_anonymous_without_view_issues_permissions |
|
| 73 | 92 |
# Anonymous user should not see issues without permission |
| 74 | 93 |
Role.anonymous.remove_permission!(:view_issues) |
| 75 | 94 |
issues = Issue.visible(User.anonymous).all |
| 76 | 95 |
assert issues.empty? |
| 96 |
assert_visibility_match User.anonymous, issues |
|
| 77 | 97 |
end |
| 78 |
|
|
| 79 |
def test_visible_scope_for_user
|
|
| 98 |
|
|
| 99 |
def test_visible_scope_for_non_member
|
|
| 80 | 100 |
user = User.find(9) |
| 81 | 101 |
assert user.projects.empty? |
| 82 | 102 |
# Non member user should see issues of public projects only |
| 83 | 103 |
issues = Issue.visible(user).all |
| 84 | 104 |
assert issues.any? |
| 85 | 105 |
assert_nil issues.detect {|issue| !issue.project.is_public?}
|
| 106 |
assert_nil issues.detect {|issue| issue.is_private?}
|
|
| 107 |
assert_visibility_match user, issues |
|
| 108 |
end |
|
| 109 |
|
|
| 110 |
def test_visible_scope_for_non_member_with_own_issues_visibility |
|
| 111 |
Role.non_member.update_attribute :issues_visibility, 'own' |
|
| 112 |
Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') |
|
| 113 |
user = User.find(9) |
|
| 114 |
|
|
| 115 |
issues = Issue.visible(user).all |
|
| 116 |
assert issues.any? |
|
| 117 |
assert_nil issues.detect {|issue| issue.author != user}
|
|
| 118 |
assert_visibility_match user, issues |
|
| 119 |
end |
|
| 120 |
|
|
| 121 |
def test_visible_scope_for_non_member_without_view_issues_permissions |
|
| 86 | 122 |
# Non member user should not see issues without permission |
| 87 | 123 |
Role.non_member.remove_permission!(:view_issues) |
| 88 |
user.reload |
|
| 124 |
user = User.find(9) |
|
| 125 |
assert user.projects.empty? |
|
| 89 | 126 |
issues = Issue.visible(user).all |
| 90 | 127 |
assert issues.empty? |
| 128 |
assert_visibility_match user, issues |
|
| 129 |
end |
|
| 130 |
|
|
| 131 |
def test_visible_scope_for_member |
|
| 132 |
user = User.find(9) |
|
| 91 | 133 |
# User should see issues of projects for which he has view_issues permissions only |
| 92 |
Member.create!(:principal => user, :project_id => 2, :role_ids => [1])
|
|
| 93 |
user.reload
|
|
| 134 |
Role.non_member.remove_permission!(:view_issues)
|
|
| 135 |
Member.create!(:principal => user, :project_id => 3, :role_ids => [2])
|
|
| 94 | 136 |
issues = Issue.visible(user).all |
| 95 | 137 |
assert issues.any? |
| 96 |
assert_nil issues.detect {|issue| issue.project_id != 2}
|
|
| 138 |
assert_nil issues.detect {|issue| issue.project_id != 3}
|
|
| 139 |
assert_nil issues.detect {|issue| issue.is_private?}
|
|
| 140 |
assert_visibility_match user, issues |
|
| 97 | 141 |
end |
| 98 |
|
|
| 142 |
|
|
| 99 | 143 |
def test_visible_scope_for_admin |
| 100 | 144 |
user = User.find(1) |
| 101 | 145 |
user.members.each(&:destroy) |
| ... | ... | |
| 104 | 148 |
assert issues.any? |
| 105 | 149 |
# Admin should see issues on private projects that he does not belong to |
| 106 | 150 |
assert issues.detect {|issue| !issue.project.is_public?}
|
| 151 |
# Admin should see private issues of other users |
|
| 152 |
assert issues.detect {|issue| issue.is_private? && issue.author != user}
|
|
| 153 |
assert_visibility_match user, issues |
|
| 107 | 154 |
end |
| 108 |
|
|
| 155 |
|
|
| 156 |
def test_visible_scope_with_project |
|
| 157 |
project = Project.find(1) |
|
| 158 |
issues = Issue.visible(User.find(2), :project => project).all |
|
| 159 |
projects = issues.collect(&:project).uniq |
|
| 160 |
assert_equal 1, projects.size |
|
| 161 |
assert_equal project, projects.first |
|
| 162 |
end |
|
| 163 |
|
|
| 164 |
def test_visible_scope_with_project_and_subprojects |
|
| 165 |
project = Project.find(1) |
|
| 166 |
issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all |
|
| 167 |
projects = issues.collect(&:project).uniq |
|
| 168 |
assert projects.size > 1 |
|
| 169 |
assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)}
|
|
| 170 |
end |
|
| 171 |
|
|
| 172 |
def test_visible_and_nested_set_scopes |
|
| 173 |
assert_equal 0, Issue.find(1).descendants.visible.all.size |
|
| 174 |
end |
|
| 175 |
|
|
| 109 | 176 |
def test_errors_full_messages_should_include_custom_fields_errors |
| 110 | 177 |
field = IssueCustomField.find_by_name('Database')
|
| 111 |
|
|
| 178 |
|
|
| 112 | 179 |
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
| 113 | 180 |
assert issue.available_custom_fields.include?(field) |
| 114 | 181 |
# Invalid value |
| 115 | 182 |
issue.custom_field_values = { field.id => 'SQLServer' }
|
| 116 |
|
|
| 183 |
|
|
| 117 | 184 |
assert !issue.valid? |
| 118 | 185 |
assert_equal 1, issue.errors.full_messages.size |
| 119 | 186 |
assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first
|
| 120 | 187 |
end |
| 121 |
|
|
| 188 |
|
|
| 122 | 189 |
def test_update_issue_with_required_custom_field |
| 123 | 190 |
field = IssueCustomField.find_by_name('Database')
|
| 124 | 191 |
field.update_attribute(:is_required, true) |
| 125 |
|
|
| 192 |
|
|
| 126 | 193 |
issue = Issue.find(1) |
| 127 | 194 |
assert_nil issue.custom_value_for(field) |
| 128 | 195 |
assert issue.available_custom_fields.include?(field) |
| ... | ... | |
| 137 | 204 |
issue.reload |
| 138 | 205 |
assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
| 139 | 206 |
end |
| 140 |
|
|
| 207 |
|
|
| 141 | 208 |
def test_should_not_update_attributes_if_custom_fields_validation_fails |
| 142 | 209 |
issue = Issue.find(1) |
| 143 | 210 |
field = IssueCustomField.find_by_name('Database')
|
| 144 | 211 |
assert issue.available_custom_fields.include?(field) |
| 145 |
|
|
| 212 |
|
|
| 146 | 213 |
issue.custom_field_values = { field.id => 'Invalid' }
|
| 147 | 214 |
issue.subject = 'Should be not be saved' |
| 148 | 215 |
assert !issue.save |
| 149 |
|
|
| 216 |
|
|
| 150 | 217 |
issue.reload |
| 151 | 218 |
assert_equal "Can't print recipes", issue.subject |
| 152 | 219 |
end |
| 153 |
|
|
| 220 |
|
|
| 154 | 221 |
def test_should_not_recreate_custom_values_objects_on_update |
| 155 | 222 |
field = IssueCustomField.find_by_name('Database')
|
| 156 |
|
|
| 223 |
|
|
| 157 | 224 |
issue = Issue.find(1) |
| 158 | 225 |
issue.custom_field_values = { field.id => 'PostgreSQL' }
|
| 159 | 226 |
assert issue.save |
| ... | ... | |
| 164 | 231 |
issue.reload |
| 165 | 232 |
assert_equal custom_value.id, issue.custom_value_for(field).id |
| 166 | 233 |
end |
| 167 |
|
|
| 234 |
|
|
| 168 | 235 |
def test_assigning_tracker_id_should_reload_custom_fields_values |
| 169 | 236 |
issue = Issue.new(:project => Project.find(1)) |
| 170 | 237 |
assert issue.custom_field_values.empty? |
| 171 | 238 |
issue.tracker_id = 1 |
| 172 | 239 |
assert issue.custom_field_values.any? |
| 173 | 240 |
end |
| 174 |
|
|
| 241 |
|
|
| 175 | 242 |
def test_assigning_attributes_should_assign_tracker_id_first |
| 176 | 243 |
attributes = ActiveSupport::OrderedHash.new |
| 177 | 244 |
attributes['custom_field_values'] = { '1' => 'MySQL' }
|
| ... | ... | |
| 181 | 248 |
assert_not_nil issue.custom_value_for(1) |
| 182 | 249 |
assert_equal 'MySQL', issue.custom_value_for(1).value |
| 183 | 250 |
end |
| 184 |
|
|
| 251 |
|
|
| 185 | 252 |
def test_should_update_issue_with_disabled_tracker |
| 186 | 253 |
p = Project.find(1) |
| 187 | 254 |
issue = Issue.find(1) |
| 188 |
|
|
| 255 |
|
|
| 189 | 256 |
p.trackers.delete(issue.tracker) |
| 190 | 257 |
assert !p.trackers.include?(issue.tracker) |
| 191 |
|
|
| 258 |
|
|
| 192 | 259 |
issue.reload |
| 193 | 260 |
issue.subject = 'New subject' |
| 194 | 261 |
assert issue.save |
| 195 | 262 |
end |
| 196 |
|
|
| 263 |
|
|
| 197 | 264 |
def test_should_not_set_a_disabled_tracker |
| 198 | 265 |
p = Project.find(1) |
| 199 | 266 |
p.trackers.delete(Tracker.find(2)) |
| 200 |
|
|
| 267 |
|
|
| 201 | 268 |
issue = Issue.find(1) |
| 202 | 269 |
issue.tracker_id = 2 |
| 203 | 270 |
issue.subject = 'New subject' |
| 204 | 271 |
assert !issue.save |
| 205 | 272 |
assert_not_nil issue.errors.on(:tracker_id) |
| 206 | 273 |
end |
| 207 |
|
|
| 274 |
|
|
| 208 | 275 |
def test_category_based_assignment |
Also available in: Unified diff