@@ -54,7 +54,7 class DocumentsController < ApplicationController | |||
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def edit |
|
57 |
@categories = Enumeration |
|
|
57 | @categories = Enumeration.document_categories | |
|
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 |
@@ -85,7 +85,7 class EnumerationsController < ApplicationController | |||
|
85 | 85 | redirect_to :action => 'index' |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 |
@enumerations = Enumeration. |
|
|
88 | @enumerations = Enumeration.values(@enumeration.opt) - [@enumeration] | |
|
89 | 89 | #rescue |
|
90 | 90 | # flash[:error] = 'Unable to delete enumeration' |
|
91 | 91 | # redirect_to :action => 'index' |
@@ -100,7 +100,7 class IssuesController < ApplicationController | |||
|
100 | 100 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
101 | 101 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
102 | 102 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
103 |
@priorities = Enumeration |
|
|
103 | @priorities = Enumeration.priorities | |
|
104 | 104 | @time_entry = TimeEntry.new |
|
105 | 105 | respond_to do |format| |
|
106 | 106 | format.html { render :template => 'issues/show.rhtml' } |
@@ -153,7 +153,7 class IssuesController < ApplicationController | |||
|
153 | 153 | return |
|
154 | 154 | end |
|
155 | 155 | end |
|
156 |
@priorities = Enumeration |
|
|
156 | @priorities = Enumeration.priorities | |
|
157 | 157 | render :layout => !request.xhr? |
|
158 | 158 | end |
|
159 | 159 | |
@@ -163,7 +163,7 class IssuesController < ApplicationController | |||
|
163 | 163 | |
|
164 | 164 | def edit |
|
165 | 165 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
166 |
@priorities = Enumeration |
|
|
166 | @priorities = Enumeration.priorities | |
|
167 | 167 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
168 | 168 | @time_entry = TimeEntry.new |
|
169 | 169 | |
@@ -403,7 +403,7 class IssuesController < ApplicationController | |||
|
403 | 403 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
404 | 404 | end |
|
405 | 405 | |
|
406 |
@priorities = Enumeration. |
|
|
406 | @priorities = Enumeration.priorities.reverse | |
|
407 | 407 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
408 | 408 | @back = request.env['HTTP_REFERER'] |
|
409 | 409 |
@@ -37,7 +37,7 class ReportsController < ApplicationController | |||
|
37 | 37 | render :template => "reports/issue_report_details" |
|
38 | 38 | when "priority" |
|
39 | 39 | @field = "priority_id" |
|
40 |
@rows = Enumeration |
|
|
40 | @rows = Enumeration.priorities | |
|
41 | 41 | @data = issues_by_priority |
|
42 | 42 | @report_title = l(:field_priority) |
|
43 | 43 | render :template => "reports/issue_report_details" |
@@ -68,7 +68,7 class ReportsController < ApplicationController | |||
|
68 | 68 | else |
|
69 | 69 | @trackers = @project.trackers |
|
70 | 70 | @versions = @project.versions.sort |
|
71 |
@priorities = Enumeration |
|
|
71 | @priorities = Enumeration.priorities | |
|
72 | 72 | @categories = @project.issue_categories |
|
73 | 73 | @assignees = @project.members.collect { |m| m.user } |
|
74 | 74 | @authors = @project.members.collect { |m| m.user } |
@@ -27,7 +27,7 module TimelogHelper | |||
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def activity_collection_for_select_options |
|
30 |
activities = Enumeration |
|
|
30 | activities = Enumeration.activities | |
|
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] } |
@@ -31,7 +31,7 class Document < ActiveRecord::Base | |||
|
31 | 31 | |
|
32 | 32 | def after_initialize |
|
33 | 33 | if new_record? |
|
34 |
self.category ||= Enumeration.default |
|
|
34 | self.category ||= Enumeration.document_categories.default | |
|
35 | 35 | end |
|
36 | 36 | end |
|
37 | 37 | end |
@@ -26,17 +26,29 class Enumeration < ActiveRecord::Base | |||
|
26 | 26 | |
|
27 | 27 | # Single table inheritance would be an option |
|
28 | 28 | OPTIONS = { |
|
29 | "IPRI" => {:label => :enumeration_issue_priorities, :model => Issue, :foreign_key => :priority_id}, | |
|
30 | "DCAT" => {:label => :enumeration_doc_categories, :model => Document, :foreign_key => :category_id}, | |
|
31 | "ACTI" => {:label => :enumeration_activities, :model => TimeEntry, :foreign_key => :activity_id} | |
|
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 | 32 | }.freeze |
|
33 | 33 | |
|
34 | def self.get_values(option) | |
|
35 | find(:all, :conditions => {:opt => option}, :order => 'position') | |
|
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 | |
|
45 | end | |
|
36 | 46 | end |
|
37 | 47 | |
|
38 | def self.default(option) | |
|
39 | find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position') | |
|
48 | named_scope :values, lambda {|opt| { :conditions => { :opt => opt }, :order => 'position' } } do | |
|
49 | def default | |
|
50 | find(:first, :conditions => { :is_default => true }) | |
|
51 | end | |
|
40 | 52 | end |
|
41 | 53 | |
|
42 | 54 | def option_name |
@@ -63,7 +63,7 class Issue < ActiveRecord::Base | |||
|
63 | 63 | if new_record? |
|
64 | 64 | # set default values for new records only |
|
65 | 65 | self.status ||= IssueStatus.default |
|
66 |
self.priority ||= Enumeration.default |
|
|
66 | self.priority ||= Enumeration.priorities.default | |
|
67 | 67 | end |
|
68 | 68 | end |
|
69 | 69 |
@@ -37,7 +37,7 class TimeEntry < ActiveRecord::Base | |||
|
37 | 37 | |
|
38 | 38 | def after_initialize |
|
39 | 39 | if new_record? && self.activity.nil? |
|
40 |
if default_activity = Enumeration.default |
|
|
40 | if default_activity = Enumeration.activities.default | |
|
41 | 41 | self.activity_id = default_activity.id |
|
42 | 42 | end |
|
43 | 43 | end |
@@ -2,7 +2,7 | |||
|
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. |
|
|
5 | <%= select('document', 'category_id', Enumeration.document_categories.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> |
@@ -3,7 +3,7 | |||
|
3 | 3 | <% Enumeration::OPTIONS.each do |option, params| %> |
|
4 | 4 | <h3><%= l(params[:label]) %></h3> |
|
5 | 5 | |
|
6 |
<% enumerations = Enumeration. |
|
|
6 | <% enumerations = Enumeration.values(option) %> | |
|
7 | 7 | <% if enumerations.any? %> |
|
8 | 8 | <table class="list"> |
|
9 | 9 | <% enumerations.each do |enumeration| %> |
@@ -13,7 +13,7 | |||
|
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. |
|
|
16 | <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.priorities, :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') + |
@@ -40,7 +40,7 task :migrate_from_mantis => :environment do | |||
|
40 | 40 | 90 => closed_status # closed |
|
41 | 41 | } |
|
42 | 42 | |
|
43 |
priorities = Enumeration. |
|
|
43 | priorities = Enumeration.priorities | |
|
44 | 44 | DEFAULT_PRIORITY = priorities[2] |
|
45 | 45 | PRIORITY_MAPPING = {10 => priorities[1], # none |
|
46 | 46 | 20 => priorities[1], # low |
@@ -37,7 +37,7 namespace :redmine do | |||
|
37 | 37 | 'closed' => closed_status |
|
38 | 38 | } |
|
39 | 39 | |
|
40 |
priorities = Enumeration. |
|
|
40 | priorities = Enumeration.priorities | |
|
41 | 41 | DEFAULT_PRIORITY = priorities[0] |
|
42 | 42 | PRIORITY_MAPPING = {'lowest' => priorities[0], |
|
43 | 43 | 'low' => priorities[0], |
@@ -640,7 +640,7 class IssuesControllerTest < Test::Unit::TestCase | |||
|
640 | 640 | :id => 1, |
|
641 | 641 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
642 | 642 | :notes => 'Assigned to dlopper', |
|
643 |
:time_entry => { :hours => '', :comments => '', :activity_id => Enumeration. |
|
|
643 | :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first } | |
|
644 | 644 | end |
|
645 | 645 | assert_redirected_to :action => 'show', :id => '1' |
|
646 | 646 | issue.reload |
@@ -676,7 +676,7 class IssuesControllerTest < Test::Unit::TestCase | |||
|
676 | 676 | post :edit, |
|
677 | 677 | :id => 1, |
|
678 | 678 | :notes => '2.5 hours added', |
|
679 |
:time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration. |
|
|
679 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first } | |
|
680 | 680 | end |
|
681 | 681 | assert_redirected_to :action => 'show', :id => '1' |
|
682 | 682 |
@@ -38,7 +38,7 class EnumerationTest < Test::Unit::TestCase | |||
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_default |
|
41 |
e = Enumeration.default |
|
|
41 | e = Enumeration.priorities.default | |
|
42 | 42 | assert e.is_a?(Enumeration) |
|
43 | 43 | assert e.is_default? |
|
44 | 44 | assert_equal 'Normal', e.name |
@@ -47,31 +47,31 class EnumerationTest < Test::Unit::TestCase | |||
|
47 | 47 | def test_create |
|
48 | 48 | e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => false) |
|
49 | 49 | assert e.save |
|
50 |
assert_equal 'Normal', Enumeration.default |
|
|
50 | assert_equal 'Normal', Enumeration.priorities.default.name | |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_create_as_default |
|
54 | 54 | e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => true) |
|
55 | 55 | assert e.save |
|
56 |
assert_equal e, Enumeration.default |
|
|
56 | assert_equal e, Enumeration.priorities.default | |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def test_update_default |
|
60 |
e = Enumeration.default |
|
|
60 | e = Enumeration.priorities.default | |
|
61 | 61 | e.update_attributes(:name => 'Changed', :is_default => true) |
|
62 |
assert_equal e, Enumeration.default |
|
|
62 | assert_equal e, Enumeration.priorities.default | |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def test_update_default_to_non_default |
|
66 |
e = Enumeration.default |
|
|
66 | e = Enumeration.priorities.default | |
|
67 | 67 | e.update_attributes(:name => 'Changed', :is_default => false) |
|
68 |
assert_nil Enumeration.default |
|
|
68 | assert_nil Enumeration.priorities.default | |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def test_change_default |
|
72 | 72 | e = Enumeration.find_by_name('Urgent') |
|
73 | 73 | e.update_attributes(:name => 'Urgent', :is_default => true) |
|
74 |
assert_equal e, Enumeration.default |
|
|
74 | assert_equal e, Enumeration.priorities.default | |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def test_destroy_with_reassign |
@@ -27,14 +27,14 class IssueTest < Test::Unit::TestCase | |||
|
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. |
|
|
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') | |
|
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. |
|
|
37 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'test_create') | |
|
38 | 38 | assert issue.save |
|
39 | 39 | assert issue.description.nil? |
|
40 | 40 | end |
@@ -110,7 +110,7 class IssueTest < Test::Unit::TestCase | |||
|
110 | 110 | end |
|
111 | 111 | |
|
112 | 112 | def test_category_based_assignment |
|
113 |
issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration. |
|
|
113 | 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) | |
|
114 | 114 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
115 | 115 | end |
|
116 | 116 | |
@@ -126,7 +126,7 class IssueTest < Test::Unit::TestCase | |||
|
126 | 126 | |
|
127 | 127 | def test_should_close_duplicates |
|
128 | 128 | # Create 3 issues |
|
129 |
issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration. |
|
|
129 | 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') | |
|
130 | 130 | assert issue1.save |
|
131 | 131 | issue2 = issue1.clone |
|
132 | 132 | assert issue2.save |
@@ -153,7 +153,7 class IssueTest < Test::Unit::TestCase | |||
|
153 | 153 | |
|
154 | 154 | def test_should_not_close_duplicated_issue |
|
155 | 155 | # Create 3 issues |
|
156 |
issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration. |
|
|
156 | 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') | |
|
157 | 157 | assert issue1.save |
|
158 | 158 | issue2 = issue1.clone |
|
159 | 159 | assert issue2.save |
General Comments 0
You need to be logged in to leave comments.
Login now