Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor: move NewsController#preview to PreviewsController#news
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4174 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Sep 24, 2010
1 parent 2030541 commit deed1b9
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 29 deletions.
13 changes: 4 additions & 9 deletions app/controllers/news_controller.rb
Expand Up @@ -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

Expand Down Expand Up @@ -78,11 +78,6 @@ def destroy
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])
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/previews_controller.rb
Expand Up @@ -16,6 +16,11 @@ def issue
render :layout => false
end

def news
@text = (params[:news] ? params[:news][:description] : nil)
render :partial => 'common/preview'
end

private

def find_project
Expand Down
4 changes: 2 additions & 2 deletions app/views/news/edit.rhtml
Expand Up @@ -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) %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/news/index.rhtml
Expand Up @@ -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) %> |
Expand Down
4 changes: 2 additions & 2 deletions app/views/news/new.rhtml
Expand Up @@ -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) %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/news/show.rhtml
Expand Up @@ -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) %> |
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Expand Up @@ -138,6 +138,9 @@
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'
Expand Down
11 changes: 0 additions & 11 deletions test/functional/news_controller_test.rb
Expand Up @@ -117,15 +117,4 @@ def test_destroy
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
10 changes: 10 additions & 0 deletions test/functional/previews_controller_test.rb
Expand Up @@ -19,4 +19,14 @@ def test_preview_issue_notes
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
6 changes: 5 additions & 1 deletion test/integration/routing_test.rb
Expand Up @@ -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'

Expand Down

0 comments on commit deed1b9

Please sign in to comment.