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