summaryrefslogtreecommitdiffstats
path: root/test
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
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')
-rw-r--r--test/fixtures/enumerations.yml23
-rw-r--r--test/fixtures/issues.yml4
-rw-r--r--test/functional/issues_controller_test.rb4
-rw-r--r--test/integration/issues_test.rb2
-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
9 files changed, 158 insertions, 25 deletions
diff --git a/test/fixtures/enumerations.yml b/test/fixtures/enumerations.yml
index 22a581ab9..6e7983e8a 100644
--- a/test/fixtures/enumerations.yml
+++ b/test/fixtures/enumerations.yml
@@ -3,46 +3,67 @@ enumerations_001:
name: Uncategorized
id: 1
opt: DCAT
+ type: DocumentCategory
enumerations_002:
name: User documentation
id: 2
opt: DCAT
+ type: DocumentCategory
enumerations_003:
name: Technical documentation
id: 3
opt: DCAT
+ type: DocumentCategory
enumerations_004:
name: Low
id: 4
opt: IPRI
+ type: IssuePriority
enumerations_005:
name: Normal
id: 5
opt: IPRI
+ type: IssuePriority
is_default: true
enumerations_006:
name: High
id: 6
opt: IPRI
+ type: IssuePriority
enumerations_007:
name: Urgent
id: 7
opt: IPRI
+ type: IssuePriority
enumerations_008:
name: Immediate
id: 8
opt: IPRI
+ type: IssuePriority
enumerations_009:
name: Design
id: 9
opt: ACTI
+ type: TimeEntryActivity
enumerations_010:
name: Development
id: 10
opt: ACTI
+ type: TimeEntryActivity
is_default: true
enumerations_011:
name: QA
id: 11
opt: ACTI
- \ No newline at end of file
+ type: TimeEntryActivity
+enumerations_012:
+ name: Default Enumeration
+ id: 12
+ opt: ''
+ type: Enumeration
+ is_default: true
+enumerations_013:
+ name: Another Enumeration
+ id: 13
+ opt: ''
+ type: Enumeration
diff --git a/test/fixtures/issues.yml b/test/fixtures/issues.yml
index 856f80289..b66f2eb41 100644
--- a/test/fixtures/issues.yml
+++ b/test/fixtures/issues.yml
@@ -95,7 +95,7 @@ issues_007:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
- priority_id: 3
+ priority_id: 5
subject: Issue due today
id: 7
fixed_version_id:
@@ -112,7 +112,7 @@ issues_008:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
- priority_id: 3
+ priority_id: 5
subject: Closed issue
id: 8
fixed_version_id:
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 16c1a0804..95e75b43b 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -715,7 +715,7 @@ class IssuesControllerTest < Test::Unit::TestCase
:id => 1,
:issue => { :status_id => 2, :assigned_to_id => 3 },
:notes => 'Assigned to dlopper',
- :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
+ :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
end
assert_redirected_to :action => 'show', :id => '1'
issue.reload
@@ -753,7 +753,7 @@ class IssuesControllerTest < Test::Unit::TestCase
post :edit,
:id => 1,
:notes => '2.5 hours added',
- :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
+ :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first }
end
assert_redirected_to :action => 'show', :id => '1'
diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb
index 710fa5f76..9a73252b4 100644
--- a/test/integration/issues_test.rb
+++ b/test/integration/issues_test.rb
@@ -41,7 +41,7 @@ class IssuesTest < ActionController::IntegrationTest
post 'projects/1/issues', :tracker_id => "1",
:issue => { :start_date => "2006-12-26",
- :priority_id => "3",
+ :priority_id => "4",
:subject => "new test issue",
:category_id => "",
:description => "new issue",
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
+