Added branch for hooks integration.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1716 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class ActivityTest < Test::Unit::TestCase
|
||||
fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
|
||||
:trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
end
|
||||
|
||||
def test_activity_without_subprojects
|
||||
events = find_events(User.anonymous, :project => @project)
|
||||
assert_not_nil events
|
||||
|
||||
assert events.include?(Issue.find(1))
|
||||
assert !events.include?(Issue.find(4))
|
||||
# subproject issue
|
||||
assert !events.include?(Issue.find(5))
|
||||
end
|
||||
|
||||
def test_activity_with_subprojects
|
||||
events = find_events(User.anonymous, :project => @project, :with_subprojects => 1)
|
||||
assert_not_nil events
|
||||
|
||||
assert events.include?(Issue.find(1))
|
||||
# subproject issue
|
||||
assert events.include?(Issue.find(5))
|
||||
end
|
||||
|
||||
def test_global_activity_anonymous
|
||||
events = find_events(User.anonymous)
|
||||
assert_not_nil events
|
||||
|
||||
assert events.include?(Issue.find(1))
|
||||
assert events.include?(Message.find(5))
|
||||
# Issue of a private project
|
||||
assert !events.include?(Issue.find(4))
|
||||
end
|
||||
|
||||
def test_global_activity_logged_user
|
||||
events = find_events(User.find(2)) # manager
|
||||
assert_not_nil events
|
||||
|
||||
assert events.include?(Issue.find(1))
|
||||
# Issue of a private project the user belongs to
|
||||
assert events.include?(Issue.find(4))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_events(user, options={})
|
||||
Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class AttachmentTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_diskfilename
|
||||
assert Attachment.disk_filename("test_file.txt") =~ /^\d{12}_test_file.txt$/
|
||||
assert_equal 'test_file.txt', Attachment.disk_filename("test_file.txt")[13..-1]
|
||||
assert_equal '770c509475505f37c2b8fb6030434d6b.txt', Attachment.disk_filename("test_accentué.txt")[13..-1]
|
||||
assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
|
||||
assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class BoardTest < Test::Unit::TestCase
|
||||
fixtures :projects, :boards, :messages
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
end
|
||||
|
||||
def test_create
|
||||
board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description')
|
||||
assert board.save
|
||||
board.reload
|
||||
assert_equal 'Test board', board.name
|
||||
assert_equal 'Test board description', board.description
|
||||
assert_equal @project, board.project
|
||||
assert_equal 0, board.topics_count
|
||||
assert_equal 0, board.messages_count
|
||||
assert_nil board.last_message
|
||||
# last position
|
||||
assert_equal @project.boards.size, board.position
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
board = Board.find(1)
|
||||
assert board.destroy
|
||||
# make sure that the associated messages are removed
|
||||
assert_equal 0, Message.count(:conditions => {:board_id => 1})
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class CalendarTest < Test::Unit::TestCase
|
||||
|
||||
def test_monthly
|
||||
c = Redmine::Helpers::Calendar.new(Date.today, :fr, :month)
|
||||
assert_equal [1, 7], [c.startdt.cwday, c.enddt.cwday]
|
||||
|
||||
c = Redmine::Helpers::Calendar.new('2007-07-14'.to_date, :fr, :month)
|
||||
assert_equal ['2007-06-25'.to_date, '2007-08-05'.to_date], [c.startdt, c.enddt]
|
||||
|
||||
c = Redmine::Helpers::Calendar.new(Date.today, :en, :month)
|
||||
assert_equal [7, 6], [c.startdt.cwday, c.enddt.cwday]
|
||||
end
|
||||
|
||||
def test_weekly
|
||||
c = Redmine::Helpers::Calendar.new(Date.today, :fr, :week)
|
||||
assert_equal [1, 7], [c.startdt.cwday, c.enddt.cwday]
|
||||
|
||||
c = Redmine::Helpers::Calendar.new('2007-07-14'.to_date, :fr, :week)
|
||||
assert_equal ['2007-07-09'.to_date, '2007-07-15'.to_date], [c.startdt, c.enddt]
|
||||
|
||||
c = Redmine::Helpers::Calendar.new(Date.today, :en, :week)
|
||||
assert_equal [7, 6], [c.startdt.cwday, c.enddt.cwday]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class ChangesetTest < Test::Unit::TestCase
|
||||
fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :trackers
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_ref_keywords_any
|
||||
Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
|
||||
Setting.commit_fix_done_ratio = '90'
|
||||
Setting.commit_ref_keywords = '*'
|
||||
Setting.commit_fix_keywords = 'fixes , closes'
|
||||
|
||||
c = Changeset.new(:repository => Project.find(1).repository,
|
||||
:committed_on => Time.now,
|
||||
:comments => 'New commit (#2). Fixes #1')
|
||||
c.scan_comment_for_issue_ids
|
||||
|
||||
assert_equal [1, 2], c.issue_ids.sort
|
||||
fixed = Issue.find(1)
|
||||
assert fixed.closed?
|
||||
assert_equal 90, fixed.done_ratio
|
||||
end
|
||||
|
||||
def test_ref_keywords_any_line_start
|
||||
Setting.commit_ref_keywords = '*'
|
||||
|
||||
c = Changeset.new(:repository => Project.find(1).repository,
|
||||
:committed_on => Time.now,
|
||||
:comments => '#1 is the reason of this commit')
|
||||
c.scan_comment_for_issue_ids
|
||||
|
||||
assert_equal [1], c.issue_ids.sort
|
||||
end
|
||||
|
||||
def test_previous
|
||||
changeset = Changeset.find_by_revision('3')
|
||||
assert_equal Changeset.find_by_revision('2'), changeset.previous
|
||||
end
|
||||
|
||||
def test_previous_nil
|
||||
changeset = Changeset.find_by_revision('1')
|
||||
assert_nil changeset.previous
|
||||
end
|
||||
|
||||
def test_next
|
||||
changeset = Changeset.find_by_revision('2')
|
||||
assert_equal Changeset.find_by_revision('3'), changeset.next
|
||||
end
|
||||
|
||||
def test_next_nil
|
||||
changeset = Changeset.find_by_revision('4')
|
||||
assert_nil changeset.next
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class CommentTest < Test::Unit::TestCase
|
||||
fixtures :users, :news, :comments
|
||||
|
||||
def setup
|
||||
@jsmith = User.find(2)
|
||||
@news = News.find(1)
|
||||
end
|
||||
|
||||
def test_create
|
||||
comment = Comment.new(:commented => @news, :author => @jsmith, :comments => "my comment")
|
||||
assert comment.save
|
||||
@news.reload
|
||||
assert_equal 2, @news.comments_count
|
||||
end
|
||||
|
||||
def test_validate
|
||||
comment = Comment.new(:commented => @news)
|
||||
assert !comment.save
|
||||
assert_equal 2, comment.errors.length
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
comment = Comment.find(1)
|
||||
assert comment.destroy
|
||||
@news.reload
|
||||
assert_equal 0, @news.comments_count
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class CustomFieldTest < Test::Unit::TestCase
|
||||
fixtures :custom_fields
|
||||
|
||||
def test_create
|
||||
field = UserCustomField.new(:name => 'Money money money', :field_format => 'float')
|
||||
assert field.save
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
field = CustomField.find(1)
|
||||
assert field.destroy
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,117 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class CustomValueTest < Test::Unit::TestCase
|
||||
fixtures :custom_fields
|
||||
|
||||
def test_string_field_validation_with_blank_value
|
||||
f = CustomField.new(:field_format => 'string')
|
||||
v = CustomValue.new(:custom_field => f)
|
||||
|
||||
v.value = nil
|
||||
assert v.valid?
|
||||
v.value = ''
|
||||
assert v.valid?
|
||||
|
||||
f.is_required = true
|
||||
v.value = nil
|
||||
assert !v.valid?
|
||||
v.value = ''
|
||||
assert !v.valid?
|
||||
end
|
||||
|
||||
def test_string_field_validation_with_min_and_max_lengths
|
||||
f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
|
||||
v = CustomValue.new(:custom_field => f, :value => '')
|
||||
assert v.valid?
|
||||
v.value = 'a'
|
||||
assert !v.valid?
|
||||
v.value = 'a' * 2
|
||||
assert v.valid?
|
||||
v.value = 'a' * 6
|
||||
assert !v.valid?
|
||||
end
|
||||
|
||||
def test_string_field_validation_with_regexp
|
||||
f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
|
||||
v = CustomValue.new(:custom_field => f, :value => '')
|
||||
assert v.valid?
|
||||
v.value = 'abc'
|
||||
assert !v.valid?
|
||||
v.value = 'ABC'
|
||||
assert v.valid?
|
||||
end
|
||||
|
||||
def test_date_field_validation
|
||||
f = CustomField.new(:field_format => 'date')
|
||||
v = CustomValue.new(:custom_field => f, :value => '')
|
||||
assert v.valid?
|
||||
v.value = 'abc'
|
||||
assert !v.valid?
|
||||
v.value = '1975-07-14'
|
||||
assert v.valid?
|
||||
end
|
||||
|
||||
def test_list_field_validation
|
||||
f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
|
||||
v = CustomValue.new(:custom_field => f, :value => '')
|
||||
assert v.valid?
|
||||
v.value = 'abc'
|
||||
assert !v.valid?
|
||||
v.value = 'value2'
|
||||
assert v.valid?
|
||||
end
|
||||
|
||||
def test_int_field_validation
|
||||
f = CustomField.new(:field_format => 'int')
|
||||
v = CustomValue.new(:custom_field => f, :value => '')
|
||||
assert v.valid?
|
||||
v.value = 'abc'
|
||||
assert !v.valid?
|
||||
v.value = '123'
|
||||
assert v.valid?
|
||||
v.value = '+123'
|
||||
assert v.valid?
|
||||
v.value = '-123'
|
||||
assert v.valid?
|
||||
end
|
||||
|
||||
def test_float_field_validation
|
||||
v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money'))
|
||||
v.value = '11.2'
|
||||
assert v.save
|
||||
v.value = ''
|
||||
assert v.save
|
||||
v.value = '-6.250'
|
||||
assert v.save
|
||||
v.value = '6a'
|
||||
assert !v.save
|
||||
end
|
||||
|
||||
def test_default_value
|
||||
field = CustomField.find_by_default_value('Default string')
|
||||
assert_not_nil field
|
||||
|
||||
v = CustomValue.new(:custom_field => field)
|
||||
assert_equal 'Default string', v.value
|
||||
|
||||
v = CustomValue.new(:custom_field => field, :value => 'Not empty')
|
||||
assert_equal 'Not empty', v.value
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class DefaultDataTest < Test::Unit::TestCase
|
||||
fixtures :roles
|
||||
|
||||
def test_no_data
|
||||
assert !Redmine::DefaultData::Loader::no_data?
|
||||
Role.delete_all("builtin = 0")
|
||||
Tracker.delete_all
|
||||
IssueStatus.delete_all
|
||||
Enumeration.delete_all
|
||||
assert Redmine::DefaultData::Loader::no_data?
|
||||
end
|
||||
|
||||
def test_load
|
||||
GLoc.valid_languages.each do |lang|
|
||||
begin
|
||||
Role.delete_all("builtin = 0")
|
||||
Tracker.delete_all
|
||||
IssueStatus.delete_all
|
||||
Enumeration.delete_all
|
||||
assert Redmine::DefaultData::Loader::load(lang)
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
assert false, ":#{lang} default data is invalid (#{e.message})."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class EnumerationTest < Test::Unit::TestCase
|
||||
fixtures :enumerations, :issues
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_objects_count
|
||||
# low priority
|
||||
assert_equal 5, Enumeration.find(4).objects_count
|
||||
# urgent
|
||||
assert_equal 0, Enumeration.find(7).objects_count
|
||||
end
|
||||
|
||||
def test_in_use
|
||||
# low priority
|
||||
assert Enumeration.find(4).in_use?
|
||||
# urgent
|
||||
assert !Enumeration.find(7).in_use?
|
||||
end
|
||||
|
||||
def test_destroy_with_reassign
|
||||
Enumeration.find(4).destroy(Enumeration.find(6))
|
||||
assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
|
||||
assert_equal 5, Enumeration.find(6).objects_count
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
|
||||
class FilesystemAdapterTest < Test::Unit::TestCase
|
||||
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository'
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def setup
|
||||
@adapter = Redmine::Scm::Adapters::FilesystemAdapter.new(REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
def test_entries
|
||||
assert_equal 2, @adapter.entries.size
|
||||
assert_equal ["dir", "test"], @adapter.entries.collect(&:name)
|
||||
assert_equal ["dir", "test"], @adapter.entries(nil).collect(&:name)
|
||||
assert_equal ["dir", "test"], @adapter.entries("/").collect(&:name)
|
||||
["dir", "/dir", "/dir/", "dir/"].each do |path|
|
||||
assert_equal ["subdir", "dirfile"], @adapter.entries(path).collect(&:name)
|
||||
end
|
||||
# If y try to use "..", the path is ignored
|
||||
["/../","dir/../", "..", "../", "/..", "dir/.."].each do |path|
|
||||
assert_equal ["dir", "test"], @adapter.entries(path).collect(&:name), ".. must be ignored in path argument"
|
||||
end
|
||||
end
|
||||
|
||||
def test_cat
|
||||
assert_equal "TEST CAT\n", @adapter.cat("test")
|
||||
assert_equal "TEST CAT\n", @adapter.cat("/test")
|
||||
# Revision number is ignored
|
||||
assert_equal "TEST CAT\n", @adapter.cat("/test", 1)
|
||||
end
|
||||
|
||||
else
|
||||
puts "Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS."
|
||||
def test_fake; assert true end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,345 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
|
||||
class ApplicationHelperTest < HelperTestCase
|
||||
include ApplicationHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules
|
||||
|
||||
def setup
|
||||
super
|
||||
end
|
||||
|
||||
def test_auto_links
|
||||
to_test = {
|
||||
'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
|
||||
'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
|
||||
'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
|
||||
'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
|
||||
'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
|
||||
'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
|
||||
'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
|
||||
'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&t=z&s=">http://foo.bar/page?p=1&t=z&s=</a>',
|
||||
'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
|
||||
'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
|
||||
'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
|
||||
}
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_auto_mailto
|
||||
assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
|
||||
textilizable('test@foo.bar')
|
||||
end
|
||||
|
||||
def test_inline_images
|
||||
to_test = {
|
||||
'!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
|
||||
'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
|
||||
'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
|
||||
'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />',
|
||||
}
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_textile_external_links
|
||||
to_test = {
|
||||
'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
|
||||
'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
|
||||
'"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
|
||||
"This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
|
||||
# no multiline link text
|
||||
"This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />\nand another on a second line\":test"
|
||||
}
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_redmine_links
|
||||
issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
|
||||
:class => 'issue', :title => 'Error 281 when updating a recipe (New)')
|
||||
|
||||
changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
|
||||
:class => 'changeset', :title => 'My very first commit')
|
||||
|
||||
document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
|
||||
:class => 'document')
|
||||
|
||||
version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
|
||||
:class => 'version')
|
||||
|
||||
source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
|
||||
source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
|
||||
|
||||
to_test = {
|
||||
# tickets
|
||||
'#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
|
||||
# changesets
|
||||
'r1' => changeset_link,
|
||||
# documents
|
||||
'document#1' => document_link,
|
||||
'document:"Test document"' => document_link,
|
||||
# versions
|
||||
'version#2' => version_link,
|
||||
'version:1.0' => version_link,
|
||||
'version:"1.0"' => version_link,
|
||||
# source
|
||||
'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
|
||||
'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
|
||||
'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
|
||||
'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
|
||||
'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
|
||||
'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
|
||||
'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
|
||||
'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
|
||||
'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
|
||||
'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
|
||||
'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
|
||||
'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
|
||||
# escaping
|
||||
'!#3.' => '#3.',
|
||||
'!r1' => 'r1',
|
||||
'!document#1' => 'document#1',
|
||||
'!document:"Test document"' => 'document:"Test document"',
|
||||
'!version#2' => 'version#2',
|
||||
'!version:1.0' => 'version:1.0',
|
||||
'!version:"1.0"' => 'version:"1.0"',
|
||||
'!source:/some/file' => 'source:/some/file',
|
||||
# invalid expressions
|
||||
'source:' => 'source:',
|
||||
# url hash
|
||||
"http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
|
||||
}
|
||||
@project = Project.find(1)
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_wiki_links
|
||||
to_test = {
|
||||
'[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
||||
'[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>',
|
||||
# link with anchor
|
||||
'[[CookBook documentation#One-section]]' => '<a href="/wiki/ecookbook/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
|
||||
'[[Another page#anchor|Page]]' => '<a href="/wiki/ecookbook/Another_page#anchor" class="wiki-page">Page</a>',
|
||||
# page that doesn't exist
|
||||
'[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>',
|
||||
'[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>',
|
||||
# link to another project wiki
|
||||
'[[onlinestore:]]' => '<a href="/wiki/onlinestore/" class="wiki-page">onlinestore</a>',
|
||||
'[[onlinestore:|Wiki]]' => '<a href="/wiki/onlinestore/" class="wiki-page">Wiki</a>',
|
||||
'[[onlinestore:Start page]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Start page</a>',
|
||||
'[[onlinestore:Start page|Text]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Text</a>',
|
||||
'[[onlinestore:Unknown page]]' => '<a href="/wiki/onlinestore/Unknown_page" class="wiki-page new">Unknown page</a>',
|
||||
# striked through link
|
||||
'-[[Another page|Page]]-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a></del>',
|
||||
# escaping
|
||||
'![[Another page|Page]]' => '[[Another page|Page]]',
|
||||
}
|
||||
@project = Project.find(1)
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_html_tags
|
||||
to_test = {
|
||||
"<div>content</div>" => "<p><div>content</div></p>",
|
||||
"<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>",
|
||||
"<script>some script;</script>" => "<p><script>some script;</script></p>",
|
||||
# do not escape pre/code tags
|
||||
"<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
|
||||
"<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
|
||||
"<pre><div>content</div></pre>" => "<pre><div>content</div></pre>",
|
||||
"HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>",
|
||||
"<!-- opening comment" => "<p><!-- opening comment</p>"
|
||||
}
|
||||
to_test.each { |text, result| assert_equal result, textilizable(text) }
|
||||
end
|
||||
|
||||
def test_allowed_html_tags
|
||||
to_test = {
|
||||
"<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
|
||||
"<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
|
||||
}
|
||||
to_test.each { |text, result| assert_equal result, textilizable(text) }
|
||||
end
|
||||
|
||||
def test_wiki_links_in_tables
|
||||
to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
|
||||
'<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' +
|
||||
'<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' +
|
||||
'</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>'
|
||||
}
|
||||
@project = Project.find(1)
|
||||
to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
|
||||
end
|
||||
|
||||
def test_text_formatting
|
||||
to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
|
||||
'(_text within parentheses_)' => '(<em>text within parentheses</em>)'
|
||||
}
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_wiki_horizontal_rule
|
||||
assert_equal '<hr />', textilizable('---')
|
||||
assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
|
||||
end
|
||||
|
||||
def test_table_of_content
|
||||
raw = <<-RAW
|
||||
{{toc}}
|
||||
|
||||
h1. Title
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
|
||||
|
||||
h2. Subtitle
|
||||
|
||||
Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
|
||||
|
||||
h2. Subtitle with %{color:red}red text%
|
||||
|
||||
h1. Another title
|
||||
|
||||
RAW
|
||||
|
||||
expected = '<ul class="toc">' +
|
||||
'<li class="heading1"><a href="#Title">Title</a></li>' +
|
||||
'<li class="heading2"><a href="#Subtitle">Subtitle</a></li>' +
|
||||
'<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
|
||||
'<li class="heading1"><a href="#Another-title">Another title</a></li>' +
|
||||
'</ul>'
|
||||
|
||||
assert textilizable(raw).gsub("\n", "").include?(expected)
|
||||
end
|
||||
|
||||
def test_blockquote
|
||||
# orig raw text
|
||||
raw = <<-RAW
|
||||
John said:
|
||||
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
|
||||
> Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
|
||||
> * Donec odio lorem,
|
||||
> * sagittis ac,
|
||||
> * malesuada in,
|
||||
> * adipiscing eu, dolor.
|
||||
>
|
||||
> >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
|
||||
> Proin a tellus. Nam vel neque.
|
||||
|
||||
He's right.
|
||||
RAW
|
||||
|
||||
# expected html
|
||||
expected = <<-EXPECTED
|
||||
<p>John said:</p>
|
||||
<blockquote>
|
||||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
|
||||
Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
|
||||
<ul>
|
||||
<li>Donec odio lorem,</li>
|
||||
<li>sagittis ac,</li>
|
||||
<li>malesuada in,</li>
|
||||
<li>adipiscing eu, dolor.</li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
|
||||
</blockquote>
|
||||
<p>Proin a tellus. Nam vel neque.</p>
|
||||
</blockquote>
|
||||
<p>He's right.</p>
|
||||
EXPECTED
|
||||
|
||||
assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
|
||||
end
|
||||
|
||||
def test_table
|
||||
raw = <<-RAW
|
||||
This is a table with empty cells:
|
||||
|
||||
|cell11|cell12||
|
||||
|cell21||cell23|
|
||||
|cell31|cell32|cell33|
|
||||
RAW
|
||||
|
||||
expected = <<-EXPECTED
|
||||
<p>This is a table with empty cells:</p>
|
||||
|
||||
<table>
|
||||
<tr><td>cell11</td><td>cell12</td><td></td></tr>
|
||||
<tr><td>cell21</td><td></td><td>cell23</td></tr>
|
||||
<tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
|
||||
</table>
|
||||
EXPECTED
|
||||
|
||||
assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
|
||||
end
|
||||
|
||||
def test_macro_hello_world
|
||||
text = "{{hello_world}}"
|
||||
assert textilizable(text).match(/Hello world!/)
|
||||
# escaping
|
||||
text = "!{{hello_world}}"
|
||||
assert_equal '<p>{{hello_world}}</p>', textilizable(text)
|
||||
end
|
||||
|
||||
def test_macro_include
|
||||
@project = Project.find(1)
|
||||
# include a page of the current project wiki
|
||||
text = "{{include(Another page)}}"
|
||||
assert textilizable(text).match(/This is a link to a ticket/)
|
||||
|
||||
@project = nil
|
||||
# include a page of a specific project wiki
|
||||
text = "{{include(ecookbook:Another page)}}"
|
||||
assert textilizable(text).match(/This is a link to a ticket/)
|
||||
|
||||
text = "{{include(ecookbook:)}}"
|
||||
assert textilizable(text).match(/CookBook documentation/)
|
||||
|
||||
text = "{{include(unknowidentifier:somepage)}}"
|
||||
assert textilizable(text).match(/Unknow project/)
|
||||
end
|
||||
|
||||
def test_date_format_default
|
||||
today = Date.today
|
||||
Setting.date_format = ''
|
||||
assert_equal l_date(today), format_date(today)
|
||||
end
|
||||
|
||||
def test_date_format
|
||||
today = Date.today
|
||||
Setting.date_format = '%d %m %Y'
|
||||
assert_equal today.strftime('%d %m %Y'), format_date(today)
|
||||
end
|
||||
|
||||
def test_time_format_default
|
||||
now = Time.now
|
||||
Setting.date_format = ''
|
||||
Setting.time_format = ''
|
||||
assert_equal l_datetime(now), format_time(now)
|
||||
assert_equal l_time(now), format_time(now, false)
|
||||
end
|
||||
|
||||
def test_time_format
|
||||
now = Time.now
|
||||
Setting.date_format = '%d %m %Y'
|
||||
Setting.time_format = '%H %M'
|
||||
assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
|
||||
assert_equal now.strftime('%H %M'), format_time(now, false)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
|
||||
class ProjectsHelperTest < HelperTestCase
|
||||
include ProjectsHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
fixtures :projects, :trackers, :issue_statuses, :issues, :enumerations, :users, :issue_categories
|
||||
|
||||
def setup
|
||||
super
|
||||
end
|
||||
|
||||
if Object.const_defined?(:Magick)
|
||||
def test_gantt_image
|
||||
assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 6, 2)
|
||||
end
|
||||
|
||||
def test_gantt_image_with_days
|
||||
assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 3, 4)
|
||||
end
|
||||
else
|
||||
puts "RMagick not installed. Skipping tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class IssueCategoryTest < Test::Unit::TestCase
|
||||
fixtures :issue_categories, :issues
|
||||
|
||||
def setup
|
||||
@category = IssueCategory.find(1)
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
issue = @category.issues.first
|
||||
@category.destroy
|
||||
# Make sure the category was nullified on the issue
|
||||
assert_nil issue.reload.category
|
||||
end
|
||||
|
||||
def test_destroy_with_reassign
|
||||
issue = @category.issues.first
|
||||
reassign_to = IssueCategory.find(2)
|
||||
@category.destroy(reassign_to)
|
||||
# Make sure the issue was reassigned
|
||||
assert_equal reassign_to, issue.reload.category
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,49 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class IssueStatusTest < Test::Unit::TestCase
|
||||
fixtures :issue_statuses
|
||||
|
||||
def test_create
|
||||
status = IssueStatus.new :name => "Assigned"
|
||||
assert !status.save
|
||||
# status name uniqueness
|
||||
assert_equal 1, status.errors.count
|
||||
|
||||
status.name = "Test Status"
|
||||
assert status.save
|
||||
assert !status.is_default
|
||||
end
|
||||
|
||||
def test_default
|
||||
status = IssueStatus.default
|
||||
assert_kind_of IssueStatus, status
|
||||
end
|
||||
|
||||
def test_change_default
|
||||
status = IssueStatus.find(2)
|
||||
assert !status.is_default
|
||||
status.is_default = true
|
||||
assert status.save
|
||||
status.reload
|
||||
|
||||
assert_equal status, IssueStatus.default
|
||||
assert !IssueStatus.find(1).is_default
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,193 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class IssueTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :members,
|
||||
:trackers, :projects_trackers,
|
||||
:issue_statuses, :issue_categories,
|
||||
:enumerations,
|
||||
:issues,
|
||||
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
|
||||
:time_entries
|
||||
|
||||
def test_create
|
||||
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30')
|
||||
assert issue.save
|
||||
issue.reload
|
||||
assert_equal 1.5, issue.estimated_hours
|
||||
end
|
||||
|
||||
def test_create_with_required_custom_field
|
||||
field = IssueCustomField.find_by_name('Database')
|
||||
field.update_attribute(:is_required, true)
|
||||
|
||||
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')
|
||||
assert issue.available_custom_fields.include?(field)
|
||||
# No value for the custom field
|
||||
assert !issue.save
|
||||
assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
|
||||
# Blank value
|
||||
issue.custom_field_values = { field.id => '' }
|
||||
assert !issue.save
|
||||
assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
|
||||
# Invalid value
|
||||
issue.custom_field_values = { field.id => 'SQLServer' }
|
||||
assert !issue.save
|
||||
assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
|
||||
# Valid value
|
||||
issue.custom_field_values = { field.id => 'PostgreSQL' }
|
||||
assert issue.save
|
||||
issue.reload
|
||||
assert_equal 'PostgreSQL', issue.custom_value_for(field).value
|
||||
end
|
||||
|
||||
def test_update_issue_with_required_custom_field
|
||||
field = IssueCustomField.find_by_name('Database')
|
||||
field.update_attribute(:is_required, true)
|
||||
|
||||
issue = Issue.find(1)
|
||||
assert_nil issue.custom_value_for(field)
|
||||
assert issue.available_custom_fields.include?(field)
|
||||
# No change to custom values, issue can be saved
|
||||
assert issue.save
|
||||
# Blank value
|
||||
issue.custom_field_values = { field.id => '' }
|
||||
assert !issue.save
|
||||
# Valid value
|
||||
issue.custom_field_values = { field.id => 'PostgreSQL' }
|
||||
assert issue.save
|
||||
issue.reload
|
||||
assert_equal 'PostgreSQL', issue.custom_value_for(field).value
|
||||
end
|
||||
|
||||
def test_should_not_update_attributes_if_custom_fields_validation_fails
|
||||
issue = Issue.find(1)
|
||||
field = IssueCustomField.find_by_name('Database')
|
||||
assert issue.available_custom_fields.include?(field)
|
||||
|
||||
issue.custom_field_values = { field.id => 'Invalid' }
|
||||
issue.subject = 'Should be not be saved'
|
||||
assert !issue.save
|
||||
|
||||
issue.reload
|
||||
assert_equal "Can't print recipes", issue.subject
|
||||
end
|
||||
|
||||
def test_should_not_recreate_custom_values_objects_on_update
|
||||
field = IssueCustomField.find_by_name('Database')
|
||||
|
||||
issue = Issue.find(1)
|
||||
issue.custom_field_values = { field.id => 'PostgreSQL' }
|
||||
assert issue.save
|
||||
custom_value = issue.custom_value_for(field)
|
||||
issue.reload
|
||||
issue.custom_field_values = { field.id => 'MySQL' }
|
||||
assert issue.save
|
||||
issue.reload
|
||||
assert_equal custom_value.id, issue.custom_value_for(field).id
|
||||
end
|
||||
|
||||
def test_category_based_assignment
|
||||
issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
|
||||
assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
|
||||
end
|
||||
|
||||
def test_copy
|
||||
issue = Issue.new.copy_from(1)
|
||||
assert issue.save
|
||||
issue.reload
|
||||
orig = Issue.find(1)
|
||||
assert_equal orig.subject, issue.subject
|
||||
assert_equal orig.tracker, issue.tracker
|
||||
assert_equal orig.custom_values.first.value, issue.custom_values.first.value
|
||||
end
|
||||
|
||||
def test_should_close_duplicates
|
||||
# Create 3 issues
|
||||
issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test')
|
||||
assert issue1.save
|
||||
issue2 = issue1.clone
|
||||
assert issue2.save
|
||||
issue3 = issue1.clone
|
||||
assert issue3.save
|
||||
|
||||
# 2 is a dupe of 1
|
||||
IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
|
||||
# And 3 is a dupe of 2
|
||||
IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
|
||||
# And 3 is a dupe of 1 (circular duplicates)
|
||||
IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
|
||||
|
||||
assert issue1.reload.duplicates.include?(issue2)
|
||||
|
||||
# Closing issue 1
|
||||
issue1.init_journal(User.find(:first), "Closing issue1")
|
||||
issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
|
||||
assert issue1.save
|
||||
# 2 and 3 should be also closed
|
||||
assert issue2.reload.closed?
|
||||
assert issue3.reload.closed?
|
||||
end
|
||||
|
||||
def test_should_not_close_duplicated_issue
|
||||
# Create 3 issues
|
||||
issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test')
|
||||
assert issue1.save
|
||||
issue2 = issue1.clone
|
||||
assert issue2.save
|
||||
|
||||
# 2 is a dupe of 1
|
||||
IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
|
||||
# 2 is a dup of 1 but 1 is not a duplicate of 2
|
||||
assert !issue2.reload.duplicates.include?(issue1)
|
||||
|
||||
# Closing issue 2
|
||||
issue2.init_journal(User.find(:first), "Closing issue2")
|
||||
issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true}
|
||||
assert issue2.save
|
||||
# 1 should not be also closed
|
||||
assert !issue1.reload.closed?
|
||||
end
|
||||
|
||||
def test_move_to_another_project_with_same_category
|
||||
issue = Issue.find(1)
|
||||
assert issue.move_to(Project.find(2))
|
||||
issue.reload
|
||||
assert_equal 2, issue.project_id
|
||||
# Category changes
|
||||
assert_equal 4, issue.category_id
|
||||
# Make sure time entries were move to the target project
|
||||
assert_equal 2, issue.time_entries.first.project_id
|
||||
end
|
||||
|
||||
def test_move_to_another_project_without_same_category
|
||||
issue = Issue.find(2)
|
||||
assert issue.move_to(Project.find(2))
|
||||
issue.reload
|
||||
assert_equal 2, issue.project_id
|
||||
# Category cleared
|
||||
assert_nil issue.category_id
|
||||
end
|
||||
|
||||
def test_issue_destroy
|
||||
Issue.find(1).destroy
|
||||
assert_nil Issue.find_by_id(1)
|
||||
assert_nil TimeEntry.find_by_issue_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,39 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class JournalTest < Test::Unit::TestCase
|
||||
fixtures :issues, :issue_statuses, :journals, :journal_details
|
||||
|
||||
def setup
|
||||
@journal = Journal.find 1
|
||||
end
|
||||
|
||||
def test_journalized_is_an_issue
|
||||
issue = @journal.issue
|
||||
assert_kind_of Issue, issue
|
||||
assert_equal 1, issue.id
|
||||
end
|
||||
|
||||
def test_new_status
|
||||
status = @journal.new_status
|
||||
assert_not_nil status
|
||||
assert_kind_of IssueStatus, status
|
||||
assert_equal 2, status.id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,107 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class MailHandlerTest < Test::Unit::TestCase
|
||||
fixtures :users, :projects,
|
||||
:enabled_modules,
|
||||
:roles,
|
||||
:members,
|
||||
:issues,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:enumerations,
|
||||
:issue_categories
|
||||
|
||||
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
|
||||
|
||||
def setup
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
def test_add_issue
|
||||
# This email contains: 'Project: onlinestore'
|
||||
issue = submit_email('ticket_on_given_project.eml')
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert_equal 'New ticket on a given project', issue.subject
|
||||
assert_equal User.find_by_login('jsmith'), issue.author
|
||||
assert_equal Project.find(2), issue.project
|
||||
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
||||
end
|
||||
|
||||
def test_add_issue_with_attributes_override
|
||||
issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert_equal 'New ticket on a given project', issue.subject
|
||||
assert_equal User.find_by_login('jsmith'), issue.author
|
||||
assert_equal Project.find(2), issue.project
|
||||
assert_equal 'Feature request', issue.tracker.to_s
|
||||
assert_equal 'Stock management', issue.category.to_s
|
||||
assert_equal 'Urgent', issue.priority.to_s
|
||||
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
||||
end
|
||||
|
||||
def test_add_issue_with_partial_attributes_override
|
||||
issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker'])
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert_equal 'New ticket on a given project', issue.subject
|
||||
assert_equal User.find_by_login('jsmith'), issue.author
|
||||
assert_equal Project.find(2), issue.project
|
||||
assert_equal 'Feature request', issue.tracker.to_s
|
||||
assert_nil issue.category
|
||||
assert_equal 'High', issue.priority.to_s
|
||||
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
||||
end
|
||||
|
||||
def test_add_issue_with_attachment_to_specific_project
|
||||
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert_equal 'Ticket created by email with attachment', issue.subject
|
||||
assert_equal User.find_by_login('jsmith'), issue.author
|
||||
assert_equal Project.find(2), issue.project
|
||||
assert_equal 'This is a new ticket with attachments', issue.description
|
||||
# Attachment properties
|
||||
assert_equal 1, issue.attachments.size
|
||||
assert_equal 'Paella.jpg', issue.attachments.first.filename
|
||||
assert_equal 'image/jpeg', issue.attachments.first.content_type
|
||||
assert_equal 10790, issue.attachments.first.filesize
|
||||
end
|
||||
|
||||
def test_add_issue_note
|
||||
journal = submit_email('ticket_reply.eml')
|
||||
assert journal.is_a?(Journal)
|
||||
assert_equal User.find_by_login('jsmith'), journal.user
|
||||
assert_equal Issue.find(2), journal.journalized
|
||||
assert_equal 'This is reply', journal.notes
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def submit_email(filename, options={})
|
||||
raw = IO.read(File.join(FIXTURES_PATH, filename))
|
||||
MailHandler.receive(raw, options)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,128 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class MailerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations
|
||||
|
||||
def test_generated_links_in_emails
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Setting.host_name = 'mydomain.foo'
|
||||
Setting.protocol = 'https'
|
||||
|
||||
journal = Journal.find(2)
|
||||
assert Mailer.deliver_issue_edit(journal)
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_kind_of TMail::Mail, mail
|
||||
# link to the main ticket
|
||||
assert mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>')
|
||||
|
||||
# link to a referenced ticket
|
||||
assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
|
||||
# link to a changeset
|
||||
assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>')
|
||||
end
|
||||
|
||||
# test mailer methods for each language
|
||||
def test_issue_add
|
||||
issue = Issue.find(1)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
Setting.default_language = lang.to_s
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
end
|
||||
end
|
||||
|
||||
def test_issue_edit
|
||||
journal = Journal.find(1)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
Setting.default_language = lang.to_s
|
||||
assert Mailer.deliver_issue_edit(journal)
|
||||
end
|
||||
end
|
||||
|
||||
def test_document_added
|
||||
document = Document.find(1)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
Setting.default_language = lang.to_s
|
||||
assert Mailer.deliver_document_added(document)
|
||||
end
|
||||
end
|
||||
|
||||
def test_attachments_added
|
||||
attachements = [ Attachment.find_by_container_type('Document') ]
|
||||
GLoc.valid_languages.each do |lang|
|
||||
Setting.default_language = lang.to_s
|
||||
assert Mailer.deliver_attachments_added(attachements)
|
||||
end
|
||||
end
|
||||
|
||||
def test_news_added
|
||||
news = News.find(:first)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
Setting.default_language = lang.to_s
|
||||
assert Mailer.deliver_news_added(news)
|
||||
end
|
||||
end
|
||||
|
||||
def test_message_posted
|
||||
message = Message.find(:first)
|
||||
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
|
||||
recipients = recipients.compact.uniq
|
||||
GLoc.valid_languages.each do |lang|
|
||||
Setting.default_language = lang.to_s
|
||||
assert Mailer.deliver_message_posted(message, recipients)
|
||||
end
|
||||
end
|
||||
|
||||
def test_account_information
|
||||
user = User.find(:first)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
user.update_attribute :language, lang.to_s
|
||||
user.reload
|
||||
assert Mailer.deliver_account_information(user, 'pAsswORd')
|
||||
end
|
||||
end
|
||||
|
||||
def test_lost_password
|
||||
token = Token.find(2)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
token.user.update_attribute :language, lang.to_s
|
||||
token.reload
|
||||
assert Mailer.deliver_lost_password(token)
|
||||
end
|
||||
end
|
||||
|
||||
def test_register
|
||||
token = Token.find(1)
|
||||
GLoc.valid_languages.each do |lang|
|
||||
token.user.update_attribute :language, lang.to_s
|
||||
token.reload
|
||||
assert Mailer.deliver_register(token)
|
||||
end
|
||||
end
|
||||
|
||||
def test_reminders
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Mailer.reminders(:days => 42)
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,51 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class MemberTest < Test::Unit::TestCase
|
||||
fixtures :users, :projects, :roles, :members
|
||||
|
||||
def setup
|
||||
@jsmith = Member.find(1)
|
||||
end
|
||||
|
||||
def test_create
|
||||
member = Member.new(:project_id => 1, :user_id => 4, :role_id => 1)
|
||||
assert member.save
|
||||
end
|
||||
|
||||
def test_update
|
||||
assert_equal "eCookbook", @jsmith.project.name
|
||||
assert_equal "Manager", @jsmith.role.name
|
||||
assert_equal "jsmith", @jsmith.user.login
|
||||
|
||||
@jsmith.role = Role.find(2)
|
||||
assert @jsmith.save
|
||||
end
|
||||
|
||||
def test_validate
|
||||
member = Member.new(:project_id => 1, :user_id => 2, :role_id =>2)
|
||||
# same use can't have more than one role for a project
|
||||
assert !member.save
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@jsmith.destroy
|
||||
assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
begin
|
||||
require 'mocha'
|
||||
|
||||
class MercurialAdapterTest < Test::Unit::TestCase
|
||||
|
||||
TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR
|
||||
TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
|
||||
TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
|
||||
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
||||
|
||||
def test_hgversion
|
||||
to_test = { "0.9.5" => [0,9,5],
|
||||
"1.0" => [1,0],
|
||||
"1e4ddc9ac9f7+20080325" => nil,
|
||||
"1.0.1+20080525" => [1,0,1],
|
||||
"1916e629a29d" => nil}
|
||||
|
||||
to_test.each do |s, v|
|
||||
test_hgversion_for(s, v)
|
||||
end
|
||||
end
|
||||
|
||||
def test_template_path
|
||||
to_test = { [0,9,5] => "0.9.5",
|
||||
[1,0] => "1.0",
|
||||
[] => "1.0",
|
||||
[1,0,1] => "1.0"}
|
||||
|
||||
to_test.each do |v, template|
|
||||
test_template_path_for(v, template)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def test_hgversion_for(hgversion, version)
|
||||
Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion)
|
||||
adapter = Redmine::Scm::Adapters::MercurialAdapter
|
||||
assert_equal version, adapter.hgversion
|
||||
end
|
||||
|
||||
def test_template_path_for(version, template)
|
||||
adapter = Redmine::Scm::Adapters::MercurialAdapter
|
||||
assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version)
|
||||
assert File.exist?(adapter.template_path_for(version))
|
||||
end
|
||||
end
|
||||
|
||||
rescue LoadError
|
||||
def test_fake; assert(false, "Requires mocha to run those tests") end
|
||||
end
|
||||
@@ -0,0 +1,70 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class MessageTest < Test::Unit::TestCase
|
||||
fixtures :projects, :boards, :messages
|
||||
|
||||
def setup
|
||||
@board = Board.find(1)
|
||||
@user = User.find(1)
|
||||
end
|
||||
|
||||
def test_create
|
||||
topics_count = @board.topics_count
|
||||
messages_count = @board.messages_count
|
||||
|
||||
message = Message.new(:board => @board, :subject => 'Test message', :content => 'Test message content', :author => @user)
|
||||
assert message.save
|
||||
@board.reload
|
||||
# topics count incremented
|
||||
assert_equal topics_count+1, @board[:topics_count]
|
||||
# messages count incremented
|
||||
assert_equal messages_count+1, @board[:messages_count]
|
||||
assert_equal message, @board.last_message
|
||||
end
|
||||
|
||||
def test_reply
|
||||
topics_count = @board.topics_count
|
||||
messages_count = @board.messages_count
|
||||
@message = Message.find(1)
|
||||
replies_count = @message.replies_count
|
||||
|
||||
reply = Message.new(:board => @board, :subject => 'Test reply', :content => 'Test reply content', :parent => @message, :author => @user)
|
||||
assert reply.save
|
||||
@board.reload
|
||||
# same topics count
|
||||
assert_equal topics_count, @board[:topics_count]
|
||||
# messages count incremented
|
||||
assert_equal messages_count+1, @board[:messages_count]
|
||||
assert_equal reply, @board.last_message
|
||||
@message.reload
|
||||
# replies count incremented
|
||||
assert_equal replies_count+1, @message[:replies_count]
|
||||
assert_equal reply, @message.last_reply
|
||||
end
|
||||
|
||||
def test_destroy_topic
|
||||
message = Message.find(1)
|
||||
board = message.board
|
||||
topics_count, messages_count = board.topics_count, board.messages_count
|
||||
assert message.destroy
|
||||
board.reload
|
||||
|
||||
# Replies deleted
|
||||
assert Message.find_all_by_parent_id(1).empty?
|
||||
# Checks counters
|
||||
assert_equal topics_count - 1, board.topics_count
|
||||
assert_equal messages_count - 3, board.messages_count
|
||||
end
|
||||
|
||||
def test_destroy_reply
|
||||
message = Message.find(5)
|
||||
board = message.board
|
||||
topics_count, messages_count = board.topics_count, board.messages_count
|
||||
assert message.destroy
|
||||
board.reload
|
||||
|
||||
# Checks counters
|
||||
assert_equal topics_count, board.topics_count
|
||||
assert_equal messages_count - 1, board.messages_count
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,133 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class ProjectTest < Test::Unit::TestCase
|
||||
fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
|
||||
|
||||
def setup
|
||||
@ecookbook = Project.find(1)
|
||||
@ecookbook_sub1 = Project.find(3)
|
||||
end
|
||||
|
||||
def test_truth
|
||||
assert_kind_of Project, @ecookbook
|
||||
assert_equal "eCookbook", @ecookbook.name
|
||||
end
|
||||
|
||||
def test_update
|
||||
assert_equal "eCookbook", @ecookbook.name
|
||||
@ecookbook.name = "eCook"
|
||||
assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
|
||||
@ecookbook.reload
|
||||
assert_equal "eCook", @ecookbook.name
|
||||
end
|
||||
|
||||
def test_validate
|
||||
@ecookbook.name = ""
|
||||
assert !@ecookbook.save
|
||||
assert_equal 1, @ecookbook.errors.count
|
||||
assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
|
||||
end
|
||||
|
||||
def test_public_projects
|
||||
public_projects = Project.find(:all, :conditions => ["is_public=?", true])
|
||||
assert_equal 3, public_projects.length
|
||||
assert_equal true, public_projects[0].is_public?
|
||||
end
|
||||
|
||||
def test_archive
|
||||
user = @ecookbook.members.first.user
|
||||
@ecookbook.archive
|
||||
@ecookbook.reload
|
||||
|
||||
assert !@ecookbook.active?
|
||||
assert !user.projects.include?(@ecookbook)
|
||||
# Subproject are also archived
|
||||
assert !@ecookbook.children.empty?
|
||||
assert @ecookbook.active_children.empty?
|
||||
end
|
||||
|
||||
def test_unarchive
|
||||
user = @ecookbook.members.first.user
|
||||
@ecookbook.archive
|
||||
# A subproject of an archived project can not be unarchived
|
||||
assert !@ecookbook_sub1.unarchive
|
||||
|
||||
# Unarchive project
|
||||
assert @ecookbook.unarchive
|
||||
@ecookbook.reload
|
||||
assert @ecookbook.active?
|
||||
assert user.projects.include?(@ecookbook)
|
||||
# Subproject can now be unarchived
|
||||
@ecookbook_sub1.reload
|
||||
assert @ecookbook_sub1.unarchive
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
# 2 active members
|
||||
assert_equal 2, @ecookbook.members.size
|
||||
# and 1 is locked
|
||||
assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
|
||||
# some boards
|
||||
assert @ecookbook.boards.any?
|
||||
|
||||
@ecookbook.destroy
|
||||
# make sure that the project non longer exists
|
||||
assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
|
||||
# make sure related data was removed
|
||||
assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
|
||||
assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
|
||||
end
|
||||
|
||||
def test_subproject_ok
|
||||
sub = Project.find(2)
|
||||
sub.parent = @ecookbook
|
||||
assert sub.save
|
||||
assert_equal @ecookbook.id, sub.parent.id
|
||||
@ecookbook.reload
|
||||
assert_equal 4, @ecookbook.children.size
|
||||
end
|
||||
|
||||
def test_subproject_invalid
|
||||
sub = Project.find(2)
|
||||
sub.parent = @ecookbook_sub1
|
||||
assert !sub.save
|
||||
end
|
||||
|
||||
def test_subproject_invalid_2
|
||||
sub = @ecookbook
|
||||
sub.parent = Project.find(2)
|
||||
assert !sub.save
|
||||
end
|
||||
|
||||
def test_rolled_up_trackers
|
||||
parent = Project.find(1)
|
||||
parent.trackers = Tracker.find([1,2])
|
||||
child = parent.children.find(3)
|
||||
|
||||
assert_equal [1, 2], parent.tracker_ids
|
||||
assert_equal [2, 3], child.tracker_ids
|
||||
|
||||
assert_kind_of Tracker, parent.rolled_up_trackers.first
|
||||
assert_equal Tracker.find(1), parent.rolled_up_trackers.first
|
||||
|
||||
assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
|
||||
assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,173 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class QueryTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
|
||||
|
||||
def test_custom_fields_for_all_projects_should_be_available_in_global_queries
|
||||
query = Query.new(:project => nil, :name => '_')
|
||||
assert query.available_filters.has_key?('cf_1')
|
||||
assert !query.available_filters.has_key?('cf_3')
|
||||
end
|
||||
|
||||
def find_issues_with_query(query)
|
||||
Issue.find :all,
|
||||
:include => [ :assigned_to, :status, :tracker, :project, :priority ],
|
||||
:conditions => query.statement
|
||||
end
|
||||
|
||||
def test_query_with_multiple_custom_fields
|
||||
query = Query.find(1)
|
||||
assert query.valid?
|
||||
assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
|
||||
issues = find_issues_with_query(query)
|
||||
assert_equal 1, issues.length
|
||||
assert_equal Issue.find(3), issues.first
|
||||
end
|
||||
|
||||
def test_operator_none
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('fixed_version_id', '!*', [''])
|
||||
query.add_filter('cf_1', '!*', [''])
|
||||
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL")
|
||||
assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_none_for_integer
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('estimated_hours', '!*', [''])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
assert issues.all? {|i| !i.estimated_hours}
|
||||
end
|
||||
|
||||
def test_operator_all
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('fixed_version_id', '*', [''])
|
||||
query.add_filter('cf_1', '*', [''])
|
||||
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL")
|
||||
assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_greater_than
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('done_ratio', '>=', ['40'])
|
||||
assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_in_more_than
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', '>t+', ['15'])
|
||||
assert query.statement.include?("#{Issue.table_name}.due_date >=")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_in_less_than
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', '<t+', ['15'])
|
||||
assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_today
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', 't', [''])
|
||||
assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_this_week_on_date
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', 'w', [''])
|
||||
assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_this_week_on_datetime
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('created_on', 'w', [''])
|
||||
assert query.statement.include?("#{Issue.table_name}.created_on BETWEEN")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_contains
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('subject', '~', ['string'])
|
||||
assert query.statement.include?("#{Issue.table_name}.subject LIKE '%string%'")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_does_not_contains
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('subject', '!~', ['string'])
|
||||
assert query.statement.include?("#{Issue.table_name}.subject NOT LIKE '%string%'")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_default_columns
|
||||
q = Query.new
|
||||
assert !q.columns.empty?
|
||||
end
|
||||
|
||||
def test_set_column_names
|
||||
q = Query.new
|
||||
q.column_names = ['tracker', :subject, '', 'unknonw_column']
|
||||
assert_equal [:tracker, :subject], q.columns.collect {|c| c.name}
|
||||
c = q.columns.first
|
||||
assert q.has_column?(c)
|
||||
end
|
||||
|
||||
def test_label_for
|
||||
q = Query.new
|
||||
assert_equal 'assigned_to', q.label_for('assigned_to_id')
|
||||
end
|
||||
|
||||
def test_editable_by
|
||||
admin = User.find(1)
|
||||
manager = User.find(2)
|
||||
developer = User.find(3)
|
||||
|
||||
# Public query on project 1
|
||||
q = Query.find(1)
|
||||
assert q.editable_by?(admin)
|
||||
assert q.editable_by?(manager)
|
||||
assert !q.editable_by?(developer)
|
||||
|
||||
# Private query on project 1
|
||||
q = Query.find(2)
|
||||
assert q.editable_by?(admin)
|
||||
assert !q.editable_by?(manager)
|
||||
assert q.editable_by?(developer)
|
||||
|
||||
# Private query for all projects
|
||||
q = Query.find(3)
|
||||
assert q.editable_by?(admin)
|
||||
assert !q.editable_by?(manager)
|
||||
assert q.editable_by?(developer)
|
||||
|
||||
# Public query for all projects
|
||||
q = Query.find(4)
|
||||
assert q.editable_by?(admin)
|
||||
assert !q.editable_by?(manager)
|
||||
assert !q.editable_by?(developer)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,88 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositoryBazaarTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
|
||||
REPOSITORY_PATH.gsub!(/\/+/, '/')
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}")
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets_from_scratch
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 4, @repository.changesets.count
|
||||
assert_equal 9, @repository.changes.count
|
||||
assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
|
||||
end
|
||||
|
||||
def test_fetch_changesets_incremental
|
||||
@repository.fetch_changesets
|
||||
# Remove changesets with revision > 5
|
||||
@repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
|
||||
@repository.reload
|
||||
assert_equal 2, @repository.changesets.count
|
||||
|
||||
@repository.fetch_changesets
|
||||
assert_equal 4, @repository.changesets.count
|
||||
end
|
||||
|
||||
def test_entries
|
||||
entries = @repository.entries
|
||||
assert_equal 2, entries.size
|
||||
|
||||
assert_equal 'dir', entries[0].kind
|
||||
assert_equal 'directory', entries[0].name
|
||||
|
||||
assert_equal 'file', entries[1].kind
|
||||
assert_equal 'doc-mkdir.txt', entries[1].name
|
||||
end
|
||||
|
||||
def test_entries_in_subdirectory
|
||||
entries = @repository.entries('directory')
|
||||
assert_equal 3, entries.size
|
||||
|
||||
assert_equal 'file', entries.last.kind
|
||||
assert_equal 'edit.png', entries.last.name
|
||||
end
|
||||
|
||||
def test_cat
|
||||
cat = @repository.scm.cat('directory/document.txt')
|
||||
assert cat =~ /Write the contents of a file as of a given revision to standard output/
|
||||
end
|
||||
|
||||
def test_annotate
|
||||
annotate = @repository.scm.annotate('doc-mkdir.txt')
|
||||
assert_equal 17, annotate.lines.size
|
||||
assert_equal 1, annotate.revisions[0].identifier
|
||||
assert_equal 'jsmith@', annotate.revisions[0].author
|
||||
assert_equal 'mkdir', annotate.lines[0]
|
||||
end
|
||||
else
|
||||
puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'pp'
|
||||
class RepositoryCvsTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
|
||||
# CVS module
|
||||
MODULE_NAME = 'test'
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
assert @repository = Repository::Cvs.create(:project => @project,
|
||||
:root_url => REPOSITORY_PATH,
|
||||
:url => MODULE_NAME)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets_from_scratch
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 5, @repository.changesets.count
|
||||
assert_equal 14, @repository.changes.count
|
||||
assert_not_nil @repository.changesets.find_by_comments('Two files changed')
|
||||
end
|
||||
|
||||
def test_fetch_changesets_incremental
|
||||
@repository.fetch_changesets
|
||||
# Remove the 3 latest changesets
|
||||
@repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
|
||||
@repository.reload
|
||||
assert_equal 2, @repository.changesets.count
|
||||
|
||||
@repository.fetch_changesets
|
||||
assert_equal 5, @repository.changesets.count
|
||||
end
|
||||
else
|
||||
puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,55 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositoryDarcsTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository'
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
assert @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets_from_scratch
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 6, @repository.changesets.count
|
||||
assert_equal 13, @repository.changes.count
|
||||
assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
|
||||
end
|
||||
|
||||
def test_fetch_changesets_incremental
|
||||
@repository.fetch_changesets
|
||||
# Remove changesets with revision > 3
|
||||
@repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
|
||||
@repository.reload
|
||||
assert_equal 3, @repository.changesets.count
|
||||
|
||||
@repository.fetch_changesets
|
||||
assert_equal 6, @repository.changesets.count
|
||||
end
|
||||
else
|
||||
puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositoryFilesystemTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository'
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
|
||||
assert @repository = Repository::Filesystem.create(:project => @project, :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 0, @repository.changesets.count
|
||||
assert_equal 0, @repository.changes.count
|
||||
end
|
||||
|
||||
def test_entries
|
||||
assert_equal 2, @repository.entries("", 2).size
|
||||
assert_equal 2, @repository.entries("dir", 3).size
|
||||
end
|
||||
|
||||
def test_cat
|
||||
assert_equal "TEST CAT\n", @repository.scm.cat("test")
|
||||
end
|
||||
|
||||
else
|
||||
puts "Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS."
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,56 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositoryGitTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
|
||||
REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets_from_scratch
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 6, @repository.changesets.count
|
||||
assert_equal 11, @repository.changes.count
|
||||
assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find(:first, :order => 'id ASC').comments
|
||||
end
|
||||
|
||||
def test_fetch_changesets_incremental
|
||||
@repository.fetch_changesets
|
||||
# Remove the 3 latest changesets
|
||||
@repository.changesets.find(:all, :order => 'id DESC', :limit => 3).each(&:destroy)
|
||||
@repository.reload
|
||||
assert_equal 3, @repository.changesets.count
|
||||
|
||||
@repository.fetch_changesets
|
||||
assert_equal 6, @repository.changesets.count
|
||||
end
|
||||
else
|
||||
puts "Git test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,75 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositoryMercurialTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets_from_scratch
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 6, @repository.changesets.count
|
||||
assert_equal 11, @repository.changes.count
|
||||
assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
|
||||
end
|
||||
|
||||
def test_fetch_changesets_incremental
|
||||
@repository.fetch_changesets
|
||||
# Remove changesets with revision > 2
|
||||
@repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
|
||||
@repository.reload
|
||||
assert_equal 3, @repository.changesets.count
|
||||
|
||||
@repository.fetch_changesets
|
||||
assert_equal 6, @repository.changesets.count
|
||||
end
|
||||
|
||||
def test_entries
|
||||
assert_equal 2, @repository.entries("sources", 2).size
|
||||
assert_equal 1, @repository.entries("sources", 3).size
|
||||
end
|
||||
|
||||
def test_locate_on_outdated_repository
|
||||
# Change the working dir state
|
||||
%x{hg -R #{REPOSITORY_PATH} up -r 0}
|
||||
assert_equal 1, @repository.entries("images", 0).size
|
||||
assert_equal 2, @repository.entries("images").size
|
||||
assert_equal 2, @repository.entries("images", 2).size
|
||||
end
|
||||
|
||||
|
||||
def test_cat
|
||||
assert @repository.scm.cat("sources/welcome_controller.rb", 2)
|
||||
assert_nil @repository.scm.cat("sources/welcome_controller.rb")
|
||||
end
|
||||
|
||||
else
|
||||
puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,55 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositorySubversionTest < Test::Unit::TestCase
|
||||
fixtures :projects
|
||||
|
||||
# No '..' in the repository path for svn
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}")
|
||||
end
|
||||
|
||||
if File.directory?(REPOSITORY_PATH)
|
||||
def test_fetch_changesets_from_scratch
|
||||
@repository.fetch_changesets
|
||||
@repository.reload
|
||||
|
||||
assert_equal 8, @repository.changesets.count
|
||||
assert_equal 16, @repository.changes.count
|
||||
assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
|
||||
end
|
||||
|
||||
def test_fetch_changesets_incremental
|
||||
@repository.fetch_changesets
|
||||
# Remove changesets with revision > 5
|
||||
@repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
|
||||
@repository.reload
|
||||
assert_equal 5, @repository.changesets.count
|
||||
|
||||
@repository.fetch_changesets
|
||||
assert_equal 8, @repository.changesets.count
|
||||
end
|
||||
else
|
||||
puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,130 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RepositoryTest < Test::Unit::TestCase
|
||||
fixtures :projects,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:repositories,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:changesets,
|
||||
:changes,
|
||||
:users,
|
||||
:enumerations
|
||||
|
||||
def setup
|
||||
@repository = Project.find(1).repository
|
||||
end
|
||||
|
||||
def test_create
|
||||
repository = Repository::Subversion.new(:project => Project.find(3))
|
||||
assert !repository.save
|
||||
|
||||
repository.url = "svn://localhost"
|
||||
assert repository.save
|
||||
repository.reload
|
||||
|
||||
project = Project.find(3)
|
||||
assert_equal repository, project.repository
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
changesets = Changeset.count(:all, :conditions => "repository_id = 10")
|
||||
changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
|
||||
assert_difference 'Changeset.count', -changesets do
|
||||
assert_difference 'Change.count', -changes do
|
||||
Repository.find(10).destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_create_with_disabled_scm
|
||||
# disable Subversion
|
||||
Setting.enabled_scm = ['Darcs', 'Git']
|
||||
repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
|
||||
assert !repository.save
|
||||
assert_equal :activerecord_error_invalid, repository.errors.on(:type)
|
||||
# re-enable Subversion for following tests
|
||||
Setting.delete_all
|
||||
end
|
||||
|
||||
def test_scan_changesets_for_issue_ids
|
||||
# choosing a status to apply to fix issues
|
||||
Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
|
||||
Setting.commit_fix_done_ratio = "90"
|
||||
Setting.commit_ref_keywords = 'refs , references, IssueID'
|
||||
Setting.commit_fix_keywords = 'fixes , closes'
|
||||
Setting.default_language = 'en'
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
# make sure issue 1 is not already closed
|
||||
fixed_issue = Issue.find(1)
|
||||
assert !fixed_issue.status.is_closed?
|
||||
old_status = fixed_issue.status
|
||||
|
||||
Repository.scan_changesets_for_issue_ids
|
||||
assert_equal [101, 102], Issue.find(3).changeset_ids
|
||||
|
||||
# fixed issues
|
||||
fixed_issue.reload
|
||||
assert fixed_issue.status.is_closed?
|
||||
assert_equal 90, fixed_issue.done_ratio
|
||||
assert_equal [101], fixed_issue.changeset_ids
|
||||
|
||||
# issue change
|
||||
journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
|
||||
assert_equal User.find_by_login('dlopper'), journal.user
|
||||
assert_equal 'Applied in changeset r2.', journal.notes
|
||||
|
||||
# 2 email notifications
|
||||
assert_equal 2, ActionMailer::Base.deliveries.size
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
assert_kind_of TMail::Mail, mail
|
||||
assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
|
||||
assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
|
||||
|
||||
# ignoring commits referencing an issue of another project
|
||||
assert_equal [], Issue.find(4).changesets
|
||||
end
|
||||
|
||||
def test_for_changeset_comments_strip
|
||||
repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
|
||||
comment = <<-COMMENT
|
||||
This is a loooooooooooooooooooooooooooong comment
|
||||
|
||||
|
||||
COMMENT
|
||||
changeset = Changeset.new(
|
||||
:comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
|
||||
:committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
|
||||
assert( changeset.save )
|
||||
assert_not_equal( comment, changeset.comments )
|
||||
assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
|
||||
end
|
||||
|
||||
def test_for_urls_strip
|
||||
repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository',
|
||||
:root_url => 'foo ')
|
||||
assert repository.save
|
||||
repository.reload
|
||||
assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
|
||||
assert_equal 'foo', repository.root_url
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RoleTest < Test::Unit::TestCase
|
||||
fixtures :roles, :workflows
|
||||
|
||||
def test_copy_workflows
|
||||
source = Role.find(1)
|
||||
assert_equal 90, source.workflows.size
|
||||
|
||||
target = Role.new(:name => 'Target')
|
||||
assert target.save
|
||||
target.workflows.copy(source)
|
||||
target.reload
|
||||
assert_equal 90, target.workflows.size
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,143 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class SearchTest < Test::Unit::TestCase
|
||||
fixtures :users,
|
||||
:members,
|
||||
:projects,
|
||||
:roles,
|
||||
:enabled_modules,
|
||||
:issues,
|
||||
:trackers,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:repositories,
|
||||
:changesets
|
||||
|
||||
def setup
|
||||
@project = Project.find(1)
|
||||
@issue_keyword = '%unable to print recipes%'
|
||||
@issue = Issue.find(1)
|
||||
@changeset_keyword = '%very first commit%'
|
||||
@changeset = Changeset.find(100)
|
||||
end
|
||||
|
||||
def test_search_by_anonymous
|
||||
User.current = nil
|
||||
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert r.include?(@changeset)
|
||||
|
||||
# Removes the :view_changesets permission from Anonymous role
|
||||
remove_permission Role.anonymous, :view_changesets
|
||||
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert !r.include?(@changeset)
|
||||
|
||||
# Make the project private
|
||||
@project.update_attribute :is_public, false
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert !r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert !r.include?(@changeset)
|
||||
end
|
||||
|
||||
def test_search_by_user
|
||||
User.current = User.find_by_login('rhill')
|
||||
assert User.current.memberships.empty?
|
||||
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert r.include?(@changeset)
|
||||
|
||||
# Removes the :view_changesets permission from Non member role
|
||||
remove_permission Role.non_member, :view_changesets
|
||||
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert !r.include?(@changeset)
|
||||
|
||||
# Make the project private
|
||||
@project.update_attribute :is_public, false
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert !r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert !r.include?(@changeset)
|
||||
end
|
||||
|
||||
def test_search_by_allowed_member
|
||||
User.current = User.find_by_login('jsmith')
|
||||
assert User.current.projects.include?(@project)
|
||||
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert r.include?(@changeset)
|
||||
|
||||
# Make the project private
|
||||
@project.update_attribute :is_public, false
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert r.include?(@changeset)
|
||||
end
|
||||
|
||||
def test_search_by_unallowed_member
|
||||
# Removes the :view_changesets permission from user's and non member role
|
||||
remove_permission Role.find(1), :view_changesets
|
||||
remove_permission Role.non_member, :view_changesets
|
||||
|
||||
User.current = User.find_by_login('jsmith')
|
||||
assert User.current.projects.include?(@project)
|
||||
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert !r.include?(@changeset)
|
||||
|
||||
# Make the project private
|
||||
@project.update_attribute :is_public, false
|
||||
r = Issue.search(@issue_keyword).first
|
||||
assert r.include?(@issue)
|
||||
r = Changeset.search(@changeset_keyword).first
|
||||
assert !r.include?(@changeset)
|
||||
end
|
||||
|
||||
def test_search_issue_with_multiple_hits_in_journals
|
||||
i = Issue.find(1)
|
||||
assert_equal 2, i.journals.count(:all, :conditions => "notes LIKE '%notes%'")
|
||||
|
||||
r = Issue.search('%notes%').first
|
||||
assert_equal 1, r.size
|
||||
assert_equal i, r.first
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_permission(role, permission)
|
||||
role.permissions = role.permissions - [ permission ]
|
||||
role.save
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class SettingTest < Test::Unit::TestCase
|
||||
|
||||
def test_read_default
|
||||
assert_equal "Redmine", Setting.app_title
|
||||
assert Setting.self_registration?
|
||||
assert !Setting.login_required?
|
||||
end
|
||||
|
||||
def test_update
|
||||
Setting.app_title = "My title"
|
||||
assert_equal "My title", Setting.app_title
|
||||
# make sure db has been updated (INSERT)
|
||||
assert_equal "My title", Setting.find_by_name('app_title').value
|
||||
|
||||
Setting.app_title = "My other title"
|
||||
assert_equal "My other title", Setting.app_title
|
||||
# make sure db has been updated (UPDATE)
|
||||
assert_equal "My other title", Setting.find_by_name('app_title').value
|
||||
end
|
||||
|
||||
def test_serialized_setting
|
||||
Setting.notified_events = ['issue_added', 'issue_updated', 'news_added']
|
||||
assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events
|
||||
assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.find_by_name('notified_events').value
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'mkmf'
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class SubversionAdapterTest < Test::Unit::TestCase
|
||||
|
||||
if find_executable0('svn')
|
||||
def test_client_version
|
||||
v = Redmine::Scm::Adapters::SubversionAdapter.client_version
|
||||
assert v.is_a?(Array)
|
||||
end
|
||||
else
|
||||
puts "Subversion binary NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TimeEntryTest < Test::Unit::TestCase
|
||||
fixtures :issues, :projects, :users, :time_entries
|
||||
|
||||
def test_hours_format
|
||||
assertions = { "2" => 2.0,
|
||||
"21.1" => 21.1,
|
||||
"2,1" => 2.1,
|
||||
"7:12" => 7.2,
|
||||
"10h" => 10.0,
|
||||
"10 h" => 10.0,
|
||||
"45m" => 0.75,
|
||||
"45 m" => 0.75,
|
||||
"3h15" => 3.25,
|
||||
"3h 15" => 3.25,
|
||||
"3 h 15" => 3.25,
|
||||
"3 h 15m" => 3.25,
|
||||
"3 h 15 m" => 3.25,
|
||||
"3 hours" => 3.0,
|
||||
"12min" => 0.2,
|
||||
}
|
||||
|
||||
assertions.each do |k, v|
|
||||
t = TimeEntry.new(:hours => k)
|
||||
assert_equal v, t.hours
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TokenTest < Test::Unit::TestCase
|
||||
fixtures :tokens
|
||||
|
||||
def test_create
|
||||
token = Token.new
|
||||
token.save
|
||||
assert_equal 40, token.value.length
|
||||
assert !token.expired?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TrackerTest < Test::Unit::TestCase
|
||||
fixtures :trackers, :workflows
|
||||
|
||||
def test_copy_workflows
|
||||
source = Tracker.find(1)
|
||||
assert_equal 89, source.workflows.size
|
||||
|
||||
target = Tracker.new(:name => 'Target')
|
||||
assert target.save
|
||||
target.workflows.copy(source)
|
||||
target.reload
|
||||
assert_equal 89, target.workflows.size
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class UserPreferenceTest < Test::Unit::TestCase
|
||||
fixtures :users, :user_preferences
|
||||
|
||||
def test_create
|
||||
user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
|
||||
user.login = "newuser"
|
||||
user.password, user.password_confirmation = "password", "password"
|
||||
assert user.save
|
||||
|
||||
assert_kind_of UserPreference, user.pref
|
||||
assert_kind_of Hash, user.pref.others
|
||||
assert user.pref.save
|
||||
end
|
||||
|
||||
def test_update
|
||||
user = User.find(1)
|
||||
assert_equal true, user.pref.hide_mail
|
||||
user.pref['preftest'] = 'value'
|
||||
assert user.pref.save
|
||||
|
||||
user.reload
|
||||
assert_equal 'value', user.pref['preftest']
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,155 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class UserTest < Test::Unit::TestCase
|
||||
fixtures :users, :members, :projects
|
||||
|
||||
def setup
|
||||
@admin = User.find(1)
|
||||
@jsmith = User.find(2)
|
||||
@dlopper = User.find(3)
|
||||
end
|
||||
|
||||
def test_truth
|
||||
assert_kind_of User, @jsmith
|
||||
end
|
||||
|
||||
def test_create
|
||||
user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
|
||||
|
||||
user.login = "jsmith"
|
||||
user.password, user.password_confirmation = "password", "password"
|
||||
# login uniqueness
|
||||
assert !user.save
|
||||
assert_equal 1, user.errors.count
|
||||
|
||||
user.login = "newuser"
|
||||
user.password, user.password_confirmation = "passwd", "password"
|
||||
# password confirmation
|
||||
assert !user.save
|
||||
assert_equal 1, user.errors.count
|
||||
|
||||
user.password, user.password_confirmation = "password", "password"
|
||||
assert user.save
|
||||
end
|
||||
|
||||
def test_update
|
||||
assert_equal "admin", @admin.login
|
||||
@admin.login = "john"
|
||||
assert @admin.save, @admin.errors.full_messages.join("; ")
|
||||
@admin.reload
|
||||
assert_equal "john", @admin.login
|
||||
end
|
||||
|
||||
def test_validate
|
||||
@admin.login = ""
|
||||
assert !@admin.save
|
||||
assert_equal 1, @admin.errors.count
|
||||
end
|
||||
|
||||
def test_password
|
||||
user = User.try_to_login("admin", "admin")
|
||||
assert_kind_of User, user
|
||||
assert_equal "admin", user.login
|
||||
user.password = "hello"
|
||||
assert user.save
|
||||
|
||||
user = User.try_to_login("admin", "hello")
|
||||
assert_kind_of User, user
|
||||
assert_equal "admin", user.login
|
||||
assert_equal User.hash_password("hello"), user.hashed_password
|
||||
end
|
||||
|
||||
def test_name_format
|
||||
assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
|
||||
Setting.user_format = :firstname_lastname
|
||||
assert_equal 'John Smith', @jsmith.name
|
||||
Setting.user_format = :username
|
||||
assert_equal 'jsmith', @jsmith.name
|
||||
end
|
||||
|
||||
def test_lock
|
||||
user = User.try_to_login("jsmith", "jsmith")
|
||||
assert_equal @jsmith, user
|
||||
|
||||
@jsmith.status = User::STATUS_LOCKED
|
||||
assert @jsmith.save
|
||||
|
||||
user = User.try_to_login("jsmith", "jsmith")
|
||||
assert_equal nil, user
|
||||
end
|
||||
|
||||
def test_create_anonymous
|
||||
AnonymousUser.delete_all
|
||||
anon = User.anonymous
|
||||
assert !anon.new_record?
|
||||
assert_kind_of AnonymousUser, anon
|
||||
end
|
||||
|
||||
def test_rss_key
|
||||
assert_nil @jsmith.rss_token
|
||||
key = @jsmith.rss_key
|
||||
assert_equal 40, key.length
|
||||
|
||||
@jsmith.reload
|
||||
assert_equal key, @jsmith.rss_key
|
||||
end
|
||||
|
||||
def test_role_for_project
|
||||
# user with a role
|
||||
role = @jsmith.role_for_project(Project.find(1))
|
||||
assert_kind_of Role, role
|
||||
assert_equal "Manager", role.name
|
||||
|
||||
# user with no role
|
||||
assert !@dlopper.role_for_project(Project.find(2)).member?
|
||||
end
|
||||
|
||||
def test_mail_notification_all
|
||||
@jsmith.mail_notification = true
|
||||
@jsmith.notified_project_ids = []
|
||||
@jsmith.save
|
||||
@jsmith.reload
|
||||
assert @jsmith.projects.first.recipients.include?(@jsmith.mail)
|
||||
end
|
||||
|
||||
def test_mail_notification_selected
|
||||
@jsmith.mail_notification = false
|
||||
@jsmith.notified_project_ids = [1]
|
||||
@jsmith.save
|
||||
@jsmith.reload
|
||||
assert Project.find(1).recipients.include?(@jsmith.mail)
|
||||
end
|
||||
|
||||
def test_mail_notification_none
|
||||
@jsmith.mail_notification = false
|
||||
@jsmith.notified_project_ids = []
|
||||
@jsmith.save
|
||||
@jsmith.reload
|
||||
assert !@jsmith.projects.first.recipients.include?(@jsmith.mail)
|
||||
end
|
||||
|
||||
def test_comments_sorting_preference
|
||||
assert !@jsmith.wants_comments_in_reverse_order?
|
||||
@jsmith.pref.comments_sorting = 'asc'
|
||||
assert !@jsmith.wants_comments_in_reverse_order?
|
||||
@jsmith.pref.comments_sorting = 'desc'
|
||||
assert @jsmith.wants_comments_in_reverse_order?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,69 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class WatcherTest < Test::Unit::TestCase
|
||||
fixtures :issues, :users
|
||||
|
||||
def setup
|
||||
@user = User.find(1)
|
||||
@issue = Issue.find(1)
|
||||
end
|
||||
|
||||
def test_watch
|
||||
assert @issue.add_watcher(@user)
|
||||
@issue.reload
|
||||
assert @issue.watchers.detect { |w| w.user == @user }
|
||||
end
|
||||
|
||||
def test_cant_watch_twice
|
||||
assert @issue.add_watcher(@user)
|
||||
assert !@issue.add_watcher(@user)
|
||||
end
|
||||
|
||||
def test_watched_by
|
||||
assert @issue.add_watcher(@user)
|
||||
@issue.reload
|
||||
assert @issue.watched_by?(@user)
|
||||
assert Issue.watched_by(@user).include?(@issue)
|
||||
end
|
||||
|
||||
def test_recipients
|
||||
@issue.watchers.delete_all
|
||||
@issue.reload
|
||||
|
||||
assert @issue.watcher_recipients.empty?
|
||||
assert @issue.add_watcher(@user)
|
||||
|
||||
@user.mail_notification = true
|
||||
@user.save
|
||||
@issue.reload
|
||||
assert @issue.watcher_recipients.include?(@user.mail)
|
||||
|
||||
@user.mail_notification = false
|
||||
@user.save
|
||||
@issue.reload
|
||||
assert @issue.watcher_recipients.include?(@user.mail)
|
||||
end
|
||||
|
||||
def test_unwatch
|
||||
assert @issue.add_watcher(@user)
|
||||
@issue.reload
|
||||
assert_equal 1, @issue.remove_watcher(@user)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class WikiContentTest < Test::Unit::TestCase
|
||||
fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :users
|
||||
|
||||
def setup
|
||||
@wiki = Wiki.find(1)
|
||||
@page = @wiki.pages.first
|
||||
end
|
||||
|
||||
def test_create
|
||||
page = WikiPage.new(:wiki => @wiki, :title => "Page")
|
||||
page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
|
||||
assert page.save
|
||||
page.reload
|
||||
|
||||
content = page.content
|
||||
assert_kind_of WikiContent, content
|
||||
assert_equal 1, content.version
|
||||
assert_equal 1, content.versions.length
|
||||
assert_equal "Content text", content.text
|
||||
assert_equal "My comment", content.comments
|
||||
assert_equal User.find(1), content.author
|
||||
assert_equal content.text, content.versions.last.text
|
||||
end
|
||||
|
||||
def test_update
|
||||
content = @page.content
|
||||
version_count = content.version
|
||||
content.text = "My new content"
|
||||
assert content.save
|
||||
content.reload
|
||||
assert_equal version_count+1, content.version
|
||||
assert_equal version_count+1, content.versions.length
|
||||
end
|
||||
|
||||
def test_fetch_history
|
||||
assert !@page.content.versions.empty?
|
||||
@page.content.versions.each do |version|
|
||||
assert_kind_of String, version.text
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,103 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class WikiPageTest < Test::Unit::TestCase
|
||||
fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
|
||||
|
||||
def setup
|
||||
@wiki = Wiki.find(1)
|
||||
@page = @wiki.pages.first
|
||||
end
|
||||
|
||||
def test_create
|
||||
page = WikiPage.new(:wiki => @wiki)
|
||||
assert !page.save
|
||||
assert_equal 1, page.errors.count
|
||||
|
||||
page.title = "Page"
|
||||
assert page.save
|
||||
page.reload
|
||||
|
||||
@wiki.reload
|
||||
assert @wiki.pages.include?(page)
|
||||
end
|
||||
|
||||
def test_find_or_new_page
|
||||
page = @wiki.find_or_new_page("CookBook documentation")
|
||||
assert_kind_of WikiPage, page
|
||||
assert !page.new_record?
|
||||
|
||||
page = @wiki.find_or_new_page("Non existing page")
|
||||
assert_kind_of WikiPage, page
|
||||
assert page.new_record?
|
||||
end
|
||||
|
||||
def test_parent_title
|
||||
page = WikiPage.find_by_title('Another_page')
|
||||
assert_nil page.parent_title
|
||||
|
||||
page = WikiPage.find_by_title('Page_with_an_inline_image')
|
||||
assert_equal 'CookBook documentation', page.parent_title
|
||||
end
|
||||
|
||||
def test_assign_parent
|
||||
page = WikiPage.find_by_title('Another_page')
|
||||
page.parent_title = 'CookBook documentation'
|
||||
assert page.save
|
||||
page.reload
|
||||
assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
|
||||
end
|
||||
|
||||
def test_unassign_parent
|
||||
page = WikiPage.find_by_title('Page_with_an_inline_image')
|
||||
page.parent_title = ''
|
||||
assert page.save
|
||||
page.reload
|
||||
assert_nil page.parent
|
||||
end
|
||||
|
||||
def test_parent_validation
|
||||
page = WikiPage.find_by_title('CookBook_documentation')
|
||||
|
||||
# A page that doesn't exist
|
||||
page.parent_title = 'Unknown title'
|
||||
assert !page.save
|
||||
assert_equal :activerecord_error_invalid, page.errors.on(:parent_title)
|
||||
# A child page
|
||||
page.parent_title = 'Page_with_an_inline_image'
|
||||
assert !page.save
|
||||
assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
|
||||
# The page itself
|
||||
page.parent_title = 'CookBook_documentation'
|
||||
assert !page.save
|
||||
assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
|
||||
|
||||
page.parent_title = 'Another_page'
|
||||
assert page.save
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
page = WikiPage.find(1)
|
||||
page.destroy
|
||||
assert_nil WikiPage.find_by_id(1)
|
||||
# make sure that page content and its history are deleted
|
||||
assert WikiContent.find_all_by_page_id(1).empty?
|
||||
assert WikiContent.versioned_class.find_all_by_page_id(1).empty?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class WikiRedirectTest < Test::Unit::TestCase
|
||||
fixtures :projects, :wikis
|
||||
|
||||
def setup
|
||||
@wiki = Wiki.find(1)
|
||||
@original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
|
||||
end
|
||||
|
||||
def test_create_redirect
|
||||
@original.title = 'New title'
|
||||
assert @original.save
|
||||
@original.reload
|
||||
|
||||
assert_equal 'New_title', @original.title
|
||||
assert @wiki.redirects.find_by_title('Original_title')
|
||||
assert @wiki.find_page('Original title')
|
||||
end
|
||||
|
||||
def test_update_redirect
|
||||
# create a redirect that point to this page
|
||||
assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
|
||||
|
||||
@original.title = 'New title'
|
||||
@original.save
|
||||
# make sure the old page now points to the new page
|
||||
assert_equal 'New_title', @wiki.find_page('An old page').title
|
||||
end
|
||||
|
||||
def test_reverse_rename
|
||||
# create a redirect that point to this page
|
||||
assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
|
||||
|
||||
@original.title = 'An old page'
|
||||
@original.save
|
||||
assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'An_old_page')
|
||||
assert @wiki.redirects.find_by_title_and_redirects_to('Original_title', 'An_old_page')
|
||||
end
|
||||
|
||||
def test_rename_to_already_redirected
|
||||
assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Other_page')
|
||||
|
||||
@original.title = 'An old page'
|
||||
@original.save
|
||||
# this redirect have to be removed since 'An old page' page now exists
|
||||
assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'Other_page')
|
||||
end
|
||||
|
||||
def test_redirects_removed_when_deleting_page
|
||||
assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
|
||||
|
||||
@original.destroy
|
||||
assert !@wiki.redirects.find(:first)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,44 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class WikiTest < Test::Unit::TestCase
|
||||
fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
|
||||
|
||||
def test_create
|
||||
wiki = Wiki.new(:project => Project.find(2))
|
||||
assert !wiki.save
|
||||
assert_equal 1, wiki.errors.count
|
||||
|
||||
wiki.start_page = "Start page"
|
||||
assert wiki.save
|
||||
end
|
||||
|
||||
def test_update
|
||||
@wiki = Wiki.find(1)
|
||||
@wiki.start_page = "Another start page"
|
||||
assert @wiki.save
|
||||
@wiki.reload
|
||||
assert_equal "Another start page", @wiki.start_page
|
||||
end
|
||||
|
||||
def test_titleize
|
||||
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
|
||||
assert_equal 'テスト', Wiki.titleize('テスト')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user