summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-09-27 16:51:12 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-09-27 16:51:12 +0000
commit79e30e7087d714ad81de83d389c37ae7d46d4dad (patch)
treece724e68907a3363c126bfc6d029c53539e9801f
parent0a224e8bb1a5939fb2745bfc936f9432960a9672 (diff)
downloadredmine-79e30e7087d714ad81de83d389c37ae7d46d4dad.tar.gz
redmine-79e30e7087d714ad81de83d389c37ae7d46d4dad.zip
Refactor: convert News to a REST resource
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4214 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/views/news/_news.rhtml2
-rw-r--r--app/views/news/edit.rhtml4
-rw-r--r--app/views/news/index.rhtml8
-rw-r--r--app/views/news/new.rhtml4
-rw-r--r--app/views/news/show.rhtml8
-rw-r--r--config/routes.rb30
-rw-r--r--test/functional/news_controller_test.rb2
-rw-r--r--test/integration/routing_test.rb7
8 files changed, 23 insertions, 42 deletions
diff --git a/app/views/news/_news.rhtml b/app/views/news/_news.rhtml
index 8f481f09c..ddbaecabf 100644
--- a/app/views/news/_news.rhtml
+++ b/app/views/news/_news.rhtml
@@ -1,5 +1,5 @@
<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 %>
<br />
<% unless news.summary.blank? %><span class="summary"><%=h news.summary %></span><br /><% end %>
diff --git a/app/views/news/edit.rhtml b/app/views/news/edit.rhtml
index 704820089..0d44bfbb9 100644
--- a/app/views/news/edit.rhtml
+++ b/app/views/news/edit.rhtml
@@ -1,11 +1,11 @@
<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| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ { :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
diff --git a/app/views/news/index.rhtml b/app/views/news/index.rhtml
index d65bdf2f3..c2a227fe0 100644
--- a/app/views/news/index.rhtml
+++ b/app/views/news/index.rhtml
@@ -1,18 +1,18 @@
<div class="contextual">
<%= link_to_if_authorized(l(:label_news_new),
- {:controller => 'news', :action => 'new', :project_id => @project},
+ new_project_news_path(@project),
:class => 'icon icon-add',
:onclick => 'Element.show("add-news"); Form.Element.focus("news_title"); return false;') if @project %>
</div>
<div id="add-news" style="display:none;">
<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| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ { :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
@@ -29,7 +29,7 @@
<% else %>
<% @newss.each do |news| %>
<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>
<p class="author"><%= authoring news.created_on, news.author %></p>
<div class="wiki">
diff --git a/app/views/news/new.rhtml b/app/views/news/new.rhtml
index 929e6b874..946646e3e 100644
--- a/app/views/news/new.rhtml
+++ b/app/views/news/new.rhtml
@@ -1,11 +1,11 @@
<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| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ { :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
diff --git a/app/views/news/show.rhtml b/app/views/news/show.rhtml
index af93af261..119436d5d 100644
--- a/app/views/news/show.rhtml
+++ b/app/views/news/show.rhtml
@@ -1,22 +1,22 @@
<div class="contextual">
<%= link_to_if_authorized l(:button_edit),
- {:controller => 'news', :action => 'edit', :id => @news},
+ edit_news_path(@news),
:class => 'icon icon-edit',
:accesskey => accesskey(:edit),
: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>
<h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2>
<% if authorize_for('news', 'edit') %>
<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| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ { :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
diff --git a/config/routes.rb b/config/routes.rb
index f0d9f503a..eab2157d8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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/destroy', :action => 'destroy'
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.with_options :controller => 'users' do |users|
@@ -182,6 +159,12 @@ ActionController::Routing::Routes.draw do |map|
# For nice "roadmap" in the url for the index action
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 => {
:copy => [:get, :post],
:settings => :get,
@@ -192,6 +175,7 @@ ActionController::Routing::Routes.draw do |map|
project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
project.resources :files, :only => [:index, :new, :create]
project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post}
+ project.resources :news, :shallow => true
end
# Destroy uses a get request to prompt the user before the actual DELETE request
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index 30ca5a26e..de5c055a4 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -113,7 +113,7 @@ class NewsControllerTest < ActionController::TestCase
def test_destroy
@request.session[:user_id] = 2
- post :destroy, :id => 1
+ delete :destroy, :id => 1
assert_redirected_to 'projects/ecookbook/news'
assert_nil News.find_by_id(1)
end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index be12dd027..37f262909 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -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, "/news/234", :controller => 'news', :action => 'show', :id => '234'
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 :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, "/issues/preview/123", :controller => 'previews', :action => 'issue', :id => '123'
-
- should_route :put, "/news/567/edit", :controller => 'news', :action => 'update', :id => '567'
+ should_route :put, "/news/567", :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'
end