Refactor: move NewsController#preview to PreviewsController#news

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4174 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-09-24 16:26:46 +00:00
parent 20305418f4
commit deed1b949d
10 changed files with 35 additions and 29 deletions

View File

@ -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])

View File

@ -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

View File

@ -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) %>

View File

@ -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) %> |

View File

@ -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) %>

View File

@ -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) %> |

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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'