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:
parent
20305418f4
commit
deed1b949d
@ -18,10 +18,10 @@
|
|||||||
class NewsController < ApplicationController
|
class NewsController < ApplicationController
|
||||||
default_search_scope :news
|
default_search_scope :news
|
||||||
model_object News
|
model_object News
|
||||||
before_filter :find_model_object, :except => [:new, :create, :index, :preview]
|
before_filter :find_model_object, :except => [:new, :create, :index]
|
||||||
before_filter :find_project_from_association, :except => [:new, :create, :index, :preview]
|
before_filter :find_project_from_association, :except => [:new, :create, :index]
|
||||||
before_filter :find_project, :only => [:new, :create, :preview]
|
before_filter :find_project, :only => [:new, :create]
|
||||||
before_filter :authorize, :except => [:index, :preview]
|
before_filter :authorize, :except => [:index]
|
||||||
before_filter :find_optional_project, :only => :index
|
before_filter :find_optional_project, :only => :index
|
||||||
accept_key_auth :index
|
accept_key_auth :index
|
||||||
|
|
||||||
@ -78,11 +78,6 @@ class NewsController < ApplicationController
|
|||||||
redirect_to :action => 'index', :project_id => @project
|
redirect_to :action => 'index', :project_id => @project
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview
|
|
||||||
@text = (params[:news] ? params[:news][:description] : nil)
|
|
||||||
render :partial => 'common/preview'
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
|
@ -16,6 +16,11 @@ class PreviewsController < ApplicationController
|
|||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def news
|
||||||
|
@text = (params[:news] ? params[:news][:description] : nil)
|
||||||
|
render :partial => 'common/preview'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
<%= 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 => 'news', :action => 'preview', :project_id => @project },
|
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project },
|
||||||
:method => 'post',
|
:method => 'get',
|
||||||
:update => 'preview',
|
:update => 'preview',
|
||||||
:with => "Form.serialize('news-form')"
|
:with => "Form.serialize('news-form')"
|
||||||
}, :accesskey => accesskey(:preview) %>
|
}, :accesskey => accesskey(:preview) %>
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
<%= 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 => 'news', :action => 'preview', :project_id => @project },
|
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project },
|
||||||
:method => 'post',
|
:method => 'get',
|
||||||
:update => 'preview',
|
:update => 'preview',
|
||||||
:with => "Form.serialize('news-form')"
|
:with => "Form.serialize('news-form')"
|
||||||
}, :accesskey => accesskey(:preview) %> |
|
}, :accesskey => accesskey(:preview) %> |
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
<%= 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 => 'news', :action => 'preview', :project_id => @project },
|
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project },
|
||||||
:method => 'post',
|
:method => 'get',
|
||||||
:update => 'preview',
|
:update => 'preview',
|
||||||
:with => "Form.serialize('news-form')"
|
:with => "Form.serialize('news-form')"
|
||||||
}, :accesskey => accesskey(:preview) %>
|
}, :accesskey => accesskey(:preview) %>
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
<%= 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 => 'news', :action => 'preview', :project_id => @project },
|
{ :url => { :controller => 'previews', :action => 'news', :project_id => @project },
|
||||||
:method => 'post',
|
:method => 'get',
|
||||||
:update => 'preview',
|
:update => 'preview',
|
||||||
:with => "Form.serialize('news-form')"
|
:with => "Form.serialize('news-form')"
|
||||||
}, :accesskey => accesskey(:preview) %> |
|
}, :accesskey => accesskey(:preview) %> |
|
||||||
|
@ -138,6 +138,9 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
end
|
end
|
||||||
|
|
||||||
map.with_options :controller => 'news' do |news_routes|
|
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_routes.with_options :conditions => {:method => :get} do |news_views|
|
||||||
news_views.connect 'news', :action => 'index'
|
news_views.connect 'news', :action => 'index'
|
||||||
news_views.connect 'projects/:project_id/news', :action => 'index'
|
news_views.connect 'projects/:project_id/news', :action => 'index'
|
||||||
|
@ -117,15 +117,4 @@ class NewsControllerTest < ActionController::TestCase
|
|||||||
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
|
||||||
|
|
||||||
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
|
end
|
||||||
|
@ -19,4 +19,14 @@ class PreviewsControllerTest < ActionController::TestCase
|
|||||||
assert_not_nil assigns(:notes)
|
assert_not_nil assigns(:notes)
|
||||||
end
|
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
|
end
|
||||||
|
@ -157,11 +157,15 @@ 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 :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/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/edit", :controller => 'news', :action => 'update', :id => '567'
|
should_route :put, "/news/567/edit", :controller => 'news', :action => 'update', :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'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user