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
This commit is contained in:
Eric Davis
2009-05-30 23:30:36 +00:00
parent fbfb349496
commit 62e58f26b0
32 changed files with 394 additions and 89 deletions
+22 -1
View File
@@ -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
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
+2 -2
View File
@@ -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:
+2 -2
View File
@@ -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'
+1 -1
View File
@@ -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",
+36
View 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 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
+15 -13
View File
@@ -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
+38
View File
@@ -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
+6 -6
View File
@@ -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
+36
View 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 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