@@ -19,28 +19,19 class EnumerationsController < ApplicationController | |||||
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin |
|
21 | before_filter :require_admin | |
|
22 | before_filter :build_new_enumeration, :only => [:new, :create] | |||
|
23 | before_filter :find_enumeration, :only => [:edit, :update, :destroy] | |||
22 |
|
24 | |||
23 | helper :custom_fields |
|
25 | helper :custom_fields | |
24 | include CustomFieldsHelper |
|
|||
25 |
|
26 | |||
26 | def index |
|
27 | def index | |
27 | end |
|
28 | end | |
28 |
|
29 | |||
29 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
|||
30 | :redirect_to => { :action => :index } |
|
|||
31 |
|
||||
32 | def new |
|
30 | def new | |
33 | begin |
|
|||
34 | @enumeration = params[:type].constantize.new |
|
|||
35 | rescue NameError |
|
|||
36 | @enumeration = Enumeration.new |
|
|||
37 | end |
|
|||
38 | end |
|
31 | end | |
39 |
|
32 | |||
40 | def create |
|
33 | def create | |
41 | @enumeration = Enumeration.new(params[:enumeration]) |
|
34 | if request.post? && @enumeration.save | |
42 | @enumeration.type = params[:enumeration][:type] |
|
|||
43 | if @enumeration.save |
|
|||
44 | flash[:notice] = l(:notice_successful_create) |
|
35 | flash[:notice] = l(:notice_successful_create) | |
45 | redirect_to :action => 'index', :type => @enumeration.type |
|
36 | redirect_to :action => 'index', :type => @enumeration.type | |
46 | else |
|
37 | else | |
@@ -49,13 +40,10 class EnumerationsController < ApplicationController | |||||
49 | end |
|
40 | end | |
50 |
|
41 | |||
51 | def edit |
|
42 | def edit | |
52 | @enumeration = Enumeration.find(params[:id]) |
|
|||
53 | end |
|
43 | end | |
54 |
|
44 | |||
55 | def update |
|
45 | def update | |
56 | @enumeration = Enumeration.find(params[:id]) |
|
46 | if request.put? && @enumeration.update_attributes(params[:enumeration]) | |
57 | @enumeration.type = params[:enumeration][:type] if params[:enumeration][:type] |
|
|||
58 | if @enumeration.update_attributes(params[:enumeration]) |
|
|||
59 | flash[:notice] = l(:notice_successful_update) |
|
47 | flash[:notice] = l(:notice_successful_update) | |
60 | redirect_to :action => 'index', :type => @enumeration.type |
|
48 | redirect_to :action => 'index', :type => @enumeration.type | |
61 | else |
|
49 | else | |
@@ -63,8 +51,8 class EnumerationsController < ApplicationController | |||||
63 | end |
|
51 | end | |
64 | end |
|
52 | end | |
65 |
|
53 | |||
|
54 | verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed } | |||
66 | def destroy |
|
55 | def destroy | |
67 | @enumeration = Enumeration.find(params[:id]) |
|
|||
68 | if !@enumeration.in_use? |
|
56 | if !@enumeration.in_use? | |
69 | # No associated objects |
|
57 | # No associated objects | |
70 | @enumeration.destroy |
|
58 | @enumeration.destroy | |
@@ -77,9 +65,22 class EnumerationsController < ApplicationController | |||||
77 | return |
|
65 | return | |
78 | end |
|
66 | end | |
79 | end |
|
67 | end | |
80 |
@enumerations = @enumeration.class. |
|
68 | @enumerations = @enumeration.class.all - [@enumeration] | |
81 | #rescue |
|
69 | end | |
82 | # flash[:error] = 'Unable to delete enumeration' |
|
70 | ||
83 | # redirect_to :action => 'index' |
|
71 | private | |
|
72 | ||||
|
73 | def build_new_enumeration | |||
|
74 | class_name = params[:enumeration] && params[:enumeration][:type] || params[:type] | |||
|
75 | @enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration]) | |||
|
76 | if @enumeration.nil? | |||
|
77 | render_404 | |||
|
78 | end | |||
|
79 | end | |||
|
80 | ||||
|
81 | def find_enumeration | |||
|
82 | @enumeration = Enumeration.find(params[:id]) | |||
|
83 | rescue ActiveRecord::RecordNotFound | |||
|
84 | render_404 | |||
84 | end |
|
85 | end | |
85 | end |
|
86 | end |
@@ -16,6 +16,8 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Enumeration < ActiveRecord::Base |
|
18 | class Enumeration < ActiveRecord::Base | |
|
19 | include Redmine::SubclassFactory | |||
|
20 | ||||
19 | default_scope :order => "#{Enumeration.table_name}.position ASC" |
|
21 | default_scope :order => "#{Enumeration.table_name}.position ASC" | |
20 |
|
22 | |||
21 | belongs_to :project |
|
23 | belongs_to :project | |
@@ -27,6 +29,8 class Enumeration < ActiveRecord::Base | |||||
27 | before_destroy :check_integrity |
|
29 | before_destroy :check_integrity | |
28 | before_save :check_default |
|
30 | before_save :check_default | |
29 |
|
31 | |||
|
32 | attr_protected :type | |||
|
33 | ||||
30 | validates_presence_of :name |
|
34 | validates_presence_of :name | |
31 | validates_uniqueness_of :name, :scope => [:type, :project_id] |
|
35 | validates_uniqueness_of :name, :scope => [:type, :project_id] | |
32 | validates_length_of :name, :maximum => 30 |
|
36 | validates_length_of :name, :maximum => 30 |
@@ -1,19 +1,11 | |||||
1 | <%= error_messages_for 'enumeration' %> |
|
1 | <%= error_messages_for 'enumeration' %> | |
2 | <div class="box"> |
|
|||
3 | <!--[form:optvalue]--> |
|
|||
4 | <%= hidden_field 'enumeration', 'type' %> |
|
|||
5 |
|
2 | |||
6 | <p><label for="enumeration_name"><%=l(:field_name)%></label> |
|
3 | <div class="box tabular"> | |
7 |
<%= text_field |
|
4 | <p><%= f.text_field :name %></p> | |
|
5 | <p><%= f.check_box :active %></p> | |||
|
6 | <p><%= f.check_box :is_default %></p> | |||
8 |
|
7 | |||
9 | <p><label for="enumeration_active"><%=l(:field_active)%></label> |
|
8 | <% @enumeration.custom_field_values.each do |value| %> | |
10 | <%= check_box 'enumeration', 'active' %></p> |
|
9 | <p><%= custom_field_tag_with_label :enumeration, value %></p> | |
11 |
|
10 | <% end %> | ||
12 | <p><label for="enumeration_is_default"><%=l(:field_is_default)%></label> |
|
|||
13 | <%= check_box 'enumeration', 'is_default' %></p> |
|
|||
14 | <!--[eoform:optvalue]--> |
|
|||
15 |
|
||||
16 | <% @enumeration.custom_field_values.each do |value| %> |
|
|||
17 | <p><%= custom_field_tag_with_label :enumeration, value %></p> |
|
|||
18 | <% end %> |
|
|||
19 | </div> |
|
11 | </div> |
@@ -1,6 +1,6 | |||||
1 | <h2><%= l(@enumeration.option_name) %>: <%=h @enumeration %></h2> |
|
1 | <h2><%= l(@enumeration.option_name) %>: <%=h @enumeration %></h2> | |
2 |
|
2 | |||
3 | <% form_tag({}) do %> |
|
3 | <% form_tag({}, :method => :delete) do %> | |
4 | <div class="box"> |
|
4 | <div class="box"> | |
5 | <p><strong><%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %></strong></p> |
|
5 | <p><strong><%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %></strong></p> | |
6 | <p><label for='reassign_to_id'><%= l(:text_enumeration_category_reassign_to) %></label> |
|
6 | <p><label for='reassign_to_id'><%= l(:text_enumeration_category_reassign_to) %></label> | |
@@ -8,5 +8,5 | |||||
8 | </div> |
|
8 | </div> | |
9 |
|
9 | |||
10 | <%= submit_tag l(:button_apply) %> |
|
10 | <%= submit_tag l(:button_apply) %> | |
11 |
<%= link_to l(:button_cancel), |
|
11 | <%= link_to l(:button_cancel), enumerations_path %> | |
12 | <% end %> |
|
12 | <% end %> |
@@ -1,6 +1,6 | |||||
1 |
<h2><%= link_to l(@enumeration.option_name), |
|
1 | <h2><%= link_to l(@enumeration.option_name), enumerations_path %> » <%=h @enumeration %></h2> | |
2 |
|
2 | |||
3 | <% form_tag({:action => 'update', :id => @enumeration}, :class => "tabular") do %> |
|
3 | <% labelled_form_for :enumeration, @enumeration, :url => enumeration_path(@enumeration), :html => {:method => :put} do |f| %> | |
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'form', :locals => {:f => f} %> | |
5 | <%= submit_tag l(:button_save) %> |
|
5 | <%= submit_tag l(:button_save) %> | |
6 | <% end %> |
|
6 | <% end %> |
@@ -15,13 +15,13 | |||||
15 | </tr></thead> |
|
15 | </tr></thead> | |
16 | <% enumerations.each do |enumeration| %> |
|
16 | <% enumerations.each do |enumeration| %> | |
17 | <tr class="<%= cycle('odd', 'even') %>"> |
|
17 | <tr class="<%= cycle('odd', 'even') %>"> | |
18 |
<td><%= link_to h(enumeration), |
|
18 | <td><%= link_to h(enumeration), edit_enumeration_path(enumeration) %></td> | |
19 | <td class="center" style="width:15%;"><%= checked_image enumeration.is_default? %></td> |
|
19 | <td class="center" style="width:15%;"><%= checked_image enumeration.is_default? %></td> | |
20 | <td class="center" style="width:15%;"><%= checked_image enumeration.active? %></td> |
|
20 | <td class="center" style="width:15%;"><%= checked_image enumeration.active? %></td> | |
21 | <td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %></td> |
|
21 | <td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}, :put) %></td> | |
22 | <td class="buttons"> |
|
22 | <td class="buttons"> | |
23 |
<%= link_to l(:button_delete), |
|
23 | <%= link_to l(:button_delete), enumeration_path(enumeration), | |
24 |
:method => : |
|
24 | :method => :delete, | |
25 | :confirm => l(:text_are_you_sure), |
|
25 | :confirm => l(:text_are_you_sure), | |
26 | :class => 'icon icon-del' %> |
|
26 | :class => 'icon icon-del' %> | |
27 | </td> |
|
27 | </td> | |
@@ -31,7 +31,7 | |||||
31 | <% reset_cycle %> |
|
31 | <% reset_cycle %> | |
32 | <% end %> |
|
32 | <% end %> | |
33 |
|
33 | |||
34 |
<p><%= link_to l(:label_enumeration_new), |
|
34 | <p><%= link_to l(:label_enumeration_new), new_enumeration_path(:type => klass.name) %></p> | |
35 | <% end %> |
|
35 | <% end %> | |
36 |
|
36 | |||
37 | <% html_title(l(:label_enumerations)) -%> |
|
37 | <% html_title(l(:label_enumerations)) -%> |
@@ -1,6 +1,7 | |||||
1 |
<h2><%= link_to l(@enumeration.option_name), |
|
1 | <h2><%= link_to l(@enumeration.option_name), enumerations_path %> » <%=l(:label_enumeration_new)%></h2> | |
2 |
|
2 | |||
3 | <% form_tag({:action => 'create'}, :class => "tabular") do %> |
|
3 | <% labelled_form_for :enumeration, @enumeration, :url => enumerations_path do |f| %> | |
4 | <%= render :partial => 'form' %> |
|
4 | <%= f.hidden_field :type %> | |
|
5 | <%= render :partial => 'form', :locals => {:f => f} %> | |||
5 | <%= submit_tag l(:button_create) %> |
|
6 | <%= submit_tag l(:button_create) %> | |
6 | <% end %> |
|
7 | <% end %> |
@@ -212,6 +212,7 ActionController::Routing::Routes.draw do |map| | |||||
212 | map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post} |
|
212 | map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post} | |
213 | map.resources :custom_fields, :except => :show |
|
213 | map.resources :custom_fields, :except => :show | |
214 | map.resources :roles, :except => :show, :collection => {:permissions => [:get, :post]} |
|
214 | map.resources :roles, :except => :show, :collection => {:permissions => [:get, :post]} | |
|
215 | map.resources :enumerations, :except => :show | |||
215 |
|
216 | |||
216 | map.connect 'search', :controller => 'search', :action => 'index', :conditions => {:method => :get} |
|
217 | map.connect 'search', :controller => 'search', :action => 'index', :conditions => {:method => :get} | |
217 |
|
218 | |||
@@ -244,12 +245,6 ActionController::Routing::Routes.draw do |map| | |||||
244 | map.connect 'workflows', :controller => 'workflows', :action => 'index', :conditions => {:method => :get} |
|
245 | map.connect 'workflows', :controller => 'workflows', :action => 'index', :conditions => {:method => :get} | |
245 | map.connect 'workflows/edit', :controller => 'workflows', :action => 'edit', :conditions => {:method => [:get, :post]} |
|
246 | map.connect 'workflows/edit', :controller => 'workflows', :action => 'edit', :conditions => {:method => [:get, :post]} | |
246 | map.connect 'workflows/copy', :controller => 'workflows', :action => 'copy', :conditions => {:method => [:get, :post]} |
|
247 | map.connect 'workflows/copy', :controller => 'workflows', :action => 'copy', :conditions => {:method => [:get, :post]} | |
247 | map.connect 'enumerations', :controller => 'enumerations', :action => 'index', :conditions => {:method => :get} |
|
|||
248 | map.connect 'enumerations/new', :controller => 'enumerations', :action => 'new', :conditions => {:method => :get} |
|
|||
249 | map.connect 'enumerations/create', :controller => 'enumerations', :action => 'create', :conditions => {:method => :post} |
|
|||
250 | map.connect 'enumerations/edit/:id', :controller => 'enumerations', :action => 'edit', :id => /\d+/, :conditions => {:method => :get} |
|
|||
251 | map.connect 'enumerations/update/:id', :controller => 'enumerations', :action => 'update', :id => /\d+/, :conditions => {:method => :post} |
|
|||
252 | map.connect 'enumerations/destroy/:id', :controller => 'enumerations', :action => 'destroy', :id => /\d+/, :conditions => {:method => :post} |
|
|||
253 | map.connect 'settings', :controller => 'settings', :action => 'index', :conditions => {:method => :get} |
|
248 | map.connect 'settings', :controller => 'settings', :action => 'index', :conditions => {:method => :get} | |
254 | map.connect 'settings/edit', :controller => 'settings', :action => 'edit', :conditions => {:method => [:get, :post]} |
|
249 | map.connect 'settings/edit', :controller => 'settings', :action => 'edit', :conditions => {:method => [:get, :post]} | |
255 | map.connect 'settings/plugin/:id', :controller => 'settings', :action => 'plugin', :conditions => {:method => [:get, :post]} |
|
250 | map.connect 'settings/plugin/:id', :controller => 'settings', :action => 'plugin', :conditions => {:method => [:get, :post]} |
@@ -35,6 +35,8 class EnumerationsControllerTest < ActionController::TestCase | |||||
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'new' |
|
36 | assert_template 'new' | |
37 | assert_kind_of IssuePriority, assigns(:enumeration) |
|
37 | assert_kind_of IssuePriority, assigns(:enumeration) | |
|
38 | assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'} | |||
|
39 | assert_tag 'input', :attributes => {:name => 'enumeration[name]'} | |||
38 | end |
|
40 | end | |
39 |
|
41 | |||
40 | def test_create |
|
42 | def test_create | |
@@ -58,11 +60,12 class EnumerationsControllerTest < ActionController::TestCase | |||||
58 | get :edit, :id => 6 |
|
60 | get :edit, :id => 6 | |
59 | assert_response :success |
|
61 | assert_response :success | |
60 | assert_template 'edit' |
|
62 | assert_template 'edit' | |
|
63 | assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'} | |||
61 | end |
|
64 | end | |
62 |
|
65 | |||
63 | def test_update |
|
66 | def test_update | |
64 | assert_no_difference 'IssuePriority.count' do |
|
67 | assert_no_difference 'IssuePriority.count' do | |
65 |
p |
|
68 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} | |
66 | end |
|
69 | end | |
67 | assert_redirected_to '/enumerations?type=IssuePriority' |
|
70 | assert_redirected_to '/enumerations?type=IssuePriority' | |
68 | e = IssuePriority.find(6) |
|
71 | e = IssuePriority.find(6) | |
@@ -71,20 +74,24 class EnumerationsControllerTest < ActionController::TestCase | |||||
71 |
|
74 | |||
72 | def test_update_with_failure |
|
75 | def test_update_with_failure | |
73 | assert_no_difference 'IssuePriority.count' do |
|
76 | assert_no_difference 'IssuePriority.count' do | |
74 |
p |
|
77 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} | |
75 | end |
|
78 | end | |
76 | assert_response :success |
|
79 | assert_response :success | |
77 | assert_template 'edit' |
|
80 | assert_template 'edit' | |
78 | end |
|
81 | end | |
79 |
|
82 | |||
80 | def test_destroy_enumeration_not_in_use |
|
83 | def test_destroy_enumeration_not_in_use | |
81 | post :destroy, :id => 7 |
|
84 | assert_difference 'IssuePriority.count', -1 do | |
|
85 | delete :destroy, :id => 7 | |||
|
86 | end | |||
82 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
87 | assert_redirected_to :controller => 'enumerations', :action => 'index' | |
83 | assert_nil Enumeration.find_by_id(7) |
|
88 | assert_nil Enumeration.find_by_id(7) | |
84 | end |
|
89 | end | |
85 |
|
90 | |||
86 | def test_destroy_enumeration_in_use |
|
91 | def test_destroy_enumeration_in_use | |
87 | post :destroy, :id => 4 |
|
92 | assert_no_difference 'IssuePriority.count' do | |
|
93 | delete :destroy, :id => 4 | |||
|
94 | end | |||
88 | assert_response :success |
|
95 | assert_response :success | |
89 | assert_template 'destroy' |
|
96 | assert_template 'destroy' | |
90 | assert_not_nil Enumeration.find_by_id(4) |
|
97 | assert_not_nil Enumeration.find_by_id(4) | |
@@ -92,7 +99,9 class EnumerationsControllerTest < ActionController::TestCase | |||||
92 |
|
99 | |||
93 | def test_destroy_enumeration_in_use_with_reassignment |
|
100 | def test_destroy_enumeration_in_use_with_reassignment | |
94 | issue = Issue.find(:first, :conditions => {:priority_id => 4}) |
|
101 | issue = Issue.find(:first, :conditions => {:priority_id => 4}) | |
95 | post :destroy, :id => 4, :reassign_to_id => 6 |
|
102 | assert_difference 'IssuePriority.count', -1 do | |
|
103 | delete :destroy, :id => 4, :reassign_to_id => 6 | |||
|
104 | end | |||
96 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
105 | assert_redirected_to :controller => 'enumerations', :action => 'index' | |
97 | assert_nil Enumeration.find_by_id(4) |
|
106 | assert_nil Enumeration.find_by_id(4) | |
98 | # check that the issue was reassign |
|
107 | # check that the issue was reassign |
@@ -66,6 +66,15 class RoutingTest < ActionController::IntegrationTest | |||||
66 |
|
66 | |||
67 | should_route :post, "/documents/22/add_attachment", :controller => 'documents', :action => 'add_attachment', :id => '22' |
|
67 | should_route :post, "/documents/22/add_attachment", :controller => 'documents', :action => 'add_attachment', :id => '22' | |
68 | end |
|
68 | end | |
|
69 | ||||
|
70 | context "roles" do | |||
|
71 | should_route :get, "/enumerations", :controller => 'enumerations', :action => 'index' | |||
|
72 | should_route :get, "/enumerations/new", :controller => 'enumerations', :action => 'new' | |||
|
73 | should_route :post, "/enumerations", :controller => 'enumerations', :action => 'create' | |||
|
74 | should_route :get, "/enumerations/2/edit", :controller => 'enumerations', :action => 'edit', :id => 2 | |||
|
75 | should_route :put, "/enumerations/2", :controller => 'enumerations', :action => 'update', :id => 2 | |||
|
76 | should_route :delete, "/enumerations/2", :controller => 'enumerations', :action => 'destroy', :id => 2 | |||
|
77 | end | |||
69 |
|
78 | |||
70 | context "groups" do |
|
79 | context "groups" do | |
71 | should_route :post, "/groups/567/users", :controller => 'groups', :action => 'add_users', :id => '567' |
|
80 | should_route :post, "/groups/567/users", :controller => 'groups', :action => 'add_users', :id => '567' |
General Comments 0
You need to be logged in to leave comments.
Login now