@@ -27,6 +27,7 class NewsController < ApplicationController | |||
|
27 | 27 | accept_api_auth :index |
|
28 | 28 | |
|
29 | 29 | helper :watchers |
|
30 | helper :attachments | |
|
30 | 31 | |
|
31 | 32 | def index |
|
32 | 33 | case params[:format] |
@@ -70,6 +71,8 class NewsController < ApplicationController | |||
|
70 | 71 | if request.post? |
|
71 | 72 | @news.attributes = params[:news] |
|
72 | 73 | if @news.save |
|
74 | attachments = Attachment.attach_files(@news, params[:attachments]) | |
|
75 | render_attachment_warning_if_needed(@news) | |
|
73 | 76 | flash[:notice] = l(:notice_successful_create) |
|
74 | 77 | redirect_to :controller => 'news', :action => 'index', :project_id => @project |
|
75 | 78 | else |
@@ -83,6 +86,8 class NewsController < ApplicationController | |||
|
83 | 86 | |
|
84 | 87 | def update |
|
85 | 88 | if request.put? and @news.update_attributes(params[:news]) |
|
89 | attachments = Attachment.attach_files(@news, params[:attachments]) | |
|
90 | render_attachment_warning_if_needed(@news) | |
|
86 | 91 | flash[:notice] = l(:notice_successful_update) |
|
87 | 92 | redirect_to :action => 'show', :id => @news |
|
88 | 93 | else |
@@ -24,6 +24,7 class News < ActiveRecord::Base | |||
|
24 | 24 | validates_length_of :title, :maximum => 60 |
|
25 | 25 | validates_length_of :summary, :maximum => 255 |
|
26 | 26 | |
|
27 | acts_as_attachable :delete_permission => :manage_news | |
|
27 | 28 | acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project |
|
28 | 29 | acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}} |
|
29 | 30 | acts_as_activity_provider :find_options => {:include => [:project, :author]}, |
@@ -3,6 +3,7 | |||
|
3 | 3 | <p><%= f.text_field :title, :required => true, :size => 60 %></p> |
|
4 | 4 | <p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p> |
|
5 | 5 | <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p> |
|
6 | <p id="attachments_form"><%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form' %></p> | |
|
6 | 7 | </div> |
|
7 | ||
|
8 | ||
|
8 | 9 | <%= wikitoolbar_for 'news_description' %> |
@@ -1,6 +1,6 | |||
|
1 | 1 | <h2><%=l(:label_news)%></h2> |
|
2 | 2 | |
|
3 | <% labelled_form_for @news, :html => { :id => 'news-form', :method => :put } do |f| %> | |
|
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 | 6 | <%= link_to_remote l(:label_preview), |
@@ -8,7 +8,7 | |||
|
8 | 8 | <div id="add-news" style="display:none;"> |
|
9 | 9 | <h2><%=l(:label_news_new)%></h2> |
|
10 | 10 | <% labelled_form_for @news, :url => project_news_index_path(@project), |
|
11 | :html => { :id => 'news-form' } do |f| %> | |
|
11 | :html => { :id => 'news-form', :multipart => true } do |f| %> | |
|
12 | 12 | <%= render :partial => 'news/form', :locals => { :f => f } %> |
|
13 | 13 | <%= submit_tag l(:button_create) %> |
|
14 | 14 | <%= link_to_remote l(:label_preview), |
@@ -1,7 +1,7 | |||
|
1 | 1 | <h2><%=l(:label_news_new)%></h2> |
|
2 | 2 | |
|
3 | 3 | <% labelled_form_for @news, :url => project_news_index_path(@project), |
|
4 | :html => { :id => 'news-form' } do |f| %> | |
|
4 | :html => { :id => 'news-form', :multipart => true } do |f| %> | |
|
5 | 5 | <%= render :partial => 'news/form', :locals => { :f => f } %> |
|
6 | 6 | <%= submit_tag l(:button_create) %> |
|
7 | 7 | <%= link_to_remote l(:label_preview), |
@@ -17,7 +17,7 | |||
|
17 | 17 | <% if authorize_for('news', 'edit') %> |
|
18 | 18 | <div id="edit-news" style="display:none;"> |
|
19 | 19 | <% labelled_form_for :news, @news, :url => news_path(@news), |
|
20 | :html => { :id => 'news-form', :method => :put } do |f| %> | |
|
20 | :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> | |
|
21 | 21 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
22 | 22 | <%= submit_tag l(:button_save) %> |
|
23 | 23 | <%= link_to_remote l(:label_preview), |
@@ -35,8 +35,9 | |||
|
35 | 35 | <p><% unless @news.summary.blank? %><em><%=h @news.summary %></em><br /><% end %> |
|
36 | 36 | <span class="author"><%= authoring @news.created_on, @news.author %></span></p> |
|
37 | 37 | <div class="wiki"> |
|
38 |
<%= textilizable(@news |
|
|
38 | <%= textilizable(@news, :description) %> | |
|
39 | 39 | </div> |
|
40 | <%= link_to_attachments @news %> | |
|
40 | 41 | <br /> |
|
41 | 42 | |
|
42 | 43 | <div id="comments" style="margin-bottom:16px;"> |
@@ -53,6 +53,16 class NewsControllerTest < ActionController::TestCase | |||
|
53 | 53 | assert_tag :tag => 'h2', :content => /eCookbook first release/ |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | def test_show_should_show_attachments | |
|
57 | attachment = Attachment.first | |
|
58 | attachment.container = News.find(1) | |
|
59 | attachment.save! | |
|
60 | ||
|
61 | get :show, :id => 1 | |
|
62 | assert_response :success | |
|
63 | assert_tag 'a', :content => attachment.filename | |
|
64 | end | |
|
65 | ||
|
56 | 66 | def test_show_not_found |
|
57 | 67 | get :show, :id => 999 |
|
58 | 68 | assert_response 404 |
@@ -83,6 +93,34 class NewsControllerTest < ActionController::TestCase | |||
|
83 | 93 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
84 | 94 | end |
|
85 | 95 | |
|
96 | def test_post_create_with_attachment | |
|
97 | set_tmp_attachments_directory | |
|
98 | @request.session[:user_id] = 2 | |
|
99 | assert_difference 'News.count' do | |
|
100 | assert_difference 'Attachment.count' do | |
|
101 | post :create, :project_id => 1, | |
|
102 | :news => { :title => 'Test', :description => 'This is the description' }, | |
|
103 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
|
104 | end | |
|
105 | end | |
|
106 | attachment = Attachment.first(:order => 'id DESC') | |
|
107 | news = News.first(:order => 'id DESC') | |
|
108 | assert_equal news, attachment.container | |
|
109 | end | |
|
110 | ||
|
111 | def test_post_create_with_validation_failure | |
|
112 | @request.session[:user_id] = 2 | |
|
113 | post :create, :project_id => 1, :news => { :title => '', | |
|
114 | :description => 'This is the description', | |
|
115 | :summary => '' } | |
|
116 | assert_response :success | |
|
117 | assert_template 'new' | |
|
118 | assert_not_nil assigns(:news) | |
|
119 | assert assigns(:news).new_record? | |
|
120 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, | |
|
121 | :content => /1 error/ | |
|
122 | end | |
|
123 | ||
|
86 | 124 | def test_get_edit |
|
87 | 125 | @request.session[:user_id] = 2 |
|
88 | 126 | get :edit, :id => 1 |
@@ -98,17 +136,18 class NewsControllerTest < ActionController::TestCase | |||
|
98 | 136 | assert_equal 'Description changed by test_post_edit', news.description |
|
99 | 137 | end |
|
100 | 138 | |
|
101 |
def test_p |
|
|
139 | def test_put_update_with_attachment | |
|
140 | set_tmp_attachments_directory | |
|
102 | 141 | @request.session[:user_id] = 2 |
|
103 | post :create, :project_id => 1, :news => { :title => '', | |
|
104 | :description => 'This is the description', | |
|
105 | :summary => '' } | |
|
106 | assert_response :success | |
|
107 | assert_template 'new' | |
|
108 | assert_not_nil assigns(:news) | |
|
109 | assert assigns(:news).new_record? | |
|
110 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, | |
|
111 | :content => /1 error/ | |
|
142 | assert_no_difference 'News.count' do | |
|
143 | assert_difference 'Attachment.count' do | |
|
144 | put :update, :id => 1, | |
|
145 | :news => { :description => 'This is the description' }, | |
|
146 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
|
147 | end | |
|
148 | end | |
|
149 | attachment = Attachment.first(:order => 'id DESC') | |
|
150 | assert_equal News.find(1), attachment.container | |
|
112 | 151 | end |
|
113 | 152 | |
|
114 | 153 | def test_destroy |
@@ -71,4 +71,19 class NewsTest < ActiveSupport::TestCase | |||
|
71 | 71 | 10.times { projects(:projects_001).news.create(valid_news) } |
|
72 | 72 | assert_equal 5, News.latest(users(:users_004)).size |
|
73 | 73 | end |
|
74 | ||
|
75 | def test_attachments_should_be_visible | |
|
76 | assert News.find(1).attachments_visible?(User.anonymous) | |
|
77 | end | |
|
78 | ||
|
79 | def test_attachments_should_be_deletable_with_manage_news_permission | |
|
80 | manager = User.find(2) | |
|
81 | assert News.find(1).attachments_deletable?(manager) | |
|
82 | end | |
|
83 | ||
|
84 | def test_attachments_should_not_be_deletable_without_manage_news_permission | |
|
85 | manager = User.find(2) | |
|
86 | Role.find_by_name('Manager').remove_permission!(:manage_news) | |
|
87 | assert !News.find(1).attachments_deletable?(manager) | |
|
88 | end | |
|
74 | 89 | end |
General Comments 0
You need to be logged in to leave comments.
Login now