class IssueCategoriesController < ApplicationController
menu_item :settings
- before_filter :find_project, :authorize
+ before_filter :find_category, :except => :new
+ before_filter :find_project, :only => :new
+ before_filter :authorize
verify :method => :post, :only => :destroy
+ def new
+ @category = @project.issue_categories.build(params[:category])
+ if request.post?
+ if @category.save
+ respond_to do |format|
+ format.html do
+ flash[:notice] = l(:notice_successful_create)
+ redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
+ end
+ format.js do
+ # IE doesn't support the replace_html rjs method for select box options
+ render(:update) {|page| page.replace "issue_category_id",
+ content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
+ }
+ end
+ end
+ else
+ respond_to do |format|
+ format.html
+ format.js do
+ render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
+ end
+ end
+ end
+ end
+ end
+
def edit
if request.post? and @category.update_attributes(params[:category])
flash[:notice] = l(:notice_successful_update)
end
private
- def find_project
+ def find_category
@category = IssueCategory.find(params[:id])
@project = @category.project
rescue ActiveRecord::RecordNotFound
render_404
end
+
+ def find_project
+ @project = Project.find(params[:project_id])
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
end
# hide project in layout
@project = nil
end
-
- # Add a new issue category to @project
- def add_issue_category
- @category = @project.issue_categories.build(params[:category])
- if request.post?
- if @category.save
- respond_to do |format|
- format.html do
- flash[:notice] = l(:notice_successful_create)
- redirect_to :action => 'settings', :tab => 'categories', :id => @project
- end
- format.js do
- # IE doesn't support the replace_html rjs method for select box options
- render(:update) {|page| page.replace "issue_category_id",
- content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
- }
- end
- end
- else
- respond_to do |format|
- format.html
- format.js do
- render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
- end
- end
- end
- end
- end
def add_file
if request.post?
--- /dev/null
+<h2><%=l(:label_issue_category_new)%></h2>
+
+<% labelled_tabular_form_for :category, @category, :url => { :action => 'new' } do |f| %>
+<%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
+<%= submit_tag l(:button_create) %>
+<% end %>
<%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
l(:label_issue_category_new),
'category[name]',
- {:controller => 'projects', :action => 'add_issue_category', :id => @project},
+ {:controller => 'issue_categories', :action => 'new', :project_id => @project},
:title => l(:label_issue_category_new),
- :tabindex => 199) if authorize_for('projects', 'add_issue_category') %></p>
+ :tabindex => 199) if authorize_for('issue_categories', 'new') %></p>
<% end %>
<% unless @issue.assignable_versions.empty? %>
<p><%= f.select :fixed_version_id, version_options_for_select(@issue.assignable_versions, @issue.fixed_version), :include_blank => true %>
+++ /dev/null
-<h2><%=l(:label_issue_category_new)%></h2>
-
-<% labelled_tabular_form_for :category, @category, :url => { :action => 'add_issue_category' } do |f| %>
-<%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
-<%= submit_tag l(:button_create) %>
-<% end %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
-<p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'projects', :action => 'add_issue_category', :id => @project %></p>
+<p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'issue_categories', :action => 'new', :project_id => @project %></p>
project_views.connect 'projects/:id/:action', :action => /roadmap|destroy|settings/
project_views.connect 'projects/:id/files', :action => 'list_files'
project_views.connect 'projects/:id/files/new', :action => 'add_file'
- project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category'
project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
end
project_actions.connect 'projects.:format', :action => 'add', :format => /xml/
project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/
project_actions.connect 'projects/:id/files/new', :action => 'add_file'
- project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category'
project_actions.connect 'projects/:id/activities/save', :action => 'save_activities'
end
end
end
+ map.with_options :controller => 'issue_categories' do |categories|
+ categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
+ end
+
map.with_options :controller => 'repositories' do |repositories|
repositories.with_options :conditions => {:method => :get} do |repository_views|
repository_views.connect 'projects/:id/repository', :action => 'show'
map.project_module :issue_tracking do |map|
# Issue categories
- map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member
+ map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
# Issues
map.permission :view_issues, {:projects => :roadmap,
:issues => [:index, :changes, :show, :context_menu],
@request.session[:user_id] = 2
end
+ def test_new_routing
+ assert_routing(
+ {:method => :get, :path => 'projects/test/issue_categories/new'},
+ :controller => 'issue_categories', :action => 'new', :project_id => 'test'
+ )
+ assert_routing(
+ {:method => :post, :path => 'projects/test/issue_categories/new'},
+ :controller => 'issue_categories', :action => 'new', :project_id => 'test'
+ )
+ end
+
+ def test_get_new
+ @request.session[:user_id] = 2 # manager
+ get :new, :project_id => '1'
+ assert_response :success
+ assert_template 'new'
+ end
+
+ def test_post_new
+ @request.session[:user_id] = 2 # manager
+ assert_difference 'IssueCategory.count' do
+ post :new, :project_id => '1', :category => {:name => 'New category'}
+ end
+ assert_redirected_to '/projects/ecookbook/settings/categories'
+ category = IssueCategory.find_by_name('New category')
+ assert_not_nil category
+ assert_equal 1, category.project_id
+ end
+
def test_post_edit
assert_no_difference 'IssueCategory.count' do
post :edit, :id => 2, :category => { :name => 'Testing' }
assert_equal 'Test changed name', project.name
end
- def test_add_issue_category_routing
- assert_routing(
- {:method => :get, :path => 'projects/test/categories/new'},
- :controller => 'projects', :action => 'add_issue_category', :id => 'test'
- )
- assert_routing(
- #TODO: use PUT and update form
- {:method => :post, :path => 'projects/64/categories/new'},
- :controller => 'projects', :action => 'add_issue_category', :id => '64'
- )
- end
-
def test_destroy_routing
assert_routing(
{:method => :get, :path => '/projects/567/destroy'},