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