diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-04-28 10:36:12 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-04-28 10:36:12 +0000 |
commit | 10191813ec9b5671ffd58008fcc832379f811009 (patch) | |
tree | 1238124192c80d6d53ccb907580394c5bd1b9f96 /test/unit | |
parent | be071deae29935ebb4dbcd3a7e445e290061b883 (diff) | |
download | redmine-10191813ec9b5671ffd58008fcc832379f811009.tar.gz redmine-10191813ec9b5671ffd58008fcc832379f811009.zip |
Merged r1307 to r1369 from trunk.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.7-stable@1370 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/changeset_test.rb | 12 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 25 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 9 | ||||
-rw-r--r-- | test/unit/project_test.rb | 9 | ||||
-rw-r--r-- | test/unit/query_test.rb | 36 | ||||
-rw-r--r-- | test/unit/repository_bazaar_test.rb | 4 | ||||
-rw-r--r-- | test/unit/repository_darcs_test.rb | 4 | ||||
-rw-r--r-- | test/unit/repository_mercurial_test.rb | 4 | ||||
-rw-r--r-- | test/unit/repository_subversion_test.rb | 4 | ||||
-rw-r--r-- | test/unit/time_entry_test.rb | 46 |
10 files changed, 130 insertions, 23 deletions
diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb index 2442a8b8c..bbfe6952d 100644 --- a/test/unit/changeset_test.rb +++ b/test/unit/changeset_test.rb @@ -41,22 +41,22 @@ class ChangesetTest < Test::Unit::TestCase end def test_previous - changeset = Changeset.find_by_revision(3) - assert_equal Changeset.find_by_revision(2), changeset.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) + 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 + 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) + changeset = Changeset.find_by_revision('4') assert_nil changeset.next end end diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 66499c003..fa2109131 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/../../test_helper' class ApplicationHelperTest < HelperTestCase include ApplicationHelper include ActionView::Helpers::TextHelper - fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents + fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules def setup super @@ -134,8 +134,9 @@ class ApplicationHelperTest < HelperTestCase def test_html_tags to_test = { - "<div>content</div>" => "<p><div>content</div></p>", - "<script>some script;</script>" => "<p><script>some script;</script></p>", + "<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>", @@ -167,6 +168,24 @@ class ApplicationHelperTest < HelperTestCase assert_equal '<p>{{hello_world}}</p>', textilizable(text) end + def test_macro_include + @project = Project.find(1) + # include a page of the current project wiki + text = "{{include(Another page)}}" + assert textilizable(text).match(/This is a link to a ticket/) + + @project = nil + # include a page of a specific project wiki + text = "{{include(ecookbook:Another page)}}" + assert textilizable(text).match(/This is a link to a ticket/) + + text = "{{include(ecookbook:)}}" + assert textilizable(text).match(/CookBook documentation/) + + text = "{{include(unknowidentifier:somepage)}}" + assert textilizable(text).match(/Unknow project/) + end + def test_date_format_default today = Date.today Setting.date_format = '' diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 7712b764e..36ba1fb45 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -20,6 +20,13 @@ 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_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_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 @@ -48,6 +55,8 @@ class IssueTest < Test::Unit::TestCase IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) # And 3 is a dupe of 2 IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES) + # And 3 is a dupe of 1 (circular duplicates) + IssueRelation.create(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES) assert issue1.reload.duplicates.include?(issue2) diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index f7da6ecb5..9af68c231 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -18,7 +18,7 @@ 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
+ fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
def setup
@ecookbook = Project.find(1)
@@ -84,12 +84,15 @@ class ProjectTest < Test::Unit::TestCase 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 all members have been removed
- assert_equal 0, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
+ # 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
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index c00f47e5d..d291018fb 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -1,5 +1,5 @@ # redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# 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 @@ -18,12 +18,12 @@ require File.dirname(__FILE__) + '/../test_helper' class QueryTest < Test::Unit::TestCase - fixtures :projects, :users, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries + fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries def test_query_with_multiple_custom_fields query = Query.find(1) assert query.valid? - assert query.statement.include?("custom_values.value IN ('MySQL')") + assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')") issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement assert_equal 1, issues.length assert_equal Issue.find(3), issues.first @@ -41,4 +41,34 @@ class QueryTest < Test::Unit::TestCase c = q.columns.first assert q.has_column?(c) 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 diff --git a/test/unit/repository_bazaar_test.rb b/test/unit/repository_bazaar_test.rb index 15fcc8672..b7a3cf98e 100644 --- a/test/unit/repository_bazaar_test.rb +++ b/test/unit/repository_bazaar_test.rb @@ -36,13 +36,13 @@ class RepositoryBazaarTest < Test::Unit::TestCase assert_equal 4, @repository.changesets.count assert_equal 9, @repository.changes.count - assert_equal 'Initial import', @repository.changesets.find_by_revision(1).comments + 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, :conditions => 'revision > 2').each(&:destroy) + @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} @repository.reload assert_equal 2, @repository.changesets.count diff --git a/test/unit/repository_darcs_test.rb b/test/unit/repository_darcs_test.rb index 1228976f1..1c8c1b8dd 100644 --- a/test/unit/repository_darcs_test.rb +++ b/test/unit/repository_darcs_test.rb @@ -35,13 +35,13 @@ class RepositoryDarcsTest < Test::Unit::TestCase assert_equal 6, @repository.changesets.count assert_equal 13, @repository.changes.count - assert_equal "Initial commit.", @repository.changesets.find_by_revision(1).comments + 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, :conditions => 'revision > 3').each(&:destroy) + @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3} @repository.reload assert_equal 3, @repository.changesets.count diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb index e6cfdf9b2..21ddf1e3a 100644 --- a/test/unit/repository_mercurial_test.rb +++ b/test/unit/repository_mercurial_test.rb @@ -35,13 +35,13 @@ class RepositoryMercurialTest < Test::Unit::TestCase 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 + 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, :conditions => 'revision > 2').each(&:destroy) + @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} @repository.reload assert_equal 3, @repository.changesets.count diff --git a/test/unit/repository_subversion_test.rb b/test/unit/repository_subversion_test.rb index 879feece8..7a1c9df4a 100644 --- a/test/unit/repository_subversion_test.rb +++ b/test/unit/repository_subversion_test.rb @@ -35,13 +35,13 @@ class RepositorySubversionTest < Test::Unit::TestCase assert_equal 8, @repository.changesets.count assert_equal 16, @repository.changes.count - assert_equal 'Initial import.', @repository.changesets.find_by_revision(1).comments + 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, :conditions => 'revision > 5').each(&:destroy) + @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} @repository.reload assert_equal 5, @repository.changesets.count diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb new file mode 100644 index 000000000..f86e42eab --- /dev/null +++ b/test/unit/time_entry_test.rb @@ -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 |