##// END OF EJS Templates
Refactor: split NewsController#new into #new and #create methods....
Eric Davis -
r4049:3bc29e29e091
parent child
Show More
@@ -18,9 +18,9
18 class NewsController < ApplicationController
18 class NewsController < ApplicationController
19 default_search_scope :news
19 default_search_scope :news
20 model_object News
20 model_object News
21 before_filter :find_model_object, :except => [:new, :index, :preview]
21 before_filter :find_model_object, :except => [:new, :create, :index, :preview]
22 before_filter :find_project_from_association, :except => [:new, :index, :preview]
22 before_filter :find_project_from_association, :except => [:new, :create, :index, :preview]
23 before_filter :find_project, :only => [:new, :preview]
23 before_filter :find_project, :only => [:new, :create, :preview]
24 before_filter :authorize, :except => [:index, :preview]
24 before_filter :authorize, :except => [:index, :preview]
25 before_filter :find_optional_project, :only => :index
25 before_filter :find_optional_project, :only => :index
26 accept_key_auth :index
26 accept_key_auth :index
@@ -46,11 +46,17 class NewsController < ApplicationController
46
46
47 def new
47 def new
48 @news = News.new(:project => @project, :author => User.current)
48 @news = News.new(:project => @project, :author => User.current)
49 end
50
51 def create
52 @news = News.new(:project => @project, :author => User.current)
49 if request.post?
53 if request.post?
50 @news.attributes = params[:news]
54 @news.attributes = params[:news]
51 if @news.save
55 if @news.save
52 flash[:notice] = l(:notice_successful_create)
56 flash[:notice] = l(:notice_successful_create)
53 redirect_to :controller => 'news', :action => 'index', :project_id => @project
57 redirect_to :controller => 'news', :action => 'index', :project_id => @project
58 else
59 render :action => 'new'
54 end
60 end
55 end
61 end
56 end
62 end
@@ -7,7 +7,7
7
7
8 <div id="add-news" style="display:none;">
8 <div id="add-news" style="display:none;">
9 <h2><%=l(:label_news_new)%></h2>
9 <h2><%=l(:label_news_new)%></h2>
10 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
10 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'create', :project_id => @project },
11 :html => { :id => 'news-form' } do |f| %>
11 :html => { :id => 'news-form' } do |f| %>
12 <%= render :partial => 'news/form', :locals => { :f => f } %>
12 <%= render :partial => 'news/form', :locals => { :f => f } %>
13 <%= submit_tag l(:button_create) %>
13 <%= submit_tag l(:button_create) %>
@@ -1,6 +1,6
1 <h2><%=l(:label_news_new)%></h2>
1 <h2><%=l(:label_news_new)%></h2>
2
2
3 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
3 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'create', :project_id => @project },
4 :html => { :id => 'news-form' } do |f| %>
4 :html => { :id => 'news-form' } do |f| %>
5 <%= render :partial => 'news/form', :locals => { :f => f } %>
5 <%= render :partial => 'news/form', :locals => { :f => f } %>
6 <%= submit_tag l(:button_create) %>
6 <%= submit_tag l(:button_create) %>
@@ -148,7 +148,7 ActionController::Routing::Routes.draw do |map|
148 news_views.connect 'news/:id/edit', :action => 'edit'
148 news_views.connect 'news/:id/edit', :action => 'edit'
149 end
149 end
150 news_routes.with_options do |news_actions|
150 news_routes.with_options do |news_actions|
151 news_actions.connect 'projects/:project_id/news', :action => 'new'
151 news_actions.connect 'projects/:project_id/news', :action => 'create', :conditions => {:method => :post}
152 news_actions.connect 'news/:id/edit', :action => 'edit'
152 news_actions.connect 'news/:id/edit', :action => 'edit'
153 news_actions.connect 'news/:id/destroy', :action => 'destroy'
153 news_actions.connect 'news/:id/destroy', :action => 'destroy'
154 end
154 end
@@ -91,7 +91,7 Redmine::AccessControl.map do |map|
91 end
91 end
92
92
93 map.project_module :news do |map|
93 map.project_module :news do |map|
94 map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
94 map.permission :manage_news, {:news => [:new, :create, :edit, :destroy, :destroy_comment]}, :require => :member
95 map.permission :view_news, {:news => [:index, :show]}, :public => true
95 map.permission :view_news, {:news => [:index, :show]}, :public => true
96 map.permission :comment_news, {:news => :add_comment}
96 map.permission :comment_news, {:news => :add_comment}
97 end
97 end
@@ -65,12 +65,12 class NewsControllerTest < ActionController::TestCase
65 assert_template 'new'
65 assert_template 'new'
66 end
66 end
67
67
68 def test_post_new
68 def test_post_create
69 ActionMailer::Base.deliveries.clear
69 ActionMailer::Base.deliveries.clear
70 Setting.notified_events << 'news_added'
70 Setting.notified_events << 'news_added'
71
71
72 @request.session[:user_id] = 2
72 @request.session[:user_id] = 2
73 post :new, :project_id => 1, :news => { :title => 'NewsControllerTest',
73 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest',
74 :description => 'This is the description',
74 :description => 'This is the description',
75 :summary => '' }
75 :summary => '' }
76 assert_redirected_to 'projects/ecookbook/news'
76 assert_redirected_to 'projects/ecookbook/news'
@@ -98,9 +98,9 class NewsControllerTest < ActionController::TestCase
98 assert_equal 'Description changed by test_post_edit', news.description
98 assert_equal 'Description changed by test_post_edit', news.description
99 end
99 end
100
100
101 def test_post_new_with_validation_failure
101 def test_post_create_with_validation_failure
102 @request.session[:user_id] = 2
102 @request.session[:user_id] = 2
103 post :new, :project_id => 1, :news => { :title => '',
103 post :create, :project_id => 1, :news => { :title => '',
104 :description => 'This is the description',
104 :description => 'This is the description',
105 :summary => '' }
105 :summary => '' }
106 assert_response :success
106 assert_response :success
@@ -157,7 +157,7 class RoutingTest < ActionController::IntegrationTest
157 should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
157 should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
158 should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234'
158 should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234'
159
159
160 should_route :post, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
160 should_route :post, "/projects/567/news", :controller => 'news', :action => 'create', :project_id => '567'
161 should_route :post, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
161 should_route :post, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
162 should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567'
162 should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567'
163 end
163 end
General Comments 0
You need to be logged in to leave comments. Login now