Commit 79e30e70 authored by Eric Davis's avatar Eric Davis

Refactor: convert News to a REST resource

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4214 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 0a224e8b
<p><%= link_to_project(news.project) + ': ' unless @project %> <p><%= link_to_project(news.project) + ': ' unless @project %>
<%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> <%= link_to h(news.title), news_path(news) %>
<%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %> <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %>
<br /> <br />
<% unless news.summary.blank? %><span class="summary"><%=h news.summary %></span><br /><% end %> <% unless news.summary.blank? %><span class="summary"><%=h news.summary %></span><br /><% end %>
......
<h2><%=l(:label_news)%></h2> <h2><%=l(:label_news)%></h2>
<% labelled_tabular_form_for :news, @news, :url => { :action => "update" }, <% labelled_tabular_form_for :news, @news, :url => news_path(@news),
:html => { :id => 'news-form', :method => :put } 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),
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project }, { :url => preview_news_path(:project_id => @project),
:method => 'get', :method => 'get',
:update => 'preview', :update => 'preview',
:with => "Form.serialize('news-form')" :with => "Form.serialize('news-form')"
......
<div class="contextual"> <div class="contextual">
<%= link_to_if_authorized(l(:label_news_new), <%= link_to_if_authorized(l(:label_news_new),
{:controller => 'news', :action => 'new', :project_id => @project}, new_project_news_path(@project),
:class => 'icon icon-add', :class => 'icon icon-add',
:onclick => 'Element.show("add-news"); Form.Element.focus("news_title"); return false;') if @project %> :onclick => 'Element.show("add-news"); Form.Element.focus("news_title"); return false;') if @project %>
</div> </div>
<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 => 'create', :project_id => @project }, <% labelled_tabular_form_for :news, @news, :url => project_news_index_path(@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) %>
<%= link_to_remote l(:label_preview), <%= link_to_remote l(:label_preview),
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project }, { :url => preview_news_path(:project_id => @project),
:method => 'get', :method => 'get',
:update => 'preview', :update => 'preview',
:with => "Form.serialize('news-form')" :with => "Form.serialize('news-form')"
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<% else %> <% else %>
<% @newss.each do |news| %> <% @newss.each do |news| %>
<h3><%= link_to_project(news.project) + ': ' unless news.project == @project %> <h3><%= link_to_project(news.project) + ': ' unless news.project == @project %>
<%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> <%= link_to h(news.title), news_path(news) %>
<%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3> <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3>
<p class="author"><%= authoring news.created_on, news.author %></p> <p class="author"><%= authoring news.created_on, news.author %></p>
<div class="wiki"> <div class="wiki">
......
<h2><%=l(:label_news_new)%></h2> <h2><%=l(:label_news_new)%></h2>
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'create', :project_id => @project }, <% labelled_tabular_form_for :news, @news, :url => project_news_index_path(@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) %>
<%= link_to_remote l(:label_preview), <%= link_to_remote l(:label_preview),
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project }, { :url => preview_news_path(:project_id => @project),
:method => 'get', :method => 'get',
:update => 'preview', :update => 'preview',
:with => "Form.serialize('news-form')" :with => "Form.serialize('news-form')"
......
<div class="contextual"> <div class="contextual">
<%= link_to_if_authorized l(:button_edit), <%= link_to_if_authorized l(:button_edit),
{:controller => 'news', :action => 'edit', :id => @news}, edit_news_path(@news),
:class => 'icon icon-edit', :class => 'icon icon-edit',
:accesskey => accesskey(:edit), :accesskey => accesskey(:edit),
:onclick => 'Element.show("edit-news"); return false;' %> :onclick => 'Element.show("edit-news"); return false;' %>
<%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy', :id => @news}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> <%= link_to_if_authorized l(:button_delete), news_path(@news), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
</div> </div>
<h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2> <h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2>
<% 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 => "update", :id => @news }, <% labelled_tabular_form_for :news, @news, :url => news_path(@news),
:html => { :id => 'news-form', :method => :put } 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),
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project }, { :url => preview_news_path(:project_id => @project),
:method => 'get', :method => 'get',
:update => 'preview', :update => 'preview',
:with => "Form.serialize('news-form')" :with => "Form.serialize('news-form')"
......
...@@ -136,30 +136,7 @@ ActionController::Routing::Routes.draw do |map| ...@@ -136,30 +136,7 @@ ActionController::Routing::Routes.draw do |map|
relations.connect 'issues/:issue_id/relations/:id', :action => 'new' relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy' relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
end end
map.with_options :controller => 'news' do |news_routes|
news_routes.connect 'news/:id/preview', :controller => 'previews', :action => 'news'
news_routes.connect 'news/preview', :controller => 'previews', :action => 'news'
news_routes.with_options :conditions => {:method => :get} do |news_views|
news_views.connect 'news', :action => 'index'
news_views.connect 'projects/:project_id/news', :action => 'index'
news_views.connect 'projects/:project_id/news.:format', :action => 'index'
news_views.connect 'news.:format', :action => 'index'
news_views.connect 'projects/:project_id/news/new', :action => 'new'
news_views.connect 'news/:id', :action => 'show'
news_views.connect 'news/:id/edit', :action => 'edit'
end
news_routes.with_options do |news_actions|
news_actions.connect 'projects/:project_id/news', :action => 'create', :conditions => {:method => :post}
news_actions.connect 'news/:id/destroy', :action => 'destroy'
end
news_routes.connect 'news/:id/edit', :action => 'update', :conditions => {:method => :put}
news_routes.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
news_routes.connect 'news/:id/comments/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
end
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new' map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
map.with_options :controller => 'users' do |users| map.with_options :controller => 'users' do |users|
...@@ -182,6 +159,12 @@ ActionController::Routing::Routes.draw do |map| ...@@ -182,6 +159,12 @@ ActionController::Routing::Routes.draw do |map|
# For nice "roadmap" in the url for the index action # For nice "roadmap" in the url for the index action
map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index' map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index'
map.all_news 'news', :controller => 'news', :action => 'index'
map.formatted_all_news 'news.:format', :controller => 'news', :action => 'index'
map.preview_news '/news/preview', :controller => 'previews', :action => 'news'
map.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
map.connect 'news/:id/comments/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
map.resources :projects, :member => { map.resources :projects, :member => {
:copy => [:get, :post], :copy => [:get, :post],
:settings => :get, :settings => :get,
...@@ -192,6 +175,7 @@ ActionController::Routing::Routes.draw do |map| ...@@ -192,6 +175,7 @@ ActionController::Routing::Routes.draw do |map|
project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
project.resources :files, :only => [:index, :new, :create] project.resources :files, :only => [:index, :new, :create]
project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post} project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post}
project.resources :news, :shallow => true
end end
# Destroy uses a get request to prompt the user before the actual DELETE request # Destroy uses a get request to prompt the user before the actual DELETE request
......
...@@ -113,7 +113,7 @@ class NewsControllerTest < ActionController::TestCase ...@@ -113,7 +113,7 @@ class NewsControllerTest < ActionController::TestCase
def test_destroy def test_destroy
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :destroy, :id => 1 delete :destroy, :id => 1
assert_redirected_to 'projects/ecookbook/news' assert_redirected_to 'projects/ecookbook/news'
assert_nil News.find_by_id(1) assert_nil News.find_by_id(1)
end end
......
...@@ -157,17 +157,14 @@ class RoutingTest < ActionController::IntegrationTest ...@@ -157,17 +157,14 @@ 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 :get, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567' should_route :get, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
should_route :get, "/news/123/preview", :controller => 'previews', :action => 'news', :id => '123'
should_route :get, "/news/preview", :controller => 'previews', :action => 'news' should_route :get, "/news/preview", :controller => 'previews', :action => 'news'
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/destroy", :controller => 'news', :action => 'destroy', :id => '567'
should_route :post, "/news/567/comments", :controller => 'comments', :action => 'create', :id => '567' should_route :post, "/news/567/comments", :controller => 'comments', :action => 'create', :id => '567'
should_route :post, "/issues/preview/123", :controller => 'previews', :action => 'issue', :id => '123' should_route :put, "/news/567", :controller => 'news', :action => 'update', :id => '567'
should_route :put, "/news/567/edit", :controller => 'news', :action => 'update', :id => '567'
should_route :delete, "/news/567", :controller => 'news', :action => 'destroy', :id => '567'
should_route :delete, "/news/567/comments/15", :controller => 'comments', :action => 'destroy', :id => '567', :comment_id => '15' should_route :delete, "/news/567/comments/15", :controller => 'comments', :action => 'destroy', :id => '567', :comment_id => '15'
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment