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