@@ -1,165 +1,165 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 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 NewsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_index |
|
28 | 28 | get :index |
|
29 | 29 | assert_response :success |
|
30 | 30 | assert_template 'index' |
|
31 | 31 | assert_not_nil assigns(:newss) |
|
32 | 32 | assert_nil assigns(:project) |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_index_with_project |
|
36 | 36 | get :index, :project_id => 1 |
|
37 | 37 | assert_response :success |
|
38 | 38 | assert_template 'index' |
|
39 | 39 | assert_not_nil assigns(:newss) |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_index_with_invalid_project_should_respond_with_404 |
|
43 | 43 | get :index, :project_id => 999 |
|
44 | 44 | assert_response 404 |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def test_show |
|
48 | 48 | get :show, :id => 1 |
|
49 | 49 | assert_response :success |
|
50 | 50 | assert_template 'show' |
|
51 | 51 | assert_tag :tag => 'h2', :content => /eCookbook first release/ |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_show_should_show_attachments |
|
55 | 55 | attachment = Attachment.first |
|
56 | 56 | attachment.container = News.find(1) |
|
57 | 57 | attachment.save! |
|
58 | 58 | |
|
59 | 59 | get :show, :id => 1 |
|
60 | 60 | assert_response :success |
|
61 | 61 | assert_tag 'a', :content => attachment.filename |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def test_show_not_found |
|
65 | 65 | get :show, :id => 999 |
|
66 | 66 | assert_response 404 |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def test_get_new |
|
70 | 70 | @request.session[:user_id] = 2 |
|
71 | 71 | get :new, :project_id => 1 |
|
72 | 72 | assert_response :success |
|
73 | 73 | assert_template 'new' |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def test_post_create |
|
77 | 77 | ActionMailer::Base.deliveries.clear |
|
78 | 78 | @request.session[:user_id] = 2 |
|
79 | 79 | |
|
80 | 80 | with_settings :notified_events => %w(news_added) do |
|
81 | 81 | post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', |
|
82 | 82 | :description => 'This is the description', |
|
83 | 83 | :summary => '' } |
|
84 | 84 | end |
|
85 | 85 | assert_redirected_to '/projects/ecookbook/news' |
|
86 | 86 | |
|
87 | 87 | news = News.find_by_title('NewsControllerTest') |
|
88 | 88 | assert_not_nil news |
|
89 | 89 | assert_equal 'This is the description', news.description |
|
90 | 90 | assert_equal User.find(2), news.author |
|
91 | 91 | assert_equal Project.find(1), news.project |
|
92 | 92 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def test_post_create_with_attachment |
|
96 | 96 | set_tmp_attachments_directory |
|
97 | 97 | @request.session[:user_id] = 2 |
|
98 | 98 | assert_difference 'News.count' do |
|
99 | 99 | assert_difference 'Attachment.count' do |
|
100 | 100 | post :create, :project_id => 1, |
|
101 | 101 | :news => { :title => 'Test', :description => 'This is the description' }, |
|
102 | 102 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
103 | 103 | end |
|
104 | 104 | end |
|
105 |
attachment = Attachment. |
|
|
106 |
news = News. |
|
|
105 | attachment = Attachment.order('id DESC').first | |
|
106 | news = News.order('id DESC').first | |
|
107 | 107 | assert_equal news, attachment.container |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def test_post_create_with_validation_failure |
|
111 | 111 | @request.session[:user_id] = 2 |
|
112 | 112 | post :create, :project_id => 1, :news => { :title => '', |
|
113 | 113 | :description => 'This is the description', |
|
114 | 114 | :summary => '' } |
|
115 | 115 | assert_response :success |
|
116 | 116 | assert_template 'new' |
|
117 | 117 | assert_not_nil assigns(:news) |
|
118 | 118 | assert assigns(:news).new_record? |
|
119 | 119 | assert_error_tag :content => /title can't be blank/i |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_get_edit |
|
123 | 123 | @request.session[:user_id] = 2 |
|
124 | 124 | get :edit, :id => 1 |
|
125 | 125 | assert_response :success |
|
126 | 126 | assert_template 'edit' |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def test_put_update |
|
130 | 130 | @request.session[:user_id] = 2 |
|
131 | 131 | put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' } |
|
132 | 132 | assert_redirected_to '/news/1' |
|
133 | 133 | news = News.find(1) |
|
134 | 134 | assert_equal 'Description changed by test_post_edit', news.description |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | def test_put_update_with_attachment |
|
138 | 138 | set_tmp_attachments_directory |
|
139 | 139 | @request.session[:user_id] = 2 |
|
140 | 140 | assert_no_difference 'News.count' do |
|
141 | 141 | assert_difference 'Attachment.count' do |
|
142 | 142 | put :update, :id => 1, |
|
143 | 143 | :news => { :description => 'This is the description' }, |
|
144 | 144 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
145 | 145 | end |
|
146 | 146 | end |
|
147 | 147 | attachment = Attachment.order('id DESC').first |
|
148 | 148 | assert_equal News.find(1), attachment.container |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def test_update_with_failure |
|
152 | 152 | @request.session[:user_id] = 2 |
|
153 | 153 | put :update, :id => 1, :news => { :description => '' } |
|
154 | 154 | assert_response :success |
|
155 | 155 | assert_template 'edit' |
|
156 | 156 | assert_error_tag :content => /description can't be blank/i |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def test_destroy |
|
160 | 160 | @request.session[:user_id] = 2 |
|
161 | 161 | delete :destroy, :id => 1 |
|
162 | 162 | assert_redirected_to '/projects/ecookbook/news' |
|
163 | 163 | assert_nil News.find_by_id(1) |
|
164 | 164 | end |
|
165 | 165 | end |
General Comments 0
You need to be logged in to leave comments.
Login now