Resourcified enumerations.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8189 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
1ad16c2238
commit
0471de41ff
@ -19,28 +19,19 @@ class EnumerationsController < ApplicationController
|
|||||||
layout 'admin'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
before_filter :build_new_enumeration, :only => [:new, :create]
|
||||||
|
before_filter :find_enumeration, :only => [:edit, :update, :destroy]
|
||||||
|
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
include CustomFieldsHelper
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
|
||||||
:redirect_to => { :action => :index }
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
begin
|
|
||||||
@enumeration = params[:type].constantize.new
|
|
||||||
rescue NameError
|
|
||||||
@enumeration = Enumeration.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@enumeration = Enumeration.new(params[:enumeration])
|
if request.post? && @enumeration.save
|
||||||
@enumeration.type = params[:enumeration][:type]
|
|
||||||
if @enumeration.save
|
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'index', :type => @enumeration.type
|
redirect_to :action => 'index', :type => @enumeration.type
|
||||||
else
|
else
|
||||||
@ -49,13 +40,10 @@ class EnumerationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@enumeration = Enumeration.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@enumeration = Enumeration.find(params[:id])
|
if request.put? && @enumeration.update_attributes(params[:enumeration])
|
||||||
@enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
|
|
||||||
if @enumeration.update_attributes(params[:enumeration])
|
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'index', :type => @enumeration.type
|
redirect_to :action => 'index', :type => @enumeration.type
|
||||||
else
|
else
|
||||||
@ -63,8 +51,8 @@ class EnumerationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
|
||||||
def destroy
|
def destroy
|
||||||
@enumeration = Enumeration.find(params[:id])
|
|
||||||
if !@enumeration.in_use?
|
if !@enumeration.in_use?
|
||||||
# No associated objects
|
# No associated objects
|
||||||
@enumeration.destroy
|
@enumeration.destroy
|
||||||
@ -77,9 +65,22 @@ class EnumerationsController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@enumerations = @enumeration.class.find(:all) - [@enumeration]
|
@enumerations = @enumeration.class.all - [@enumeration]
|
||||||
#rescue
|
end
|
||||||
# flash[:error] = 'Unable to delete enumeration'
|
|
||||||
# redirect_to :action => 'index'
|
private
|
||||||
|
|
||||||
|
def build_new_enumeration
|
||||||
|
class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
|
||||||
|
@enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
|
||||||
|
if @enumeration.nil?
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_enumeration
|
||||||
|
@enumeration = Enumeration.find(params[:id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Enumeration < ActiveRecord::Base
|
class Enumeration < ActiveRecord::Base
|
||||||
|
include Redmine::SubclassFactory
|
||||||
|
|
||||||
default_scope :order => "#{Enumeration.table_name}.position ASC"
|
default_scope :order => "#{Enumeration.table_name}.position ASC"
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
@ -27,6 +29,8 @@ class Enumeration < ActiveRecord::Base
|
|||||||
before_destroy :check_integrity
|
before_destroy :check_integrity
|
||||||
before_save :check_default
|
before_save :check_default
|
||||||
|
|
||||||
|
attr_protected :type
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
@ -1,19 +1,11 @@
|
|||||||
<%= error_messages_for 'enumeration' %>
|
<%= error_messages_for 'enumeration' %>
|
||||||
<div class="box">
|
|
||||||
<!--[form:optvalue]-->
|
|
||||||
<%= hidden_field 'enumeration', 'type' %>
|
|
||||||
|
|
||||||
<p><label for="enumeration_name"><%=l(:field_name)%></label>
|
<div class="box tabular">
|
||||||
<%= text_field 'enumeration', 'name' %></p>
|
<p><%= f.text_field :name %></p>
|
||||||
|
<p><%= f.check_box :active %></p>
|
||||||
|
<p><%= f.check_box :is_default %></p>
|
||||||
|
|
||||||
<p><label for="enumeration_active"><%=l(:field_active)%></label>
|
<% @enumeration.custom_field_values.each do |value| %>
|
||||||
<%= check_box 'enumeration', 'active' %></p>
|
<p><%= custom_field_tag_with_label :enumeration, value %></p>
|
||||||
|
<% end %>
|
||||||
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
|
|
||||||
<%= check_box 'enumeration', 'is_default' %></p>
|
|
||||||
<!--[eoform:optvalue]-->
|
|
||||||
|
|
||||||
<% @enumeration.custom_field_values.each do |value| %>
|
|
||||||
<p><%= custom_field_tag_with_label :enumeration, value %></p>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<h2><%= l(@enumeration.option_name) %>: <%=h @enumeration %></h2>
|
<h2><%= l(@enumeration.option_name) %>: <%=h @enumeration %></h2>
|
||||||
|
|
||||||
<% form_tag({}) do %>
|
<% form_tag({}, :method => :delete) do %>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<p><strong><%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %></strong></p>
|
<p><strong><%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %></strong></p>
|
||||||
<p><label for='reassign_to_id'><%= l(:text_enumeration_category_reassign_to) %></label>
|
<p><label for='reassign_to_id'><%= l(:text_enumeration_category_reassign_to) %></label>
|
||||||
@ -8,5 +8,5 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= submit_tag l(:button_apply) %>
|
<%= submit_tag l(:button_apply) %>
|
||||||
<%= link_to l(:button_cancel), :controller => 'enumerations', :action => 'index' %>
|
<%= link_to l(:button_cancel), enumerations_path %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<h2><%= link_to l(@enumeration.option_name), :controller => 'enumerations', :action => 'index' %> » <%=h @enumeration %></h2>
|
<h2><%= link_to l(@enumeration.option_name), enumerations_path %> » <%=h @enumeration %></h2>
|
||||||
|
|
||||||
<% form_tag({:action => 'update', :id => @enumeration}, :class => "tabular") do %>
|
<% labelled_form_for :enumeration, @enumeration, :url => enumeration_path(@enumeration), :html => {:method => :put} do |f| %>
|
||||||
<%= render :partial => 'form' %>
|
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
</tr></thead>
|
</tr></thead>
|
||||||
<% enumerations.each do |enumeration| %>
|
<% enumerations.each do |enumeration| %>
|
||||||
<tr class="<%= cycle('odd', 'even') %>">
|
<tr class="<%= cycle('odd', 'even') %>">
|
||||||
<td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
|
<td><%= link_to h(enumeration), edit_enumeration_path(enumeration) %></td>
|
||||||
<td class="center" style="width:15%;"><%= checked_image enumeration.is_default? %></td>
|
<td class="center" style="width:15%;"><%= checked_image enumeration.is_default? %></td>
|
||||||
<td class="center" style="width:15%;"><%= checked_image enumeration.active? %></td>
|
<td class="center" style="width:15%;"><%= checked_image enumeration.active? %></td>
|
||||||
<td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %></td>
|
<td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}, :put) %></td>
|
||||||
<td class="buttons">
|
<td class="buttons">
|
||||||
<%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration },
|
<%= link_to l(:button_delete), enumeration_path(enumeration),
|
||||||
:method => :post,
|
:method => :delete,
|
||||||
:confirm => l(:text_are_you_sure),
|
:confirm => l(:text_are_you_sure),
|
||||||
:class => 'icon icon-del' %>
|
:class => 'icon icon-del' %>
|
||||||
</td>
|
</td>
|
||||||
@ -31,7 +31,7 @@
|
|||||||
<% reset_cycle %>
|
<% reset_cycle %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :type => klass.name } %></p>
|
<p><%= link_to l(:label_enumeration_new), new_enumeration_path(:type => klass.name) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% html_title(l(:label_enumerations)) -%>
|
<% html_title(l(:label_enumerations)) -%>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<h2><%= link_to l(@enumeration.option_name), :controller => 'enumerations', :action => 'index' %> » <%=l(:label_enumeration_new)%></h2>
|
<h2><%= link_to l(@enumeration.option_name), enumerations_path %> » <%=l(:label_enumeration_new)%></h2>
|
||||||
|
|
||||||
<% form_tag({:action => 'create'}, :class => "tabular") do %>
|
<% labelled_form_for :enumeration, @enumeration, :url => enumerations_path do |f| %>
|
||||||
<%= render :partial => 'form' %>
|
<%= f.hidden_field :type %>
|
||||||
|
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||||
<%= submit_tag l(:button_create) %>
|
<%= submit_tag l(:button_create) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -212,6 +212,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post}
|
map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post}
|
||||||
map.resources :custom_fields, :except => :show
|
map.resources :custom_fields, :except => :show
|
||||||
map.resources :roles, :except => :show, :collection => {:permissions => [:get, :post]}
|
map.resources :roles, :except => :show, :collection => {:permissions => [:get, :post]}
|
||||||
|
map.resources :enumerations, :except => :show
|
||||||
|
|
||||||
map.connect 'search', :controller => 'search', :action => 'index', :conditions => {:method => :get}
|
map.connect 'search', :controller => 'search', :action => 'index', :conditions => {:method => :get}
|
||||||
|
|
||||||
@ -244,12 +245,6 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
map.connect 'workflows', :controller => 'workflows', :action => 'index', :conditions => {:method => :get}
|
map.connect 'workflows', :controller => 'workflows', :action => 'index', :conditions => {:method => :get}
|
||||||
map.connect 'workflows/edit', :controller => 'workflows', :action => 'edit', :conditions => {:method => [:get, :post]}
|
map.connect 'workflows/edit', :controller => 'workflows', :action => 'edit', :conditions => {:method => [:get, :post]}
|
||||||
map.connect 'workflows/copy', :controller => 'workflows', :action => 'copy', :conditions => {:method => [:get, :post]}
|
map.connect 'workflows/copy', :controller => 'workflows', :action => 'copy', :conditions => {:method => [:get, :post]}
|
||||||
map.connect 'enumerations', :controller => 'enumerations', :action => 'index', :conditions => {:method => :get}
|
|
||||||
map.connect 'enumerations/new', :controller => 'enumerations', :action => 'new', :conditions => {:method => :get}
|
|
||||||
map.connect 'enumerations/create', :controller => 'enumerations', :action => 'create', :conditions => {:method => :post}
|
|
||||||
map.connect 'enumerations/edit/:id', :controller => 'enumerations', :action => 'edit', :id => /\d+/, :conditions => {:method => :get}
|
|
||||||
map.connect 'enumerations/update/:id', :controller => 'enumerations', :action => 'update', :id => /\d+/, :conditions => {:method => :post}
|
|
||||||
map.connect 'enumerations/destroy/:id', :controller => 'enumerations', :action => 'destroy', :id => /\d+/, :conditions => {:method => :post}
|
|
||||||
map.connect 'settings', :controller => 'settings', :action => 'index', :conditions => {:method => :get}
|
map.connect 'settings', :controller => 'settings', :action => 'index', :conditions => {:method => :get}
|
||||||
map.connect 'settings/edit', :controller => 'settings', :action => 'edit', :conditions => {:method => [:get, :post]}
|
map.connect 'settings/edit', :controller => 'settings', :action => 'edit', :conditions => {:method => [:get, :post]}
|
||||||
map.connect 'settings/plugin/:id', :controller => 'settings', :action => 'plugin', :conditions => {:method => [:get, :post]}
|
map.connect 'settings/plugin/:id', :controller => 'settings', :action => 'plugin', :conditions => {:method => [:get, :post]}
|
||||||
|
@ -35,6 +35,8 @@ class EnumerationsControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'new'
|
assert_template 'new'
|
||||||
assert_kind_of IssuePriority, assigns(:enumeration)
|
assert_kind_of IssuePriority, assigns(:enumeration)
|
||||||
|
assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
|
||||||
|
assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
@ -58,11 +60,12 @@ class EnumerationsControllerTest < ActionController::TestCase
|
|||||||
get :edit, :id => 6
|
get :edit, :id => 6
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'edit'
|
assert_template 'edit'
|
||||||
|
assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
assert_no_difference 'IssuePriority.count' do
|
assert_no_difference 'IssuePriority.count' do
|
||||||
post :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
|
put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
|
||||||
end
|
end
|
||||||
assert_redirected_to '/enumerations?type=IssuePriority'
|
assert_redirected_to '/enumerations?type=IssuePriority'
|
||||||
e = IssuePriority.find(6)
|
e = IssuePriority.find(6)
|
||||||
@ -71,20 +74,24 @@ class EnumerationsControllerTest < ActionController::TestCase
|
|||||||
|
|
||||||
def test_update_with_failure
|
def test_update_with_failure
|
||||||
assert_no_difference 'IssuePriority.count' do
|
assert_no_difference 'IssuePriority.count' do
|
||||||
post :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
|
put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
|
||||||
end
|
end
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'edit'
|
assert_template 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy_enumeration_not_in_use
|
def test_destroy_enumeration_not_in_use
|
||||||
post :destroy, :id => 7
|
assert_difference 'IssuePriority.count', -1 do
|
||||||
|
delete :destroy, :id => 7
|
||||||
|
end
|
||||||
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
||||||
assert_nil Enumeration.find_by_id(7)
|
assert_nil Enumeration.find_by_id(7)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy_enumeration_in_use
|
def test_destroy_enumeration_in_use
|
||||||
post :destroy, :id => 4
|
assert_no_difference 'IssuePriority.count' do
|
||||||
|
delete :destroy, :id => 4
|
||||||
|
end
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'destroy'
|
assert_template 'destroy'
|
||||||
assert_not_nil Enumeration.find_by_id(4)
|
assert_not_nil Enumeration.find_by_id(4)
|
||||||
@ -92,7 +99,9 @@ class EnumerationsControllerTest < ActionController::TestCase
|
|||||||
|
|
||||||
def test_destroy_enumeration_in_use_with_reassignment
|
def test_destroy_enumeration_in_use_with_reassignment
|
||||||
issue = Issue.find(:first, :conditions => {:priority_id => 4})
|
issue = Issue.find(:first, :conditions => {:priority_id => 4})
|
||||||
post :destroy, :id => 4, :reassign_to_id => 6
|
assert_difference 'IssuePriority.count', -1 do
|
||||||
|
delete :destroy, :id => 4, :reassign_to_id => 6
|
||||||
|
end
|
||||||
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
||||||
assert_nil Enumeration.find_by_id(4)
|
assert_nil Enumeration.find_by_id(4)
|
||||||
# check that the issue was reassign
|
# check that the issue was reassign
|
||||||
|
@ -67,6 +67,15 @@ class RoutingTest < ActionController::IntegrationTest
|
|||||||
should_route :post, "/documents/22/add_attachment", :controller => 'documents', :action => 'add_attachment', :id => '22'
|
should_route :post, "/documents/22/add_attachment", :controller => 'documents', :action => 'add_attachment', :id => '22'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "roles" do
|
||||||
|
should_route :get, "/enumerations", :controller => 'enumerations', :action => 'index'
|
||||||
|
should_route :get, "/enumerations/new", :controller => 'enumerations', :action => 'new'
|
||||||
|
should_route :post, "/enumerations", :controller => 'enumerations', :action => 'create'
|
||||||
|
should_route :get, "/enumerations/2/edit", :controller => 'enumerations', :action => 'edit', :id => 2
|
||||||
|
should_route :put, "/enumerations/2", :controller => 'enumerations', :action => 'update', :id => 2
|
||||||
|
should_route :delete, "/enumerations/2", :controller => 'enumerations', :action => 'destroy', :id => 2
|
||||||
|
end
|
||||||
|
|
||||||
context "groups" do
|
context "groups" do
|
||||||
should_route :post, "/groups/567/users", :controller => 'groups', :action => 'add_users', :id => '567'
|
should_route :post, "/groups/567/users", :controller => 'groups', :action => 'add_users', :id => '567'
|
||||||
should_route :delete, "/groups/567/users/12", :controller => 'groups', :action => 'remove_user', :id => '567', :user_id => '12'
|
should_route :delete, "/groups/567/users/12", :controller => 'groups', :action => 'remove_user', :id => '567', :user_id => '12'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user