mirror of
https://github.com/redmine/redmine.git
synced 2026-05-07 18:17:27 +02:00
Adds a branch for unlimited project hierarchy.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/work@2148 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
80
nested_projects/test/unit/activity_test.rb
Normal file
80
nested_projects/test/unit/activity_test.rb
Normal file
@@ -0,0 +1,80 @@
|
||||
# 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
|
||||
|
||||
def test_user_activity
|
||||
user = User.find(2)
|
||||
events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
|
||||
|
||||
assert(events.size > 0)
|
||||
assert(events.size <= 10)
|
||||
assert_nil(events.detect {|e| e.event_author != user})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_events(user, options={})
|
||||
Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
|
||||
end
|
||||
end
|
||||
37
nested_projects/test/unit/attachment_test.rb
Normal file
37
nested_projects/test/unit/attachment_test.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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
|
||||
fixtures :issues, :users
|
||||
|
||||
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
|
||||
|
||||
def test_digest
|
||||
assert_equal '1478adae0d4eb06d35897518540e25d6', Attachment.digest(Test::Unit::TestCase.fixture_path + "/files/testfile.txt")
|
||||
end
|
||||
end
|
||||
36
nested_projects/test/unit/auth_source_ldap_test.rb
Normal file
36
nested_projects/test/unit/auth_source_ldap_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# 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 AuthSourceLdapTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_create
|
||||
a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName')
|
||||
assert a.save
|
||||
end
|
||||
|
||||
def test_should_strip_ldap_attributes
|
||||
a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName',
|
||||
:attr_firstname => 'givenName ')
|
||||
assert a.save
|
||||
assert_equal 'givenName', a.reload.attr_firstname
|
||||
end
|
||||
end
|
||||
30
nested_projects/test/unit/board_test.rb
Normal file
30
nested_projects/test/unit/board_test.rb
Normal file
@@ -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
|
||||
43
nested_projects/test/unit/calendar_test.rb
Normal file
43
nested_projects/test/unit/calendar_test.rb
Normal file
@@ -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
|
||||
73
nested_projects/test/unit/changeset_test.rb
Normal file
73
nested_projects/test/unit/changeset_test.rb
Normal file
@@ -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
|
||||
47
nested_projects/test/unit/comment_test.rb
Normal file
47
nested_projects/test/unit/comment_test.rb
Normal file
@@ -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
|
||||
32
nested_projects/test/unit/custom_field_test.rb
Normal file
32
nested_projects/test/unit/custom_field_test.rb
Normal file
@@ -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
|
||||
117
nested_projects/test/unit/custom_value_test.rb
Normal file
117
nested_projects/test/unit/custom_value_test.rb
Normal file
@@ -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
|
||||
45
nested_projects/test/unit/default_data_test.rb
Normal file
45
nested_projects/test/unit/default_data_test.rb
Normal file
@@ -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
|
||||
37
nested_projects/test/unit/document_test.rb
Normal file
37
nested_projects/test/unit/document_test.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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 DocumentTest < Test::Unit::TestCase
|
||||
fixtures :projects, :enumerations, :documents
|
||||
|
||||
def test_create
|
||||
doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
|
||||
assert doc.save
|
||||
end
|
||||
|
||||
def test_create_with_default_category
|
||||
# Sets a default category
|
||||
e = Enumeration.find_by_name('Technical documentation')
|
||||
e.update_attributes(:is_default => true)
|
||||
|
||||
doc = Document.new(:project => Project.find(1), :title => 'New document')
|
||||
assert_equal e, doc.category
|
||||
assert doc.save
|
||||
end
|
||||
end
|
||||
82
nested_projects/test/unit/enumeration_test.rb
Normal file
82
nested_projects/test/unit/enumeration_test.rb
Normal file
@@ -0,0 +1,82 @@
|
||||
# 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_default
|
||||
e = Enumeration.default('IPRI')
|
||||
assert e.is_a?(Enumeration)
|
||||
assert e.is_default?
|
||||
assert_equal 'Normal', e.name
|
||||
end
|
||||
|
||||
def test_create
|
||||
e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => false)
|
||||
assert e.save
|
||||
assert_equal 'Normal', Enumeration.default('IPRI').name
|
||||
end
|
||||
|
||||
def test_create_as_default
|
||||
e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => true)
|
||||
assert e.save
|
||||
assert_equal e, Enumeration.default('IPRI')
|
||||
end
|
||||
|
||||
def test_update_default
|
||||
e = Enumeration.default('IPRI')
|
||||
e.update_attributes(:name => 'Changed', :is_default => true)
|
||||
assert_equal e, Enumeration.default('IPRI')
|
||||
end
|
||||
|
||||
def test_update_default_to_non_default
|
||||
e = Enumeration.default('IPRI')
|
||||
e.update_attributes(:name => 'Changed', :is_default => false)
|
||||
assert_nil Enumeration.default('IPRI')
|
||||
end
|
||||
|
||||
def test_change_default
|
||||
e = Enumeration.find_by_name('Urgent')
|
||||
e.update_attributes(:name => 'Urgent', :is_default => true)
|
||||
assert_equal e, Enumeration.default('IPRI')
|
||||
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
|
||||
42
nested_projects/test/unit/filesystem_adapter_test.rb
Normal file
42
nested_projects/test/unit/filesystem_adapter_test.rb
Normal file
@@ -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
|
||||
|
||||
|
||||
433
nested_projects/test/unit/helpers/application_helper_test.rb
Normal file
433
nested_projects/test/unit/helpers/application_helper_test.rb
Normal file
@@ -0,0 +1,433 @@
|
||||
# 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, :roles, :enabled_modules, :users,
|
||||
:repositories, :changesets,
|
||||
:trackers, :issue_statuses, :issues, :versions, :documents,
|
||||
:wikis, :wiki_pages, :wiki_contents,
|
||||
:boards, :messages,
|
||||
:attachments
|
||||
|
||||
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>.',
|
||||
'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://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>.',
|
||||
'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
|
||||
'(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)',
|
||||
'(see inline link : http://www.foo.bar/Test)' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>)',
|
||||
'(see inline link : http://www.foo.bar/Test).' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>).',
|
||||
'(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
|
||||
'(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
|
||||
'(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</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>',
|
||||
'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
|
||||
'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
|
||||
'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
|
||||
'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://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="" />',
|
||||
'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />',
|
||||
'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted "title"" alt="This is a double-quoted "title"" />',
|
||||
}
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||||
end
|
||||
|
||||
def test_attached_images
|
||||
to_test = {
|
||||
'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
|
||||
'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />'
|
||||
}
|
||||
attachments = Attachment.find(:all)
|
||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
|
||||
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')
|
||||
|
||||
message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
|
||||
|
||||
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'),
|
||||
# message
|
||||
'message#4' => link_to('Post 2', message_url, :class => 'message'),
|
||||
'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
|
||||
# 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>',
|
||||
'-[[Another page|Page]] link-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a> link</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>",
|
||||
# remove attributes except class
|
||||
"<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
|
||||
"<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
|
||||
}
|
||||
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",
|
||||
"<notextile>this is <tag>a tag</tag></notextile>" => "this is <tag>a tag</tag>"
|
||||
}
|
||||
to_test.each { |text, result| assert_equal result, textilizable(text) }
|
||||
end
|
||||
|
||||
def syntax_highlight
|
||||
raw = <<-RAW
|
||||
<pre><code class="ruby">
|
||||
# Some ruby code here
|
||||
</pre></code>
|
||||
RAW
|
||||
|
||||
expected = <<-EXPECTED
|
||||
<pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span>
|
||||
</pre></code>
|
||||
EXPECTED
|
||||
|
||||
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
||||
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_acronym
|
||||
assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
|
||||
textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
|
||||
end
|
||||
|
||||
def test_footnotes
|
||||
raw = <<-RAW
|
||||
This is some text[1].
|
||||
|
||||
fn1. This is the foot note
|
||||
RAW
|
||||
|
||||
expected = <<-EXPECTED
|
||||
<p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
|
||||
<p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
|
||||
EXPECTED
|
||||
|
||||
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
||||
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_default_formatter
|
||||
Setting.text_formatting = 'unknown'
|
||||
text = 'a *link*: http://www.example.net/'
|
||||
assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
|
||||
Setting.text_formatting = 'textile'
|
||||
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
|
||||
|
||||
def test_utc_time_format
|
||||
now = Time.now.utc
|
||||
Setting.date_format = '%d %m %Y'
|
||||
Setting.time_format = '%H %M'
|
||||
assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now)
|
||||
assert_equal Time.now.strftime('%H %M'), format_time(now, false)
|
||||
end
|
||||
|
||||
def test_due_date_distance_in_words
|
||||
to_test = { Date.today => 'Due in 0 days',
|
||||
Date.today + 1 => 'Due in 1 day',
|
||||
Date.today + 100 => 'Due in 100 days',
|
||||
Date.today + 20000 => 'Due in 20000 days',
|
||||
Date.today - 1 => '1 day late',
|
||||
Date.today - 100 => '100 days late',
|
||||
Date.today - 20000 => '20000 days late',
|
||||
}
|
||||
to_test.each do |date, expected|
|
||||
assert_equal expected, due_date_distance_in_words(date)
|
||||
end
|
||||
end
|
||||
|
||||
def test_avatar
|
||||
# turn on avatars
|
||||
Setting.gravatar_enabled = '1'
|
||||
assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
|
||||
assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
|
||||
assert_nil avatar('jsmith')
|
||||
assert_nil avatar(nil)
|
||||
|
||||
# turn off avatars
|
||||
Setting.gravatar_enabled = '0'
|
||||
assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
|
||||
end
|
||||
end
|
||||
41
nested_projects/test/unit/issue_category_test.rb
Normal file
41
nested_projects/test/unit/issue_category_test.rb
Normal file
@@ -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
|
||||
69
nested_projects/test/unit/issue_status_test.rb
Normal file
69
nested_projects/test/unit/issue_status_test.rb
Normal file
@@ -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 IssueStatusTest < Test::Unit::TestCase
|
||||
fixtures :issue_statuses, :issues
|
||||
|
||||
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_destroy
|
||||
count_before = IssueStatus.count
|
||||
status = IssueStatus.find(3)
|
||||
assert status.destroy
|
||||
assert_equal count_before - 1, IssueStatus.count
|
||||
end
|
||||
|
||||
def test_destroy_status_in_use
|
||||
# Status assigned to an Issue
|
||||
status = Issue.find(1).status
|
||||
assert_raise(RuntimeError, "Can't delete status") { status.destroy }
|
||||
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
|
||||
|
||||
def test_reorder_should_not_clear_default_status
|
||||
status = IssueStatus.default
|
||||
status.move_to_bottom
|
||||
status.reload
|
||||
assert status.is_default?
|
||||
end
|
||||
end
|
||||
200
nested_projects/test/unit/issue_test.rb
Normal file
200
nested_projects/test/unit/issue_test.rb
Normal file
@@ -0,0 +1,200 @@
|
||||
# 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
|
||||
|
||||
def test_overdue
|
||||
assert Issue.new(:due_date => 1.day.ago.to_date).overdue?
|
||||
assert !Issue.new(:due_date => Date.today).overdue?
|
||||
assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue?
|
||||
assert !Issue.new(:due_date => nil).overdue?
|
||||
end
|
||||
end
|
||||
39
nested_projects/test/unit/journal_test.rb
Normal file
39
nested_projects/test/unit/journal_test.rb
Normal file
@@ -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
|
||||
49
nested_projects/test/unit/lib/redmine/access_control_test.rb
Normal file
49
nested_projects/test/unit/lib/redmine/access_control_test.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
# 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 Redmine::AccessControlTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@access_module = Redmine::AccessControl
|
||||
end
|
||||
|
||||
def test_permissions
|
||||
perms = @access_module.permissions
|
||||
assert perms.is_a?(Array)
|
||||
assert perms.first.is_a?(Redmine::AccessControl::Permission)
|
||||
end
|
||||
|
||||
def test_module_permission
|
||||
perm = @access_module.permission(:view_issues)
|
||||
assert perm.is_a?(Redmine::AccessControl::Permission)
|
||||
assert_equal :view_issues, perm.name
|
||||
assert_equal :issue_tracking, perm.project_module
|
||||
assert perm.actions.is_a?(Array)
|
||||
assert perm.actions.include?('issues/index')
|
||||
end
|
||||
|
||||
def test_no_module_permission
|
||||
perm = @access_module.permission(:edit_project)
|
||||
assert perm.is_a?(Redmine::AccessControl::Permission)
|
||||
assert_equal :edit_project, perm.name
|
||||
assert_nil perm.project_module
|
||||
assert perm.actions.is_a?(Array)
|
||||
assert perm.actions.include?('projects/settings')
|
||||
end
|
||||
end
|
||||
83
nested_projects/test/unit/lib/redmine/hook_test.rb
Normal file
83
nested_projects/test/unit/lib/redmine/hook_test.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
# 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 Redmine::Hook::ManagerTest < Test::Unit::TestCase
|
||||
|
||||
# Some hooks that are manually registered in these tests
|
||||
class TestHook < Redmine::Hook::Listener; end
|
||||
|
||||
class TestHook1 < TestHook
|
||||
def view_layouts_base_html_head(context)
|
||||
'Test hook 1 listener.'
|
||||
end
|
||||
end
|
||||
|
||||
class TestHook2 < TestHook
|
||||
def view_layouts_base_html_head(context)
|
||||
'Test hook 2 listener.'
|
||||
end
|
||||
end
|
||||
|
||||
class TestHook3 < TestHook
|
||||
def view_layouts_base_html_head(context)
|
||||
"Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}."
|
||||
end
|
||||
end
|
||||
Redmine::Hook.clear_listeners
|
||||
|
||||
def setup
|
||||
@hook_module = Redmine::Hook
|
||||
end
|
||||
|
||||
def teardown
|
||||
@hook_module.clear_listeners
|
||||
end
|
||||
|
||||
def test_clear_listeners
|
||||
assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
@hook_module.add_listener(TestHook1)
|
||||
@hook_module.add_listener(TestHook2)
|
||||
assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
|
||||
@hook_module.clear_listeners
|
||||
assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
end
|
||||
|
||||
def test_add_listener
|
||||
assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
@hook_module.add_listener(TestHook1)
|
||||
assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
end
|
||||
|
||||
def test_call_hook
|
||||
@hook_module.add_listener(TestHook1)
|
||||
assert_equal 'Test hook 1 listener.', @hook_module.call_hook(:view_layouts_base_html_head)
|
||||
end
|
||||
|
||||
def test_call_hook_with_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_equal 'Context keys: bar, foo.', @hook_module.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a')
|
||||
end
|
||||
|
||||
def test_call_hook_with_multiple_listeners
|
||||
@hook_module.add_listener(TestHook1)
|
||||
@hook_module.add_listener(TestHook2)
|
||||
assert_equal 'Test hook 1 listener.Test hook 2 listener.', @hook_module.call_hook(:view_layouts_base_html_head)
|
||||
end
|
||||
end
|
||||
78
nested_projects/test/unit/lib/redmine/plugin_test.rb
Normal file
78
nested_projects/test/unit/lib/redmine/plugin_test.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
# 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 Redmine::PluginTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@klass = Redmine::Plugin
|
||||
# In case some real plugins are installed
|
||||
@klass.clear
|
||||
end
|
||||
|
||||
def teardown
|
||||
@klass.clear
|
||||
end
|
||||
|
||||
def test_register
|
||||
@klass.register :foo do
|
||||
name 'Foo plugin'
|
||||
url 'http://example.net/plugins/foo'
|
||||
author 'John Smith'
|
||||
author_url 'http://example.net/jsmith'
|
||||
description 'This is a test plugin'
|
||||
version '0.0.1'
|
||||
settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
|
||||
end
|
||||
|
||||
assert_equal 1, @klass.all.size
|
||||
|
||||
plugin = @klass.find('foo')
|
||||
assert plugin.is_a?(Redmine::Plugin)
|
||||
assert_equal :foo, plugin.id
|
||||
assert_equal 'Foo plugin', plugin.name
|
||||
assert_equal 'http://example.net/plugins/foo', plugin.url
|
||||
assert_equal 'John Smith', plugin.author
|
||||
assert_equal 'http://example.net/jsmith', plugin.author_url
|
||||
assert_equal 'This is a test plugin', plugin.description
|
||||
assert_equal '0.0.1', plugin.version
|
||||
end
|
||||
|
||||
def test_requires_redmine
|
||||
test = self
|
||||
version = Redmine::VERSION.to_a.slice(0,3).join('.')
|
||||
|
||||
@klass.register :foo do
|
||||
test.assert requires_redmine(:version_or_higher => '0.1.0')
|
||||
test.assert requires_redmine(:version_or_higher => version)
|
||||
test.assert requires_redmine(version)
|
||||
test.assert_raise Redmine::PluginRequirementError do
|
||||
requires_redmine(:version_or_higher => '99.0.0')
|
||||
end
|
||||
|
||||
test.assert requires_redmine(:version => version)
|
||||
test.assert requires_redmine(:version => [version, '99.0.0'])
|
||||
test.assert_raise Redmine::PluginRequirementError do
|
||||
requires_redmine(:version => '99.0.0')
|
||||
end
|
||||
test.assert_raise Redmine::PluginRequirementError do
|
||||
requires_redmine(:version => ['98.0.0', '99.0.0'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
42
nested_projects/test/unit/lib/redmine/unified_diff_test.rb
Normal file
42
nested_projects/test/unit/lib/redmine/unified_diff_test.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# 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 Redmine::UnifiedDiffTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_subversion_diff
|
||||
diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
|
||||
# number of files
|
||||
assert_equal 4, diff.size
|
||||
assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
|
||||
end
|
||||
|
||||
def test_truncate_diff
|
||||
diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
|
||||
assert_equal 2, diff.size
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read_diff_fixture(filename)
|
||||
File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,98 @@
|
||||
# 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 Redmine::WikiFormatting::MacrosTest < HelperTestCase
|
||||
include ApplicationHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
fixtures :projects, :roles, :enabled_modules, :users,
|
||||
:repositories, :changesets,
|
||||
:trackers, :issue_statuses, :issues,
|
||||
:versions, :documents,
|
||||
:wikis, :wiki_pages, :wiki_contents,
|
||||
:boards, :messages,
|
||||
:attachments
|
||||
|
||||
def setup
|
||||
super
|
||||
@project = nil
|
||||
end
|
||||
|
||||
def teardown
|
||||
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(/Page not found/)
|
||||
end
|
||||
|
||||
def test_macro_child_pages
|
||||
expected = "<p><ul class=\"pages-hierarchy\">\n" +
|
||||
"<li><a href=\"/wiki/ecookbook/Child_1\">Child 1</a></li>\n" +
|
||||
"<li><a href=\"/wiki/ecookbook/Child_2\">Child 2</a></li>\n" +
|
||||
"</ul>\n</p>"
|
||||
|
||||
@project = Project.find(1)
|
||||
# child pages of the current wiki page
|
||||
assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content)
|
||||
# child pages of another page
|
||||
assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content)
|
||||
|
||||
@project = Project.find(2)
|
||||
assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content)
|
||||
end
|
||||
|
||||
def test_macro_child_pages_with_option
|
||||
expected = "<p><ul class=\"pages-hierarchy\">\n" +
|
||||
"<li><a href=\"/wiki/ecookbook/Another_page\">Another page</a>\n" +
|
||||
"<ul class=\"pages-hierarchy\">\n" +
|
||||
"<li><a href=\"/wiki/ecookbook/Child_1\">Child 1</a></li>\n" +
|
||||
"<li><a href=\"/wiki/ecookbook/Child_2\">Child 2</a></li>\n" +
|
||||
"</ul>\n</li>\n</ul>\n</p>"
|
||||
|
||||
@project = Project.find(1)
|
||||
# child pages of the current wiki page
|
||||
assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content)
|
||||
# child pages of another page
|
||||
assert_equal expected, textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content)
|
||||
|
||||
@project = Project.find(2)
|
||||
assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content)
|
||||
end
|
||||
end
|
||||
148
nested_projects/test/unit/mail_handler_test.rb
Normal file
148
nested_projects/test/unit/mail_handler_test.rb
Normal file
@@ -0,0 +1,148 @@
|
||||
# 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,
|
||||
:issue_statuses,
|
||||
:workflows,
|
||||
: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_status
|
||||
# This email contains: 'Project: onlinestore' and 'Status: Resolved'
|
||||
issue = submit_email('ticket_on_given_project.eml')
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert_equal Project.find(2), issue.project
|
||||
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
||||
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_with_cc
|
||||
issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
|
||||
assert_equal 1, issue.watchers.size
|
||||
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_match /This is reply/, journal.notes
|
||||
end
|
||||
|
||||
def test_add_issue_note_with_status_change
|
||||
# This email contains: 'Status: Resolved'
|
||||
journal = submit_email('ticket_reply_with_status.eml')
|
||||
assert journal.is_a?(Journal)
|
||||
issue = Issue.find(journal.issue.id)
|
||||
assert_equal User.find_by_login('jsmith'), journal.user
|
||||
assert_equal Issue.find(2), journal.journalized
|
||||
assert_match /This is reply/, journal.notes
|
||||
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
||||
end
|
||||
|
||||
def test_should_strip_tags_of_html_only_emails
|
||||
issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert_equal 'HTML email', issue.subject
|
||||
assert_equal 'This is a html-only email.', issue.description
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def submit_email(filename, options={})
|
||||
raw = IO.read(File.join(FIXTURES_PATH, filename))
|
||||
MailHandler.receive(raw, options)
|
||||
end
|
||||
end
|
||||
186
nested_projects/test/unit/mailer_test.rb
Normal file
186
nested_projects/test/unit/mailer_test.rb
Normal file
@@ -0,0 +1,186 @@
|
||||
# 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, :messages, :boards, :repositories
|
||||
|
||||
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
|
||||
|
||||
def test_generated_links_with_prefix
|
||||
relative_url_root = ActionController::AbstractRequest.relative_url_root
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Setting.host_name = 'mydomain.foo/rdm'
|
||||
Setting.protocol = 'http'
|
||||
ActionController::AbstractRequest.relative_url_root = '/rdm'
|
||||
|
||||
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="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>')
|
||||
|
||||
# link to a referenced ticket
|
||||
assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
|
||||
# link to a changeset
|
||||
assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>')
|
||||
ensure
|
||||
# restore it
|
||||
ActionController::AbstractRequest.relative_url_root = relative_url_root
|
||||
end
|
||||
|
||||
def test_generated_links_with_prefix_and_no_relative_url_root
|
||||
relative_url_root = ActionController::AbstractRequest.relative_url_root
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Setting.host_name = 'mydomain.foo/rdm'
|
||||
Setting.protocol = 'http'
|
||||
ActionController::AbstractRequest.relative_url_root = nil
|
||||
|
||||
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="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>')
|
||||
|
||||
# link to a referenced ticket
|
||||
assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
|
||||
# link to a changeset
|
||||
assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>')
|
||||
ensure
|
||||
# restore it
|
||||
ActionController::AbstractRequest.relative_url_root = relative_url_root
|
||||
end
|
||||
|
||||
def test_plain_text_mail
|
||||
Setting.plain_text_mail = 1
|
||||
journal = Journal.find(2)
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert !mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</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
|
||||
51
nested_projects/test/unit/member_test.rb
Normal file
51
nested_projects/test/unit/member_test.rb
Normal file
@@ -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
|
||||
53
nested_projects/test/unit/mercurial_adapter_test.rb
Normal file
53
nested_projects/test/unit/mercurial_adapter_test.rb
Normal file
@@ -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
|
||||
97
nested_projects/test/unit/message_test.rb
Normal file
97
nested_projects/test/unit/message_test.rb
Normal file
@@ -0,0 +1,97 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class MessageTest < Test::Unit::TestCase
|
||||
fixtures :projects, :roles, :members, :boards, :messages, :users, :watchers
|
||||
|
||||
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
|
||||
# author should be watching the message
|
||||
assert message.watched_by?(@user)
|
||||
end
|
||||
|
||||
def test_reply
|
||||
topics_count = @board.topics_count
|
||||
messages_count = @board.messages_count
|
||||
@message = Message.find(1)
|
||||
replies_count = @message.replies_count
|
||||
|
||||
reply_author = User.find(2)
|
||||
reply = Message.new(:board => @board, :subject => 'Test reply', :content => 'Test reply content', :parent => @message, :author => reply_author)
|
||||
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
|
||||
# author should be watching the message
|
||||
assert @message.watched_by?(reply_author)
|
||||
end
|
||||
|
||||
def test_destroy_topic
|
||||
message = Message.find(1)
|
||||
board = message.board
|
||||
topics_count, messages_count = board.topics_count, board.messages_count
|
||||
|
||||
assert_difference('Watcher.count', -1) do
|
||||
assert message.destroy
|
||||
end
|
||||
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
|
||||
# Watchers removed
|
||||
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
|
||||
|
||||
def test_editable_by
|
||||
message = Message.find(6)
|
||||
author = message.author
|
||||
assert message.editable_by?(author)
|
||||
|
||||
author.role_for_project(message.project).remove_permission!(:edit_own_messages)
|
||||
assert !message.reload.editable_by?(author.reload)
|
||||
end
|
||||
|
||||
def test_destroyable_by
|
||||
message = Message.find(6)
|
||||
author = message.author
|
||||
assert message.destroyable_by?(author)
|
||||
|
||||
author.role_for_project(message.project).remove_permission!(:delete_own_messages)
|
||||
assert !message.reload.destroyable_by?(author.reload)
|
||||
end
|
||||
end
|
||||
63
nested_projects/test/unit/news_test.rb
Normal file
63
nested_projects/test/unit/news_test.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
# 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 NewsTest < Test::Unit::TestCase
|
||||
fixtures :projects, :users, :roles, :members, :enabled_modules, :news
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_should_include_news_for_projects_with_news_enabled
|
||||
project = projects(:projects_001)
|
||||
assert project.enabled_modules.any?{ |em| em.name == 'news' }
|
||||
|
||||
# News.latest should return news from projects_001
|
||||
assert News.latest.any? { |news| news.project == project }
|
||||
end
|
||||
|
||||
def test_should_not_include_news_for_projects_with_news_disabled
|
||||
# The projects_002 (OnlineStore) doesn't have the news module enabled, use that project for this test
|
||||
project = projects(:projects_002)
|
||||
assert ! project.enabled_modules.any?{ |em| em.name == 'news' }
|
||||
|
||||
# Add a piece of news to the project
|
||||
news = project.news.create(:title => 'Test news', :description => 'This should not be returned by News.latest')
|
||||
|
||||
# News.latest should not return that new piece of news
|
||||
assert News.latest.include?(news) == false
|
||||
end
|
||||
|
||||
def test_should_only_include_news_from_projects_visibly_to_the_user
|
||||
# users_001 has no memberships so can only get news from public project
|
||||
assert News.latest(users(:users_001)).all? { |news| news.project.is_public? }
|
||||
end
|
||||
|
||||
def test_should_limit_the_amount_of_returned_news
|
||||
# Make sure we have a bunch of news stories
|
||||
10.times { projects(:projects_001).news.create(:title => 'Test news', :description => 'Lorem ipsum etc') }
|
||||
assert_equal 2, News.latest(users(:users_002), 2).size
|
||||
assert_equal 6, News.latest(users(:users_002), 6).size
|
||||
end
|
||||
|
||||
def test_should_return_5_news_stories_by_default
|
||||
# Make sure we have a bunch of news stories
|
||||
10.times { projects(:projects_001).news.create(:title => 'Test news', :description => 'Lorem ipsum etc') }
|
||||
assert_equal 5, News.latest(users(:users_004)).size
|
||||
end
|
||||
end
|
||||
144
nested_projects/test/unit/project_test.rb
Normal file
144
nested_projects/test/unit/project_test.rb
Normal file
@@ -0,0 +1,144 @@
|
||||
# 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
|
||||
|
||||
def test_next_identifier
|
||||
ProjectCustomField.delete_all
|
||||
Project.create!(:name => 'last', :identifier => 'p2008040')
|
||||
assert_equal 'p2008041', Project.next_identifier
|
||||
end
|
||||
|
||||
def test_next_identifier_first_project
|
||||
Project.delete_all
|
||||
assert_nil Project.next_identifier
|
||||
end
|
||||
end
|
||||
212
nested_projects/test/unit/query_test.rb
Normal file
212
nested_projects/test/unit/query_test.rb
Normal file
@@ -0,0 +1,212 @@
|
||||
# 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, :enabled_modules, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :versions, :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
|
||||
Issue.find(7).update_attribute(:due_date, (Date.today + 15))
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', '>t+', ['15'])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert(issue.due_date >= (Date.today + 15))}
|
||||
end
|
||||
|
||||
def test_operator_in_less_than
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', '<t+', ['15'])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert(issue.due_date >= Date.today && issue.due_date <= (Date.today + 15))}
|
||||
end
|
||||
|
||||
def test_operator_less_than_ago
|
||||
Issue.find(7).update_attribute(:due_date, (Date.today - 3))
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', '>t-', ['3'])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert(issue.due_date >= (Date.today - 3) && issue.due_date <= Date.today)}
|
||||
end
|
||||
|
||||
def test_operator_more_than_ago
|
||||
Issue.find(7).update_attribute(:due_date, (Date.today - 10))
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', '<t-', ['10'])
|
||||
assert query.statement.include?("#{Issue.table_name}.due_date <=")
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert(issue.due_date <= (Date.today - 10))}
|
||||
end
|
||||
|
||||
def test_operator_in
|
||||
Issue.find(7).update_attribute(:due_date, (Date.today + 2))
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', 't+', ['2'])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert_equal((Date.today + 2), issue.due_date)}
|
||||
end
|
||||
|
||||
def test_operator_ago
|
||||
Issue.find(7).update_attribute(:due_date, (Date.today - 3))
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', 't-', ['3'])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert_equal((Date.today - 3), issue.due_date)}
|
||||
end
|
||||
|
||||
def test_operator_today
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', 't', [''])
|
||||
issues = find_issues_with_query(query)
|
||||
assert !issues.empty?
|
||||
issues.each {|issue| assert_equal Date.today, issue.due_date}
|
||||
end
|
||||
|
||||
def test_operator_this_week_on_date
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('due_date', 'w', [''])
|
||||
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', [''])
|
||||
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
|
||||
88
nested_projects/test/unit/repository_bazaar_test.rb
Normal file
88
nested_projects/test/unit/repository_bazaar_test.rb
Normal file
@@ -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
|
||||
66
nested_projects/test/unit/repository_cvs_test.rb
Normal file
66
nested_projects/test/unit/repository_cvs_test.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
# 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 Redmine::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
|
||||
|
||||
def test_deleted_files_should_not_be_listed
|
||||
entries = @repository.entries('sources')
|
||||
assert entries.detect {|e| e.name == 'watchers_controller.rb'}
|
||||
assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
|
||||
end
|
||||
else
|
||||
puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
62
nested_projects/test/unit/repository_darcs_test.rb
Normal file
62
nested_projects/test/unit/repository_darcs_test.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
# 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
|
||||
|
||||
def test_cat
|
||||
@repository.fetch_changesets
|
||||
cat = @repository.cat("sources/welcome_controller.rb", 2)
|
||||
assert_not_nil cat
|
||||
assert cat.include?('class WelcomeController < ApplicationController')
|
||||
end
|
||||
else
|
||||
puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
|
||||
def test_fake; assert true end
|
||||
end
|
||||
end
|
||||
54
nested_projects/test/unit/repository_filesystem_test.rb
Normal file
54
nested_projects/test/unit/repository_filesystem_test.rb
Normal file
@@ -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
|
||||
69
nested_projects/test/unit/repository_git_test.rb
Normal file
69
nested_projects/test/unit/repository_git_test.rb
Normal file
@@ -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 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 Redmine::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
|
||||
|
||||
commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
|
||||
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
|
||||
assert_equal "jsmith <jsmith@foo.bar>", commit.committer
|
||||
assert_equal User.find_by_login('jsmith'), commit.user
|
||||
# TODO: add a commit with commit time <> author time to the test repository
|
||||
assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
|
||||
assert_equal "2007-12-14".to_date, commit.commit_date
|
||||
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
|
||||
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
|
||||
assert_equal 3, commit.changes.count
|
||||
change = commit.changes.sort_by(&:path).first
|
||||
assert_equal "README", change.path
|
||||
assert_equal "A", change.action
|
||||
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 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
|
||||
75
nested_projects/test/unit/repository_mercurial_test.rb
Normal file
75
nested_projects/test/unit/repository_mercurial_test.rb
Normal file
@@ -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
|
||||
55
nested_projects/test/unit/repository_subversion_test.rb
Normal file
55
nested_projects/test/unit/repository_subversion_test.rb
Normal file
@@ -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
|
||||
154
nested_projects/test/unit/repository_test.rb
Normal file
154
nested_projects/test/unit/repository_test.rb
Normal file
@@ -0,0 +1,154 @@
|
||||
# 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
|
||||
Setting.default_language = 'en'
|
||||
|
||||
# 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
|
||||
|
||||
def test_manual_user_mapping
|
||||
assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
|
||||
c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
|
||||
assert_nil c.user
|
||||
@repository.committer_ids = {'foo' => '2'}
|
||||
assert_equal User.find(2), c.reload.user
|
||||
# committer is now mapped
|
||||
c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.')
|
||||
assert_equal User.find(2), c.user
|
||||
end
|
||||
end
|
||||
|
||||
def test_auto_user_mapping_by_username
|
||||
c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
|
||||
assert_equal User.find(2), c.user
|
||||
end
|
||||
|
||||
def test_auto_user_mapping_by_email
|
||||
c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
|
||||
assert_equal User.find(2), c.user
|
||||
end
|
||||
end
|
||||
53
nested_projects/test/unit/role_test.rb
Normal file
53
nested_projects/test/unit/role_test.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
# 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
|
||||
|
||||
def test_add_permission
|
||||
role = Role.find(1)
|
||||
size = role.permissions.size
|
||||
role.add_permission!("apermission", "anotherpermission")
|
||||
role.reload
|
||||
assert role.permissions.include?(:anotherpermission)
|
||||
assert_equal size + 2, role.permissions.size
|
||||
end
|
||||
|
||||
def test_remove_permission
|
||||
role = Role.find(1)
|
||||
size = role.permissions.size
|
||||
perm = role.permissions[0..1]
|
||||
role.remove_permission!(*perm)
|
||||
role.reload
|
||||
assert ! role.permissions.include?(perm[0])
|
||||
assert_equal size - 2, role.permissions.size
|
||||
end
|
||||
|
||||
end
|
||||
143
nested_projects/test/unit/search_test.rb
Normal file
143
nested_projects/test/unit/search_test.rb
Normal file
@@ -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
|
||||
45
nested_projects/test/unit/setting_test.rb
Normal file
45
nested_projects/test/unit/setting_test.rb
Normal file
@@ -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
|
||||
33
nested_projects/test/unit/subversion_adapter_test.rb
Normal file
33
nested_projects/test/unit/subversion_adapter_test.rb
Normal file
@@ -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
|
||||
46
nested_projects/test/unit/time_entry_test.rb
Normal file
46
nested_projects/test/unit/time_entry_test.rb
Normal file
@@ -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
|
||||
29
nested_projects/test/unit/token_test.rb
Normal file
29
nested_projects/test/unit/token_test.rb
Normal file
@@ -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
|
||||
33
nested_projects/test/unit/tracker_test.rb
Normal file
33
nested_projects/test/unit/tracker_test.rb
Normal file
@@ -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
|
||||
43
nested_projects/test/unit/user_preference_test.rb
Normal file
43
nested_projects/test/unit/user_preference_test.rb
Normal file
@@ -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
|
||||
167
nested_projects/test/unit/user_test.rb
Normal file
167
nested_projects/test/unit/user_test.rb
Normal file
@@ -0,0 +1,167 @@
|
||||
# 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_destroy
|
||||
User.find(2).destroy
|
||||
assert_nil User.find_by_id(2)
|
||||
assert Member.find_all_by_user_id(2).empty?
|
||||
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.reload.name
|
||||
Setting.user_format = :username
|
||||
assert_equal 'jsmith', @jsmith.reload.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
|
||||
|
||||
def test_find_by_mail_should_be_case_insensitive
|
||||
u = User.find_by_mail('JSmith@somenet.foo')
|
||||
assert_not_nil u
|
||||
assert_equal 'jsmith@somenet.foo', u.mail
|
||||
end
|
||||
end
|
||||
36
nested_projects/test/unit/version_test.rb
Normal file
36
nested_projects/test/unit/version_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# 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 VersionTest < Test::Unit::TestCase
|
||||
fixtures :projects, :issues, :issue_statuses, :versions
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_create
|
||||
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '2011-03-25')
|
||||
assert v.save
|
||||
end
|
||||
|
||||
def test_invalid_effective_date_validation
|
||||
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
|
||||
assert !v.save
|
||||
assert_equal 'activerecord_error_not_a_date', v.errors.on(:effective_date)
|
||||
end
|
||||
end
|
||||
69
nested_projects/test/unit/watcher_test.rb
Normal file
69
nested_projects/test/unit/watcher_test.rb
Normal file
@@ -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
|
||||
60
nested_projects/test/unit/wiki_content_test.rb
Normal file
60
nested_projects/test/unit/wiki_content_test.rb
Normal file
@@ -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
|
||||
103
nested_projects/test/unit/wiki_page_test.rb
Normal file
103
nested_projects/test/unit/wiki_page_test.rb
Normal file
@@ -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
|
||||
73
nested_projects/test/unit/wiki_redirect_test.rb
Normal file
73
nested_projects/test/unit/wiki_redirect_test.rb
Normal file
@@ -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
|
||||
44
nested_projects/test/unit/wiki_test.rb
Normal file
44
nested_projects/test/unit/wiki_test.rb
Normal file
@@ -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