diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb index 6960dfff5..cd947148d 100644 --- a/app/controllers/previews_controller.rb +++ b/app/controllers/previews_controller.rb @@ -34,6 +34,10 @@ class PreviewsController < ApplicationController end def news + if params[:id].present? && news = News.visible.find_by_id(params[:id]) + @previewed = news + @attachments = news.attachments + end @text = (params[:news] ? params[:news][:description] : nil) render :partial => 'common/preview' end diff --git a/app/views/news/edit.html.erb b/app/views/news/edit.html.erb index 499451bb7..4e4cf2e2b 100644 --- a/app/views/news/edit.html.erb +++ b/app/views/news/edit.html.erb @@ -3,7 +3,7 @@ <%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> -<%= preview_link preview_news_path(:project_id => @project), 'news-form' %> +<%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> <% end %>
diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 295aecfb2..d4c0bae3e 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -16,7 +16,7 @@ :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> -<%= preview_link preview_news_path(:project_id => @project), 'news-form' %> | +<%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> | <%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %> <% end %> diff --git a/test/functional/previews_controller_test.rb b/test/functional/previews_controller_test.rb index e788b1504..67264e76b 100644 --- a/test/functional/previews_controller_test.rb +++ b/test/functional/previews_controller_test.rb @@ -26,7 +26,8 @@ class PreviewsControllerTest < ActionController::TestCase :members, :enabled_modules, :workflows, - :journals, :journal_details + :journals, :journal_details, + :news def test_preview_new_issue @request.session[:user_id] = 2 @@ -55,7 +56,7 @@ class PreviewsControllerTest < ActionController::TestCase assert_tag :p, :content => 'Foo' end - def test_news + def test_preview_new_news get :news, :project_id => 1, :news => {:title => '', :description => 'News description', @@ -65,4 +66,18 @@ class PreviewsControllerTest < ActionController::TestCase assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, :content => /News description/ end + + def test_existing_new_news + get :news, :project_id => 1, :id => 2, + :news => {:title => '', + :description => 'News description', + :summary => ''} + assert_response :success + assert_template 'common/_preview' + assert_equal News.find(2), assigns(:previewed) + assert_not_nil assigns(:attachments) + + assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, + :content => /News description/ + end end