summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-09-24 16:26:46 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-09-24 16:26:46 +0000
commitdeed1b949d6340c87a2cee9cca411e70d908eaf4 (patch)
tree7b6f81ef08306483f0490bb16ea00f9a7da4d693
parent20305418f475abced81843a847d1192a74647f69 (diff)
downloadredmine-deed1b949d6340c87a2cee9cca411e70d908eaf4.tar.gz
redmine-deed1b949d6340c87a2cee9cca411e70d908eaf4.zip
Refactor: move NewsController#preview to PreviewsController#news
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4174 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/news_controller.rb13
-rw-r--r--app/controllers/previews_controller.rb5
-rw-r--r--app/views/news/edit.rhtml4
-rw-r--r--app/views/news/index.rhtml4
-rw-r--r--app/views/news/new.rhtml4
-rw-r--r--app/views/news/show.rhtml4
-rw-r--r--config/routes.rb3
-rw-r--r--test/functional/news_controller_test.rb11
-rw-r--r--test/functional/previews_controller_test.rb10
-rw-r--r--test/integration/routing_test.rb6
10 files changed, 35 insertions, 29 deletions
diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 47f467862..eebc0ba02 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -18,10 +18,10 @@
class NewsController < ApplicationController
default_search_scope :news
model_object News
- before_filter :find_model_object, :except => [:new, :create, :index, :preview]
- before_filter :find_project_from_association, :except => [:new, :create, :index, :preview]
- before_filter :find_project, :only => [:new, :create, :preview]
- before_filter :authorize, :except => [:index, :preview]
+ before_filter :find_model_object, :except => [:new, :create, :index]
+ before_filter :find_project_from_association, :except => [:new, :create, :index]
+ before_filter :find_project, :only => [:new, :create]
+ before_filter :authorize, :except => [:index]
before_filter :find_optional_project, :only => :index
accept_key_auth :index
@@ -78,11 +78,6 @@ class NewsController < ApplicationController
redirect_to :action => 'index', :project_id => @project
end
- def preview
- @text = (params[:news] ? params[:news][:description] : nil)
- render :partial => 'common/preview'
- end
-
private
def find_project
@project = Project.find(params[:project_id])
diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb
index e1c644653..612025cb8 100644
--- a/app/controllers/previews_controller.rb
+++ b/app/controllers/previews_controller.rb
@@ -16,6 +16,11 @@ class PreviewsController < ApplicationController
render :layout => false
end
+ def news
+ @text = (params[:news] ? params[:news][:description] : nil)
+ render :partial => 'common/preview'
+ end
+
private
def find_project
diff --git a/app/views/news/edit.rhtml b/app/views/news/edit.rhtml
index da256031d..704820089 100644
--- a/app/views/news/edit.rhtml
+++ b/app/views/news/edit.rhtml
@@ -5,8 +5,8 @@
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
- :method => 'post',
+ { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ :method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %>
diff --git a/app/views/news/index.rhtml b/app/views/news/index.rhtml
index 2b53b7f72..d65bdf2f3 100644
--- a/app/views/news/index.rhtml
+++ b/app/views/news/index.rhtml
@@ -12,8 +12,8 @@
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
- :method => 'post',
+ { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ :method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %> |
diff --git a/app/views/news/new.rhtml b/app/views/news/new.rhtml
index 74ae64ae8..929e6b874 100644
--- a/app/views/news/new.rhtml
+++ b/app/views/news/new.rhtml
@@ -5,8 +5,8 @@
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
- :method => 'post',
+ { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ :method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %>
diff --git a/app/views/news/show.rhtml b/app/views/news/show.rhtml
index 7861a3d01..af93af261 100644
--- a/app/views/news/show.rhtml
+++ b/app/views/news/show.rhtml
@@ -16,8 +16,8 @@
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
- :method => 'post',
+ { :url => { :controller => 'previews', :action => 'news', :project_id => @project },
+ :method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %> |
diff --git a/config/routes.rb b/config/routes.rb
index 42e778d0a..f0d9f503a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -138,6 +138,9 @@ ActionController::Routing::Routes.draw do |map|
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'
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index 219c4d7a7..30ca5a26e 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -117,15 +117,4 @@ class NewsControllerTest < ActionController::TestCase
assert_redirected_to 'projects/ecookbook/news'
assert_nil News.find_by_id(1)
end
-
- def test_preview
- get :preview, :project_id => 1,
- :news => {:title => '',
- :description => 'News description',
- :summary => ''}
- assert_response :success
- assert_template 'common/_preview'
- assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
- :content => /News description/
- end
end
diff --git a/test/functional/previews_controller_test.rb b/test/functional/previews_controller_test.rb
index 63456d1d0..4140f1428 100644
--- a/test/functional/previews_controller_test.rb
+++ b/test/functional/previews_controller_test.rb
@@ -19,4 +19,14 @@ class PreviewsControllerTest < ActionController::TestCase
assert_not_nil assigns(:notes)
end
+ def test_news
+ get :news, :project_id => 1,
+ :news => {:title => '',
+ :description => 'News description',
+ :summary => ''}
+ assert_response :success
+ assert_template 'common/_preview'
+ assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
+ :content => /News description/
+ end
end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index 3376f9313..be12dd027 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -157,10 +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'