summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-05-30 23:30:36 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-05-30 23:30:36 +0000
commit62e58f26b0c6905fc0b2d79ed278ac0e4f55d793 (patch)
tree6989cbc655e9ffee0db9b7558985cd77d28b0edb /test/unit
parentfbfb34949677c41734531a552547fb216537999f (diff)
downloadredmine-62e58f26b0c6905fc0b2d79ed278ac0e4f55d793.tar.gz
redmine-62e58f26b0c6905fc0b2d79ed278ac0e4f55d793.zip
Changed Enumerations to use a Single Table Inheritance
* Added migrations to change Enumerations to an STI relationship * Added TimeEntryActivity model (STI) * Added DocumentCategory model (STI) * Added IssuePriority model (STI) * Added Enumeration#get_subclasses to get a list of the subclasses of Enumeration * Changed Enumeration to use the STI type field instead of the opt field * Changed Enumeration#opt to return the old opt values but with a deprecation warning. * Removed Enumeration::OPTIONS * Removed the dynamic named_scopes in favor of specific named_scopes. Kept for compatibility reasons. * Added Enumeration#default so each subclass can easily find it's default record. * Fixed Enumeration#default to use the STI scoping with a fake default scope for finding Enumeration's default. * Added a 'all' named scope for getting all records in order by position. * Added Deprecation warnings to the old named_scopes in Enumerations. * Moved various methods off of Enumeration and onto the concrete classes * Changed the EnumerationsController to use types * Updated the Enumeration list template * Added has_many relationships to the Enumeration STI classes. * Fixes for tests. #3007 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2777 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/document_category_test.rb36
-rw-r--r--test/unit/enumeration_test.rb28
-rw-r--r--test/unit/issue_priority_test.rb38
-rw-r--r--test/unit/issue_test.rb12
-rw-r--r--test/unit/time_entry_activity_test.rb36
5 files changed, 131 insertions, 19 deletions
diff --git a/test/unit/document_category_test.rb b/test/unit/document_category_test.rb
new file mode 100644
index 000000000..6fa93a371
--- /dev/null
+++ b/test/unit/document_category_test.rb
@@ -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 DocumentCategoryTest < Test::Unit::TestCase
+ fixtures :enumerations, :documents
+
+ def test_should_be_an_enumeration
+ assert DocumentCategory.ancestors.include?(Enumeration)
+ end
+
+ def test_objects_count
+ assert_equal 1, DocumentCategory.find_by_name("Uncategorized").objects_count
+ assert_equal 0, DocumentCategory.find_by_name("User documentation").objects_count
+ end
+
+ def test_option_name
+ assert_equal :enumeration_doc_categories, DocumentCategory.new.option_name
+ end
+end
+
diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb
index c192cee8f..14ea5e25c 100644
--- a/test/unit/enumeration_test.rb
+++ b/test/unit/enumeration_test.rb
@@ -38,40 +38,42 @@ class EnumerationTest < Test::Unit::TestCase
end
def test_default
- e = Enumeration.priorities.default
+ e = Enumeration.default
assert e.is_a?(Enumeration)
assert e.is_default?
- assert_equal 'Normal', e.name
+ assert_equal 'Default Enumeration', e.name
end
def test_create
- e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => false)
+ e = Enumeration.new(:name => 'Not default', :is_default => false)
+ e.type = 'Enumeration'
assert e.save
- assert_equal 'Normal', Enumeration.priorities.default.name
+ assert_equal 'Default Enumeration', Enumeration.default.name
end
def test_create_as_default
- e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => true)
+ e = Enumeration.new(:name => 'Very urgent', :is_default => true)
+ e.type = 'Enumeration'
assert e.save
- assert_equal e, Enumeration.priorities.default
+ assert_equal e, Enumeration.default
end
def test_update_default
- e = Enumeration.priorities.default
+ e = Enumeration.default
e.update_attributes(:name => 'Changed', :is_default => true)
- assert_equal e, Enumeration.priorities.default
+ assert_equal e, Enumeration.default
end
def test_update_default_to_non_default
- e = Enumeration.priorities.default
+ e = Enumeration.default
e.update_attributes(:name => 'Changed', :is_default => false)
- assert_nil Enumeration.priorities.default
+ assert_nil Enumeration.default
end
def test_change_default
- e = Enumeration.find_by_name('Urgent')
- e.update_attributes(:name => 'Urgent', :is_default => true)
- assert_equal e, Enumeration.priorities.default
+ e = Enumeration.find_by_name('Default Enumeration')
+ e.update_attributes(:name => 'Changed Enumeration', :is_default => true)
+ assert_equal e, Enumeration.default
end
def test_destroy_with_reassign
diff --git a/test/unit/issue_priority_test.rb b/test/unit/issue_priority_test.rb
new file mode 100644
index 000000000..e2da1e82d
--- /dev/null
+++ b/test/unit/issue_priority_test.rb
@@ -0,0 +1,38 @@
+# 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 IssuePriorityTest < Test::Unit::TestCase
+ fixtures :enumerations, :issues
+
+ def test_should_be_an_enumeration
+ assert IssuePriority.ancestors.include?(Enumeration)
+ end
+
+ def test_objects_count
+ # low priority
+ assert_equal 5, IssuePriority.find(4).objects_count
+ # urgent
+ assert_equal 0, IssuePriority.find(7).objects_count
+ end
+
+ def test_option_name
+ assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name
+ end
+end
+
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index d836f2bb5..b2eee22b9 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -27,14 +27,14 @@ class IssueTest < Test::Unit::TestCase
:time_entries
def test_create
- issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30')
+ issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.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_minimal
- issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'test_create')
+ issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create')
assert issue.save
assert issue.description.nil?
end
@@ -123,7 +123,7 @@ class IssueTest < Test::Unit::TestCase
end
def test_category_based_assignment
- issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
+ issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
end
@@ -139,7 +139,7 @@ class IssueTest < Test::Unit::TestCase
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.priorities.first, :subject => 'Duplicates test', :description => 'Duplicates test')
+ issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
assert issue1.save
issue2 = issue1.clone
assert issue2.save
@@ -166,7 +166,7 @@ class IssueTest < Test::Unit::TestCase
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.priorities.first, :subject => 'Duplicates test', :description => 'Duplicates test')
+ issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
assert issue1.save
issue2 = issue1.clone
assert issue2.save
@@ -248,7 +248,7 @@ class IssueTest < Test::Unit::TestCase
def test_create_should_send_email_notification
ActionMailer::Base.deliveries.clear
- issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'test_create', :estimated_hours => '1:30')
+ issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30')
assert issue.save
assert_equal 1, ActionMailer::Base.deliveries.size
diff --git a/test/unit/time_entry_activity_test.rb b/test/unit/time_entry_activity_test.rb
new file mode 100644
index 000000000..f99c8ab4e
--- /dev/null
+++ b/test/unit/time_entry_activity_test.rb
@@ -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 TimeEntryActivityTest < Test::Unit::TestCase
+ fixtures :enumerations, :time_entries
+
+ def test_should_be_an_enumeration
+ assert TimeEntryActivity.ancestors.include?(Enumeration)
+ end
+
+ def test_objects_count
+ assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
+ assert_equal 1, TimeEntryActivity.find_by_name("Development").objects_count
+ end
+
+ def test_option_name
+ assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
+ end
+end
+