enumeration-sti.patch

Patch to convert Enumerations to STI - for review - Eric Davis, 2009-03-25 22:50

Download (35.8 KB)

View differences:

app/controllers/documents_controller.rb
54 54
  end
55 55
  
56 56
  def edit
57
    @categories = Enumeration.document_categories
57
    @categories = DocumentCategory.all
58 58
    if request.post? and @document.update_attributes(params[:document])
59 59
      flash[:notice] = l(:notice_successful_update)
60 60
      redirect_to :action => 'show', :id => @document
app/controllers/enumerations_controller.rb
31 31
  end
32 32

  
33 33
  def new
34
    @enumeration = Enumeration.new(:opt => params[:opt])
34
    @enumeration = Enumeration.new(:type => params[:type])
35 35
  end
36 36

  
37 37
  def create
38 38
    @enumeration = Enumeration.new(params[:enumeration])
39 39
    if @enumeration.save
40 40
      flash[:notice] = l(:notice_successful_create)
41
      redirect_to :action => 'list', :opt => @enumeration.opt
41
      redirect_to :action => 'list', :type => @enumeration.type
42 42
    else
43 43
      render :action => 'new'
44 44
    end
......
52 52
    @enumeration = Enumeration.find(params[:id])
53 53
    if @enumeration.update_attributes(params[:enumeration])
54 54
      flash[:notice] = l(:notice_successful_update)
55
      redirect_to :action => 'list', :opt => @enumeration.opt
55
      redirect_to :action => 'list', :type => @enumeration.type
56 56
    else
57 57
      render :action => 'edit'
58 58
    end
......
65 65
      @enumeration.destroy
66 66
      redirect_to :action => 'index'
67 67
    elsif params[:reassign_to_id]
68
      if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
68
      if reassign_to = Enumeration.find_by_type_and_id(@enumeration.type, params[:reassign_to_id])
69 69
        @enumeration.destroy(reassign_to)
70 70
        redirect_to :action => 'index'
71 71
      end
72 72
    end
73
    @enumerations = Enumeration.values(@enumeration.opt) - [@enumeration]
73
    @enumerations = Enumeration.find(:all, :conditions => ['type = (?)', @enumeration.type]) - [@enumeration]
74 74
  #rescue
75 75
  #  flash[:error] = 'Unable to delete enumeration'
76 76
  #  redirect_to :action => 'index'
app/controllers/issues_controller.rb
102 102
    @changesets.reverse! if User.current.wants_comments_in_reverse_order?
103 103
    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
104 104
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
105
    @priorities = Enumeration.priorities
105
    @priorities = IssuePriority.all
106 106
    @time_entry = TimeEntry.new
107 107
    respond_to do |format|
108 108
      format.html { render :template => 'issues/show.rhtml' }
......
153 153
        return
154 154
      end		
155 155
    end	
156
    @priorities = Enumeration.priorities
156
    @priorities = IssuePriority.all
157 157
    render :layout => !request.xhr?
158 158
  end
159 159
  
......
163 163
  
164 164
  def edit
165 165
    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
166
    @priorities = Enumeration.priorities
166
    @priorities = IssuePriority.all
167 167
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
168 168
    @time_entry = TimeEntry.new
169 169
    
......
228 228
  def bulk_edit
229 229
    if request.post?
230 230
      status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
231
      priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
231
      priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
232 232
      assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
233 233
      category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
234 234
      fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
......
407 407
      @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
408 408
    end
409 409
    
410
    @priorities = Enumeration.priorities.reverse
410
    @priorities = IssuePriority.all.reverse
411 411
    @statuses = IssueStatus.find(:all, :order => 'position')
412 412
    @back = request.env['HTTP_REFERER']
413 413
    
app/controllers/reports_controller.rb
37 37
      render :template => "reports/issue_report_details"
38 38
    when "priority"
39 39
      @field = "priority_id"
40
      @rows = Enumeration.priorities
40
      @rows = IssuePriority.all
41 41
      @data = issues_by_priority
42 42
      @report_title = l(:field_priority)
43 43
      render :template => "reports/issue_report_details"   
......
68 68
    else
69 69
      @trackers = @project.trackers
70 70
      @versions = @project.versions.sort
71
      @priorities = Enumeration.priorities
71
      @priorities = IssuePriority.all
72 72
      @categories = @project.issue_categories
73 73
      @assignees = @project.members.collect { |m| m.user }
74 74
      @authors = @project.members.collect { |m| m.user }
......
130 130
                                                  p.id as priority_id,
131 131
                                                  count(i.id) as total 
132 132
                                                from 
133
                                                  #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Enumeration.table_name} p
133
                                                  #{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssuePriority.table_name} p
134 134
                                                where 
135 135
                                                  i.status_id=s.id 
136 136
                                                  and i.priority_id=p.id
app/controllers/timelog_controller.rb
46 46
                                          :klass => Tracker,
47 47
                                          :label => :label_tracker},
48 48
                             'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
49
                                           :klass => Enumeration,
49
                                           :klass => Activity,
50 50
                                           :label => :label_activity},
51 51
                             'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
52 52
                                         :klass => Issue,
app/helpers/issues_helper.rb
78 78
        u = User.find_by_id(detail.value) and value = u.name if detail.value
79 79
        u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
80 80
      when 'priority_id'
81
        e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value
82
        e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
81
        e = IssuePriority.find_by_id(detail.value) and value = e.name if detail.value
82
        e = IssuePriority.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
83 83
      when 'category_id'
84 84
        c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
85 85
        c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
app/helpers/timelog_helper.rb
27 27
  end
28 28
  
29 29
  def activity_collection_for_select_options
30
    activities = Enumeration.activities
30
    activities = Activity.all
31 31
    collection = []
32 32
    collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
33 33
    activities.each { |a| collection << [a.name, a.id] }
app/models/activity.rb
1
# redMine - project management software
2
# Copyright (C) 2006  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class Activity < Enumeration
19
  OptionName = :enumeration_activities
20
  
21
  def option_name
22
    OptionName
23
  end
24

  
25
  def objects_count
26
    TimeEntry.count(:conditions => "activity_id = #{id}")
27
  end
28

  
29
  def transfer_relations(to)
30
    TimeEntry.update_all("activity_id = #{to.id}", "activity_id = #{id}")
31
  end
32
end
app/models/document.rb
17 17

  
18 18
class Document < ActiveRecord::Base
19 19
  belongs_to :project
20
  belongs_to :category, :class_name => "Enumeration", :foreign_key => "category_id"
20
  belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
21 21
  acts_as_attachable :delete_permission => :manage_documents
22 22

  
23 23
  acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
......
31 31
  
32 32
  def after_initialize
33 33
    if new_record?
34
      self.category ||= Enumeration.document_categories.default
34
      self.category ||= DocumentCategory.default
35 35
    end
36 36
  end
37 37
end
app/models/document_category.rb
1
# redMine - project management software
2
# Copyright (C) 2006  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class DocumentCategory < Enumeration
19
  OptionName = :enumeration_doc_categories
20

  
21
  def option_name
22
    OptionName
23
  end
24

  
25
  def objects_count
26
    Document.count(:conditions => "category_id = #{id}")
27
  end
28

  
29
  def transfer_relations(to)
30
    Document.update_all("category_id = #{to.id}", "category_id = #{id}")
31
  end
32
end
app/models/enumeration.rb
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 17

  
18 18
class Enumeration < ActiveRecord::Base
19
  acts_as_list :scope => 'opt = \'#{opt}\''
19
  acts_as_list :scope => 'type = \'#{type}\''
20 20

  
21 21
  before_destroy :check_integrity
22 22
  
23
  validates_presence_of :opt, :name
24
  validates_uniqueness_of :name, :scope => [:opt]
23
  validates_presence_of :name
24
  validates_uniqueness_of :name, :scope => [:type]
25 25
  validates_length_of :name, :maximum => 30
26

  
27
  # Single table inheritance would be an option
28
  OPTIONS = {
29
    "IPRI" => {:label => :enumeration_issue_priorities, :model => Issue, :foreign_key => :priority_id, :scope => :priorities},
30
    "DCAT" => {:label => :enumeration_doc_categories, :model => Document, :foreign_key => :category_id, :scope => :document_categories},
31
    "ACTI" => {:label => :enumeration_activities, :model => TimeEntry, :foreign_key => :activity_id, :scope => :activities}
32
  }.freeze
33 26
  
34
  # Creates a named scope for each type of value. The scope has a +default+ method
35
  # that returns the default value, or nil if no value is set as default.
36
  # Example:
37
  #   Enumeration.priorities
38
  #   Enumeration.priorities.default
39
  OPTIONS.each do |k, v|
40
    next unless v[:scope]
41
    named_scope v[:scope], :conditions => { :opt => k }, :order => 'position' do
42
      def default
43
        find(:first, :conditions => { :is_default => true })
44
      end
27
  # Backwards compatiblity named_scopes.
28
  # Can be removed post-0.9
29
  named_scope :priorities, :conditions => { :type => "IssuePriority" }, :order => 'position' do
30
    ActiveSupport::Deprecation.warn("Enumeration#priorities is deprecated, use the IssuePriority class. (#{Redmine::Info.issue(3007)})")
31
    def default
32
      find(:first, :conditions => { :is_default => true })
33
    end
34
  end
35

  
36
  named_scope :document_categories, :conditions => { :type => "DocumentCategory" }, :order => 'position' do
37
    ActiveSupport::Deprecation.warn("Enumeration#document_categories is deprecated, use the DocumentCategories class. (#{Redmine::Info.issue(3007)})")
38
    def default
39
      find(:first, :conditions => { :is_default => true })
40
    end
41
  end
42

  
43
  named_scope :activities, :conditions => { :type => "Activity" }, :order => 'position' do
44
    ActiveSupport::Deprecation.warn("Enumeration#activities is deprecated, use the Activity class. (#{Redmine::Info.issue(3007)})")
45
    def default
46
      find(:first, :conditions => { :is_default => true })
45 47
    end
46 48
  end
47 49
  
48
  named_scope :values, lambda {|opt| { :conditions => { :opt => opt }, :order => 'position' } } do
50
  named_scope :values, lambda {|opt| { :conditions => { :type => type }, :order => 'position' } } do
49 51
    def default
50 52
      find(:first, :conditions => { :is_default => true })
51 53
    end
52 54
  end
53 55

  
56
  named_scope :all, :order => 'position'
57

  
58
  def self.default
59
    find(:first, :conditions => { :is_default => true })
60
  end
61
  
62
  # Overloaded on concrete classes
54 63
  def option_name
55
    OPTIONS[self.opt][:label]
64
    nil
56 65
  end
57 66

  
58 67
  def before_save
59 68
    if is_default? && is_default_changed?
60
      Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt})
69
      Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
61 70
    end
62 71
  end
63 72
  
73
  # Overloaded on concrete classes
64 74
  def objects_count
65
    OPTIONS[self.opt][:model].count(:conditions => "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
75
    0
66 76
  end
67 77
  
68 78
  def in_use?
......
75 85
  # If a enumeration is specified, objects are reassigned
76 86
  def destroy(reassign_to = nil)
77 87
    if reassign_to && reassign_to.is_a?(Enumeration)
78
      OPTIONS[self.opt][:model].update_all("#{OPTIONS[self.opt][:foreign_key]} = #{reassign_to.id}", "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
88
      self.transfer_relations(reassign_to)
79 89
    end
80 90
    destroy_without_reassign
81 91
  end
......
85 95
  end
86 96
  
87 97
  def to_s; name end
98

  
99
  # Returns the Subclasses of Enumeration.  Each Subclass needs to be
100
  # required in development mode.
101
  #
102
  # Note: subclasses is protected in ActiveRecord
103
  def self.get_subclasses
104
    @@subclasses[Enumeration]
105
  end
88 106
  
89 107
private
90 108
  def check_integrity
91 109
    raise "Can't delete enumeration" if self.in_use?
92 110
  end
111

  
93 112
end
113

  
114
# Force load the subclasses in development mode
115
require_dependency 'activity'
116
require_dependency 'document_category'
117
require_dependency 'issue_priority'
app/models/issue.rb
22 22
  belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
23 23
  belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
24 24
  belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
25
  belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
25
  belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
26 26
  belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
27 27

  
28 28
  has_many :journals, :as => :journalized, :dependent => :destroy
......
65 65
    if new_record?
66 66
      # set default values for new records only
67 67
      self.status ||= IssueStatus.default
68
      self.priority ||= Enumeration.priorities.default
68
      self.priority ||= IssuePriority.default
69 69
    end
70 70
  end
71 71
  
app/models/issue_priority.rb
1
# redMine - project management software
2
# Copyright (C) 2006  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class IssuePriority < Enumeration
19
  OptionName = :enumeration_issue_priorities
20

  
21
  def option_name
22
    OptionName
23
  end
24

  
25
  def objects_count
26
    Issue.count(:conditions => "priority_id = #{id}")
27
  end
28

  
29
  def transfer_relations(to)
30
    Issue.update_all("priority_id = #{to.id}", "priority_id = #{id}")
31
  end
32
end
app/models/mail_handler.rb
91 91
    project = target_project
92 92
    tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
93 93
    category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
94
    priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
94
    priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority)))
95 95
    status =  (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
96 96

  
97 97
    # check permission
app/models/query.rb
101 101
    QueryColumn.new(:project, :sortable => "#{Project.table_name}.name"),
102 102
    QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
103 103
    QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
104
    QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'),
104
    QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc'),
105 105
    QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
106 106
    QueryColumn.new(:author),
107 107
    QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname"]),
......
151 151
    
152 152
    @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },       
153 153
                           "tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },                                                                                                                
154
                           "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI'], :order => 'position').collect{|s| [s.name, s.id.to_s] } },
154
                           "priority_id" => { :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] } },
155 155
                           "subject" => { :type => :text, :order => 8 },  
156 156
                           "created_on" => { :type => :date_past, :order => 9 },                        
157 157
                           "updated_on" => { :type => :date_past, :order => 10 },
app/models/time_entry.rb
21 21
  belongs_to :project
22 22
  belongs_to :issue
23 23
  belongs_to :user
24
  belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
24
  belongs_to :activity
25 25
  
26 26
  attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
27 27

  
......
37 37

  
38 38
  def after_initialize
39 39
    if new_record? && self.activity.nil?
40
      if default_activity = Enumeration.activities.default
40
      if default_activity = Activity.default
41 41
        self.activity_id = default_activity.id
42 42
      end
43 43
    end
app/views/documents/_form.rhtml
2 2
<div class="box">
3 3
<!--[form:document]-->
4 4
<p><label for="document_category_id"><%=l(:field_category)%></label>
5
<%= select('document', 'category_id', Enumeration.document_categories.collect {|c| [c.name, c.id]}) %></p>
5
<%= select('document', 'category_id', DocumentCategory.all.collect {|c| [c.name, c.id]}) %></p>
6 6

  
7 7
<p><label for="document_title"><%=l(:field_title)%> <span class="required">*</span></label>
8 8
<%= text_field 'document', 'title', :size => 60 %></p>
app/views/enumerations/list.rhtml
1 1
<h2><%=l(:label_enumerations)%></h2>
2 2

  
3
<% Enumeration::OPTIONS.each do |option, params| %>
4
<h3><%= l(params[:label]) %></h3>
3
<% Enumeration.get_subclasses.each do |klass| %>
4
<h3><%= l(klass::OptionName) %></h3>
5 5

  
6
<% enumerations = Enumeration.values(option) %>
6
<% enumerations = klass.all %>
7 7
<% if enumerations.any? %>
8 8
<table class="list">
9 9
<% enumerations.each do |enumeration| %>
......
20 20
<% reset_cycle %>
21 21
<% end %>
22 22

  
23
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
23
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :type => klass.name } %></p>
24 24
<% end %>
25 25

  
26 26
<% html_title(l(:label_enumerations)) -%>
app/views/issues/bulk_edit.rhtml
13 13
<%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label>
14 14
<% end %>
15 15
<label><%= l(:field_priority) %>: 
16
<%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.priorities, :id, :name)) %></label>
16
<%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.all, :id, :name)) %></label>
17 17
<label><%= l(:field_category) %>: 
18 18
<%= select_tag('category_id', content_tag('option', l(:label_no_change_option), :value => '') +
19 19
                                content_tag('option', l(:label_none), :value => 'none') +
app/views/my/blocks/_issuesassignedtome.rhtml
4 4
                                :conditions => {:assigned_to_id => User.current.id},
5 5
                                :limit => 10, 
6 6
                                :include => [ :status, :project, :tracker, :priority ], 
7
                                :order => "#{Enumeration.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") %>
7
                                :order => "#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") %>
8 8
<%= render :partial => 'issues/list_simple', :locals => { :issues => assigned_issues } %>
9 9
<% if assigned_issues.length > 0 %>
10 10
<p class="small"><%= link_to l(:label_issue_view_all), :controller => 'issues',
db/migrate/20090323224724_change_enumeration_to_sti.rb
1
class ChangeEnumerationToSti < ActiveRecord::Migration
2
  def self.up
3
    add_column :enumerations, :type, :string
4
    Enumeration.reset_column_information
5

  
6
    Enumeration.update_all("type = 'IssuePriority'", "opt = 'IPRI'")
7
    Enumeration.update_all("type = 'DocumentCategory'", "opt = 'DCAT'")
8
    Enumeration.update_all("type = 'Activity'", "opt = 'ACTI'")
9
  end
10

  
11
  def self.down
12
    remove_column :enumerations, :type
13
  end
14
end
lib/redmine/info.rb
5 5
      def url; 'http://www.redmine.org/' end
6 6
      def help_url; 'http://www.redmine.org/guide' end
7 7
      def versioned_name; "#{app_name} #{Redmine::VERSION}" end
8

  
9
      # Creates the url string to a specific Redmine issue
10
      def issue(issue_id)
11
        url + 'issues/' + issue_id.to_s
12
      end
8 13
    end
9 14
  end
10 15
end
test/fixtures/enumerations.yml
3 3
  name: Uncategorized
4 4
  id: 1
5 5
  opt: DCAT
6
  type: DocumentCategory
6 7
enumerations_002: 
7 8
  name: User documentation
8 9
  id: 2
9 10
  opt: DCAT
11
  type: DocumentCategory
10 12
enumerations_003: 
11 13
  name: Technical documentation
12 14
  id: 3
13 15
  opt: DCAT
16
  type: DocumentCategory
14 17
enumerations_004: 
15 18
  name: Low
16 19
  id: 4
17 20
  opt: IPRI
21
  type: IssuePriority
18 22
enumerations_005: 
19 23
  name: Normal
20 24
  id: 5
21 25
  opt: IPRI
26
  type: IssuePriority
22 27
  is_default: true
23 28
enumerations_006: 
24 29
  name: High
25 30
  id: 6
26 31
  opt: IPRI
32
  type: IssuePriority
27 33
enumerations_007: 
28 34
  name: Urgent
29 35
  id: 7
30 36
  opt: IPRI
37
  type: IssuePriority
31 38
enumerations_008: 
32 39
  name: Immediate
33 40
  id: 8
34 41
  opt: IPRI
42
  type: IssuePriority
35 43
enumerations_009: 
36 44
  name: Design
37 45
  id: 9
38 46
  opt: ACTI
47
  type: Activity
39 48
enumerations_010: 
40 49
  name: Development
41 50
  id: 10
42 51
  opt: ACTI
52
  type: Activity
43 53
  is_default: true
44 54
enumerations_011: 
45 55
  name: QA
46 56
  id: 11
47 57
  opt: ACTI
48
  
58
  type: Activity
test/fixtures/issues.yml
95 95
  created_on: <%= 10.days.ago.to_date.to_s(:db) %>
96 96
  project_id: 1
97 97
  updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
98
  priority_id: 3
98
  priority_id: 5
99 99
  subject: Issue due today
100 100
  id: 7
101 101
  fixed_version_id: 
......
112 112
  created_on: <%= 10.days.ago.to_date.to_s(:db) %>
113 113
  project_id: 1
114 114
  updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
115
  priority_id: 3
115
  priority_id: 5
116 116
  subject: Closed issue
117 117
  id: 8
118 118
  fixed_version_id: 
test/functional/issues_controller_test.rb
670 670
           :id => 1,
671 671
           :issue => { :status_id => 2, :assigned_to_id => 3 },
672 672
           :notes => 'Assigned to dlopper',
673
           :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
673
           :time_entry => { :hours => '', :comments => '', :activity_id => Activity.first }
674 674
    end
675 675
    assert_redirected_to :action => 'show', :id => '1'
676 676
    issue.reload
......
706 706
      post :edit,
707 707
           :id => 1,
708 708
           :notes => '2.5 hours added',
709
           :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
709
           :time_entry => { :hours => '2.5', :comments => '', :activity_id => Activity.first }
710 710
    end
711 711
    assert_redirected_to :action => 'show', :id => '1'
712 712
    
test/integration/issues_test.rb
41 41
    
42 42
    post 'projects/1/issues', :tracker_id => "1",
43 43
                                 :issue => { :start_date => "2006-12-26", 
44
                                             :priority_id => "3", 
44
                                             :priority_id => "4", 
45 45
                                             :subject => "new test issue", 
46 46
                                             :category_id => "", 
47 47
                                             :description => "new issue", 
test/unit/enumeration_test.rb
38 38
  end
39 39
  
40 40
  def test_default
41
    e = Enumeration.priorities.default
41
    e = Enumeration.default
42 42
    assert e.is_a?(Enumeration)
43 43
    assert e.is_default?
44 44
    assert_equal 'Normal', e.name
45 45
  end
46 46
  
47 47
  def test_create
48
    e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => false)
48
    e = IssuePriority.new(:type => 'Priority', :name => 'Very urgent', :is_default => false)
49 49
    assert e.save
50
    assert_equal 'Normal', Enumeration.priorities.default.name
50
    assert_equal 'Normal', IssuePriority.default.name
51 51
  end
52 52
  
53 53
  def test_create_as_default
54
    e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => true)
54
    e = IssuePriority.new(:name => 'Very urgent', :is_default => true)
55 55
    assert e.save
56
    assert_equal e, Enumeration.priorities.default
56
    assert_equal e, IssuePriority.default
57 57
  end
58 58
  
59 59
  def test_update_default
60
    e = Enumeration.priorities.default
60
    e = IssuePriority.default
61 61
    e.update_attributes(:name => 'Changed', :is_default => true)
62
    assert_equal e, Enumeration.priorities.default
62
    assert_equal e, IssuePriority.default
63 63
  end
64 64
  
65 65
  def test_update_default_to_non_default
66
    e = Enumeration.priorities.default
66
    e = IssuePriority.default
67 67
    e.update_attributes(:name => 'Changed', :is_default => false)
68
    assert_nil Enumeration.priorities.default
68
    assert_nil IssuePriority.default
69 69
  end
70 70
  
71 71
  def test_change_default
72
    e = Enumeration.find_by_name('Urgent')
72
    e = IssuePriority.find_by_name('Urgent')
73 73
    e.update_attributes(:name => 'Urgent', :is_default => true)
74
    assert_equal e, Enumeration.priorities.default
74
    assert_equal e, IssuePriority.default
75 75
  end
76 76
  
77 77
  def test_destroy_with_reassign
test/unit/issue_test.rb
27 27
           :time_entries
28 28

  
29 29
  def test_create
30
    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')
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')
31 31
    assert issue.save
32 32
    issue.reload
33 33
    assert_equal 1.5, issue.estimated_hours
34 34
  end
35 35
  
36 36
  def test_create_minimal
37
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'test_create')
37
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create')
38 38
    assert issue.save
39 39
    assert issue.description.nil?
40 40
  end
......
123 123
  end
124 124
  
125 125
  def test_category_based_assignment
126
    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)
126
    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)
127 127
    assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
128 128
  end
129 129
  
......
139 139
  
140 140
  def test_should_close_duplicates
141 141
    # Create 3 issues
142
    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')
142
    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')
143 143
    assert issue1.save
144 144
    issue2 = issue1.clone
145 145
    assert issue2.save
......
166 166
  
167 167
  def test_should_not_close_duplicated_issue
168 168
    # Create 3 issues
169
    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')
169
    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')
170 170
    assert issue1.save
171 171
    issue2 = issue1.clone
172 172
    assert issue2.save