OSDN Git Service

Moves ProjectsController#add_issue_category to IssueCategoriesController#new.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 6 Mar 2010 18:43:00 +0000 (18:43 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 6 Mar 2010 18:43:00 +0000 (18:43 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3549 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issue_categories_controller.rb
app/controllers/projects_controller.rb
app/views/issue_categories/new.html.erb [moved from app/views/projects/add_issue_category.rhtml with 84% similarity]
app/views/issues/_attributes.rhtml
app/views/projects/settings/_issue_categories.rhtml
config/routes.rb
lib/redmine.rb
test/functional/issue_categories_controller_test.rb
test/functional/projects_controller_test.rb

index 8315d6e..8c077cf 100644 (file)
 
 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)
@@ -43,10 +72,16 @@ class IssueCategoriesController < ApplicationController
   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
index f009946..ea04927 100644 (file)
@@ -238,34 +238,6 @@ class ProjectsController < ApplicationController
     # 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?
similarity index 84%
rename from app/views/projects/add_issue_category.rhtml
rename to app/views/issue_categories/new.html.erb
index 08bc6d0..ac7936a 100644 (file)
@@ -1,6 +1,6 @@
 <h2><%=l(:label_issue_category_new)%></h2>
 
-<% labelled_tabular_form_for :category, @category, :url => { :action => 'add_issue_category' } do |f| %>
+<% 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 %>
index 2f0d3ed..acbd910 100644 (file)
@@ -14,9 +14,9 @@
 <%= 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 %>
index bea576c..52e34f4 100644 (file)
@@ -24,4 +24,4 @@
 <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>
index 1149942..8c707f2 100644 (file)
@@ -191,7 +191,6 @@ ActionController::Routing::Routes.draw do |map|
       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
 
@@ -208,7 +207,6 @@ ActionController::Routing::Routes.draw do |map|
       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
 
@@ -229,6 +227,10 @@ ActionController::Routing::Routes.draw do |map|
     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'
index a8b2398..1205f6f 100644 (file)
@@ -44,7 +44,7 @@ Redmine::AccessControl.map do |map|
   
   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],
index 3d1dd06..ae5919a 100644 (file)
@@ -32,6 +32,35 @@ class IssueCategoriesControllerTest < ActionController::TestCase
     @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' }
index f4fe8da..e64602a 100644 (file)
@@ -329,18 +329,6 @@ class ProjectsControllerTest < ActionController::TestCase
     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'},