mirror of
				https://github.com/redmine/redmine.git
				synced 2025-10-31 18:36:07 +01:00 
			
		
		
		
	Refactor: split NewsController#new into #new and #create methods.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4163 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
		| @@ -18,9 +18,9 @@ | |||||||
| class NewsController < ApplicationController | class NewsController < ApplicationController | ||||||
|   default_search_scope :news |   default_search_scope :news | ||||||
|   model_object News |   model_object News | ||||||
|   before_filter :find_model_object, :except => [:new, :index, :preview] |   before_filter :find_model_object, :except => [:new, :create, :index, :preview] | ||||||
|   before_filter :find_project_from_association, :except => [:new, :index, :preview] |   before_filter :find_project_from_association, :except => [:new, :create, :index, :preview] | ||||||
|   before_filter :find_project, :only => [:new, :preview] |   before_filter :find_project, :only => [:new, :create, :preview] | ||||||
|   before_filter :authorize, :except => [:index, :preview] |   before_filter :authorize, :except => [:index, :preview] | ||||||
|   before_filter :find_optional_project, :only => :index |   before_filter :find_optional_project, :only => :index | ||||||
|   accept_key_auth :index |   accept_key_auth :index | ||||||
| @@ -46,11 +46,17 @@ class NewsController < ApplicationController | |||||||
|  |  | ||||||
|   def new |   def new | ||||||
|     @news = News.new(:project => @project, :author => User.current) |     @news = News.new(:project => @project, :author => User.current) | ||||||
|  |   end | ||||||
|  |  | ||||||
|  |   def create | ||||||
|  |     @news = News.new(:project => @project, :author => User.current) | ||||||
|     if request.post? |     if request.post? | ||||||
|       @news.attributes = params[:news] |       @news.attributes = params[:news] | ||||||
|       if @news.save |       if @news.save | ||||||
|         flash[:notice] = l(:notice_successful_create) |         flash[:notice] = l(:notice_successful_create) | ||||||
|         redirect_to :controller => 'news', :action => 'index', :project_id => @project |         redirect_to :controller => 'news', :action => 'index', :project_id => @project | ||||||
|  |       else | ||||||
|  |         render :action => 'new' | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
|  |  | ||||||
| <div id="add-news" style="display:none;"> | <div id="add-news" style="display:none;"> | ||||||
| <h2><%=l(:label_news_new)%></h2> | <h2><%=l(:label_news_new)%></h2> | ||||||
| <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project }, | <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'create', :project_id => @project }, | ||||||
|                                            :html => { :id => 'news-form' } do |f| %> |                                            :html => { :id => 'news-form' } do |f| %> | ||||||
| <%= render :partial => 'news/form', :locals => { :f => f } %> | <%= render :partial => 'news/form', :locals => { :f => f } %> | ||||||
| <%= submit_tag l(:button_create) %> | <%= submit_tag l(:button_create) %> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <h2><%=l(:label_news_new)%></h2> | <h2><%=l(:label_news_new)%></h2> | ||||||
|  |  | ||||||
| <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project }, | <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'create', :project_id => @project }, | ||||||
|                                            :html => { :id => 'news-form' } do |f| %> |                                            :html => { :id => 'news-form' } do |f| %> | ||||||
| <%= render :partial => 'news/form', :locals => { :f => f } %> | <%= render :partial => 'news/form', :locals => { :f => f } %> | ||||||
| <%= submit_tag l(:button_create) %> | <%= submit_tag l(:button_create) %> | ||||||
|   | |||||||
| @@ -148,7 +148,7 @@ ActionController::Routing::Routes.draw do |map| | |||||||
|       news_views.connect 'news/:id/edit', :action => 'edit' |       news_views.connect 'news/:id/edit', :action => 'edit' | ||||||
|     end |     end | ||||||
|     news_routes.with_options do |news_actions| |     news_routes.with_options do |news_actions| | ||||||
|       news_actions.connect 'projects/:project_id/news', :action => 'new' |       news_actions.connect 'projects/:project_id/news', :action => 'create', :conditions => {:method => :post} | ||||||
|       news_actions.connect 'news/:id/edit', :action => 'edit' |       news_actions.connect 'news/:id/edit', :action => 'edit' | ||||||
|       news_actions.connect 'news/:id/destroy', :action => 'destroy' |       news_actions.connect 'news/:id/destroy', :action => 'destroy' | ||||||
|     end |     end | ||||||
|   | |||||||
| @@ -91,7 +91,7 @@ Redmine::AccessControl.map do |map| | |||||||
|   end |   end | ||||||
|    |    | ||||||
|   map.project_module :news do |map| |   map.project_module :news do |map| | ||||||
|     map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member |     map.permission :manage_news, {:news => [:new, :create, :edit, :destroy, :destroy_comment]}, :require => :member | ||||||
|     map.permission :view_news, {:news => [:index, :show]}, :public => true |     map.permission :view_news, {:news => [:index, :show]}, :public => true | ||||||
|     map.permission :comment_news, {:news => :add_comment} |     map.permission :comment_news, {:news => :add_comment} | ||||||
|   end |   end | ||||||
|   | |||||||
| @@ -65,12 +65,12 @@ class NewsControllerTest < ActionController::TestCase | |||||||
|     assert_template 'new' |     assert_template 'new' | ||||||
|   end |   end | ||||||
|    |    | ||||||
|   def test_post_new |   def test_post_create | ||||||
|     ActionMailer::Base.deliveries.clear |     ActionMailer::Base.deliveries.clear | ||||||
|     Setting.notified_events << 'news_added' |     Setting.notified_events << 'news_added' | ||||||
|  |  | ||||||
|     @request.session[:user_id] = 2 |     @request.session[:user_id] = 2 | ||||||
|     post :new, :project_id => 1, :news => { :title => 'NewsControllerTest', |     post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', | ||||||
|                                             :description => 'This is the description', |                                             :description => 'This is the description', | ||||||
|                                             :summary => '' } |                                             :summary => '' } | ||||||
|     assert_redirected_to 'projects/ecookbook/news' |     assert_redirected_to 'projects/ecookbook/news' | ||||||
| @@ -98,9 +98,9 @@ class NewsControllerTest < ActionController::TestCase | |||||||
|     assert_equal 'Description changed by test_post_edit', news.description |     assert_equal 'Description changed by test_post_edit', news.description | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   def test_post_new_with_validation_failure |   def test_post_create_with_validation_failure | ||||||
|     @request.session[:user_id] = 2 |     @request.session[:user_id] = 2 | ||||||
|     post :new, :project_id => 1, :news => { :title => '', |     post :create, :project_id => 1, :news => { :title => '', | ||||||
|                                             :description => 'This is the description', |                                             :description => 'This is the description', | ||||||
|                                             :summary => '' } |                                             :summary => '' } | ||||||
|     assert_response :success |     assert_response :success | ||||||
|   | |||||||
| @@ -157,7 +157,7 @@ class RoutingTest < ActionController::IntegrationTest | |||||||
|     should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567' |     should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567' | ||||||
|     should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234' |     should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234' | ||||||
|  |  | ||||||
|     should_route :post, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567' |     should_route :post, "/projects/567/news", :controller => 'news', :action => 'create', :project_id => '567' | ||||||
|     should_route :post, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567' |     should_route :post, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567' | ||||||
|     should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567' |     should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567' | ||||||
|   end |   end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user