@@ -1,50 +1,54 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class PreviewsController < ApplicationController |
|
19 | 19 | before_filter :find_project |
|
20 | 20 | |
|
21 | 21 | def issue |
|
22 | 22 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
23 | 23 | if @issue |
|
24 | 24 | @attachements = @issue.attachments |
|
25 | 25 | @description = params[:issue] && params[:issue][:description] |
|
26 | 26 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") |
|
27 | 27 | @description = nil |
|
28 | 28 | end |
|
29 | 29 | @notes = params[:notes] |
|
30 | 30 | else |
|
31 | 31 | @description = (params[:issue] ? params[:issue][:description] : nil) |
|
32 | 32 | end |
|
33 | 33 | render :layout => false |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def news |
|
37 | if params[:id].present? && news = News.visible.find_by_id(params[:id]) | |
|
38 | @previewed = news | |
|
39 | @attachments = news.attachments | |
|
40 | end | |
|
37 | 41 | @text = (params[:news] ? params[:news][:description] : nil) |
|
38 | 42 | render :partial => 'common/preview' |
|
39 | 43 | end |
|
40 | 44 | |
|
41 | 45 | private |
|
42 | 46 | |
|
43 | 47 | def find_project |
|
44 | 48 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
45 | 49 | @project = Project.find(project_id) |
|
46 | 50 | rescue ActiveRecord::RecordNotFound |
|
47 | 51 | render_404 |
|
48 | 52 | end |
|
49 | 53 | |
|
50 | 54 | end |
@@ -1,12 +1,12 | |||
|
1 | 1 | <h2><%=l(:label_news)%></h2> |
|
2 | 2 | |
|
3 | 3 | <%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> |
|
4 | 4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
5 | 5 | <%= submit_tag l(:button_save) %> |
|
6 | <%= preview_link preview_news_path(:project_id => @project), 'news-form' %> | |
|
6 | <%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> | |
|
7 | 7 | <% end %> |
|
8 | 8 | <div id="preview" class="wiki"></div> |
|
9 | 9 | |
|
10 | 10 | <% content_for :header_tags do %> |
|
11 | 11 | <%= stylesheet_link_tag 'scm' %> |
|
12 | 12 | <% end %> |
@@ -1,62 +1,62 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= watcher_tag(@news, User.current) %> |
|
3 | 3 | <%= link_to(l(:button_edit), |
|
4 | 4 | edit_news_path(@news), |
|
5 | 5 | :class => 'icon icon-edit', |
|
6 | 6 | :accesskey => accesskey(:edit), |
|
7 | 7 | :onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_news, @project) %> |
|
8 | 8 | <%= delete_link news_path(@news) if User.current.allowed_to?(:manage_news, @project) %> |
|
9 | 9 | </div> |
|
10 | 10 | |
|
11 | 11 | <h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2> |
|
12 | 12 | |
|
13 | 13 | <% if authorize_for('news', 'edit') %> |
|
14 | 14 | <div id="edit-news" style="display:none;"> |
|
15 | 15 | <%= labelled_form_for :news, @news, :url => news_path(@news), |
|
16 | 16 | :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> |
|
17 | 17 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
18 | 18 | <%= submit_tag l(:button_save) %> |
|
19 | <%= preview_link preview_news_path(:project_id => @project), 'news-form' %> | | |
|
19 | <%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> | | |
|
20 | 20 | <%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %> |
|
21 | 21 | <% end %> |
|
22 | 22 | <div id="preview" class="wiki"></div> |
|
23 | 23 | </div> |
|
24 | 24 | <% end %> |
|
25 | 25 | |
|
26 | 26 | <p><% unless @news.summary.blank? %><em><%=h @news.summary %></em><br /><% end %> |
|
27 | 27 | <span class="author"><%= authoring @news.created_on, @news.author %></span></p> |
|
28 | 28 | <div class="wiki"> |
|
29 | 29 | <%= textilizable(@news, :description) %> |
|
30 | 30 | </div> |
|
31 | 31 | <%= link_to_attachments @news %> |
|
32 | 32 | <br /> |
|
33 | 33 | |
|
34 | 34 | <div id="comments" style="margin-bottom:16px;"> |
|
35 | 35 | <h3 class="comments"><%= l(:label_comment_plural) %></h3> |
|
36 | 36 | <% @comments.each do |comment| %> |
|
37 | 37 | <% next if comment.new_record? %> |
|
38 | 38 | <div class="contextual"> |
|
39 | 39 | <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment}, |
|
40 | 40 | :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %> |
|
41 | 41 | </div> |
|
42 | 42 | <h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4> |
|
43 | 43 | <%= textilizable(comment.comments) %> |
|
44 | 44 | <% end if @comments.any? %> |
|
45 | 45 | </div> |
|
46 | 46 | |
|
47 | 47 | <% if @news.commentable? %> |
|
48 | 48 | <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p> |
|
49 | 49 | <%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %> |
|
50 | 50 | <div class="box"> |
|
51 | 51 | <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %> |
|
52 | 52 | <%= wikitoolbar_for 'comment_comments' %> |
|
53 | 53 | </div> |
|
54 | 54 | <p><%= submit_tag l(:button_add) %></p> |
|
55 | 55 | <% end %> |
|
56 | 56 | <% end %> |
|
57 | 57 | |
|
58 | 58 | <% html_title @news.title -%> |
|
59 | 59 | |
|
60 | 60 | <% content_for :header_tags do %> |
|
61 | 61 | <%= stylesheet_link_tag 'scm' %> |
|
62 | 62 | <% end %> |
@@ -1,68 +1,83 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class PreviewsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
22 | 22 | :enumerations, :users, :issue_categories, |
|
23 | 23 | :projects_trackers, |
|
24 | 24 | :roles, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :members, |
|
27 | 27 | :enabled_modules, |
|
28 | 28 | :workflows, |
|
29 | :journals, :journal_details | |
|
29 | :journals, :journal_details, | |
|
30 | :news | |
|
30 | 31 | |
|
31 | 32 | def test_preview_new_issue |
|
32 | 33 | @request.session[:user_id] = 2 |
|
33 | 34 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} |
|
34 | 35 | assert_response :success |
|
35 | 36 | assert_template 'preview' |
|
36 | 37 | assert_not_nil assigns(:description) |
|
37 | 38 | end |
|
38 | 39 | |
|
39 | 40 | def test_preview_issue_notes |
|
40 | 41 | @request.session[:user_id] = 2 |
|
41 | 42 | post :issue, :project_id => '1', :id => 1, |
|
42 | 43 | :issue => {:description => Issue.find(1).description}, |
|
43 | 44 | :notes => 'Foo' |
|
44 | 45 | assert_response :success |
|
45 | 46 | assert_template 'preview' |
|
46 | 47 | assert_not_nil assigns(:notes) |
|
47 | 48 | end |
|
48 | 49 | |
|
49 | 50 | def test_preview_journal_notes_for_update |
|
50 | 51 | @request.session[:user_id] = 2 |
|
51 | 52 | post :issue, :project_id => '1', :id => 1, :notes => 'Foo' |
|
52 | 53 | assert_response :success |
|
53 | 54 | assert_template 'preview' |
|
54 | 55 | assert_not_nil assigns(:notes) |
|
55 | 56 | assert_tag :p, :content => 'Foo' |
|
56 | 57 | end |
|
57 | 58 | |
|
58 | def test_news | |
|
59 | def test_preview_new_news | |
|
59 | 60 | get :news, :project_id => 1, |
|
60 | 61 | :news => {:title => '', |
|
61 | 62 | :description => 'News description', |
|
62 | 63 | :summary => ''} |
|
63 | 64 | assert_response :success |
|
64 | 65 | assert_template 'common/_preview' |
|
65 | 66 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, |
|
66 | 67 | :content => /News description/ |
|
67 | 68 | end |
|
69 | ||
|
70 | def test_existing_new_news | |
|
71 | get :news, :project_id => 1, :id => 2, | |
|
72 | :news => {:title => '', | |
|
73 | :description => 'News description', | |
|
74 | :summary => ''} | |
|
75 | assert_response :success | |
|
76 | assert_template 'common/_preview' | |
|
77 | assert_equal News.find(2), assigns(:previewed) | |
|
78 | assert_not_nil assigns(:attachments) | |
|
79 | ||
|
80 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, | |
|
81 | :content => /News description/ | |
|
82 | end | |
|
68 | 83 | end |
General Comments 0
You need to be logged in to leave comments.
Login now