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
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])
render :layout => false
end
+ def news
+ @text = (params[:news] ? params[:news][:description] : nil)
+ render :partial => 'common/preview'
+ end
+
private
def find_project
<%= 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) %>
<%= 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) %> |
<%= 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) %>
<%= 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) %> |
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'
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
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
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'