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