Refactor: split NewsController#edit into #edit and #update
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4168 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
51359704a0
commit
01d1a02df4
@ -60,14 +60,19 @@ class NewsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
if request.post? and @news.update_attributes(params[:news])
|
|
||||||
flash[:notice] = l(:notice_successful_update)
|
|
||||||
redirect_to :action => 'show', :id => @news
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if request.put? and @news.update_attributes(params[:news])
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :action => 'show', :id => @news
|
||||||
|
else
|
||||||
|
render :action => 'edit'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def add_comment
|
def add_comment
|
||||||
@comment = Comment.new(params[:comment])
|
@comment = Comment.new(params[:comment])
|
||||||
@comment.author = User.current
|
@comment.author = User.current
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<h2><%=l(:label_news)%></h2>
|
<h2><%=l(:label_news)%></h2>
|
||||||
|
|
||||||
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" },
|
<% labelled_tabular_form_for :news, @news, :url => { :action => "update" },
|
||||||
:html => { :id => 'news-form' } do |f| %>
|
:html => { :id => 'news-form', :method => :put } do |f| %>
|
||||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<%= link_to_remote l(:label_preview),
|
<%= link_to_remote l(:label_preview),
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
<% if authorize_for('news', 'edit') %>
|
<% if authorize_for('news', 'edit') %>
|
||||||
<div id="edit-news" style="display:none;">
|
<div id="edit-news" style="display:none;">
|
||||||
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news },
|
<% labelled_tabular_form_for :news, @news, :url => { :action => "update", :id => @news },
|
||||||
:html => { :id => 'news-form' } do |f| %>
|
:html => { :id => 'news-form', :method => :put } do |f| %>
|
||||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<%= link_to_remote l(:label_preview),
|
<%= link_to_remote l(:label_preview),
|
||||||
|
@ -149,9 +149,9 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
end
|
end
|
||||||
news_routes.with_options do |news_actions|
|
news_routes.with_options do |news_actions|
|
||||||
news_actions.connect 'projects/:project_id/news', :action => 'create', :conditions => {:method => :post}
|
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/destroy', :action => 'destroy'
|
news_actions.connect 'news/:id/destroy', :action => 'destroy'
|
||||||
end
|
end
|
||||||
|
news_routes.connect 'news/:id/edit', :action => 'update', :conditions => {:method => :put}
|
||||||
end
|
end
|
||||||
|
|
||||||
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
|
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
|
||||||
|
@ -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, :create, :edit, :destroy, :destroy_comment]}, :require => :member
|
map.permission :manage_news, {:news => [:new, :create, :edit, :update, :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
|
||||||
|
@ -90,9 +90,9 @@ class NewsControllerTest < ActionController::TestCase
|
|||||||
assert_template 'edit'
|
assert_template 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_post_edit
|
def test_put_update
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
|
put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
|
||||||
assert_redirected_to 'news/1'
|
assert_redirected_to 'news/1'
|
||||||
news = News.find(1)
|
news = News.find(1)
|
||||||
assert_equal 'Description changed by test_post_edit', news.description
|
assert_equal 'Description changed by test_post_edit', news.description
|
||||||
|
@ -156,10 +156,12 @@ class RoutingTest < ActionController::IntegrationTest
|
|||||||
should_route :get, "/news/2", :controller => 'news', :action => 'show', :id => '2'
|
should_route :get, "/news/2", :controller => 'news', :action => 'show', :id => '2'
|
||||||
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 :get, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
|
||||||
|
|
||||||
should_route :post, "/projects/567/news", :controller => 'news', :action => 'create', :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/destroy", :controller => 'news', :action => 'destroy', :id => '567'
|
should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567'
|
||||||
|
|
||||||
|
should_route :put, "/news/567/edit", :controller => 'news', :action => 'update', :id => '567'
|
||||||
end
|
end
|
||||||
|
|
||||||
context "projects" do
|
context "projects" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user