Mercurial > hg > soundsoftware-site
comparison test/functional/news_controller_test.rb @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 40f7cfd4df19 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.dirname(__FILE__) + '/../test_helper' | |
19 require 'news_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class NewsController; def rescue_action(e) raise e end; end | |
23 | |
24 class NewsControllerTest < ActionController::TestCase | |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments | |
26 | |
27 def setup | |
28 @controller = NewsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | |
32 end | |
33 | |
34 def test_index | |
35 get :index | |
36 assert_response :success | |
37 assert_template 'index' | |
38 assert_not_nil assigns(:newss) | |
39 assert_nil assigns(:project) | |
40 end | |
41 | |
42 def test_index_with_project | |
43 get :index, :project_id => 1 | |
44 assert_response :success | |
45 assert_template 'index' | |
46 assert_not_nil assigns(:newss) | |
47 end | |
48 | |
49 def test_show | |
50 get :show, :id => 1 | |
51 assert_response :success | |
52 assert_template 'show' | |
53 assert_tag :tag => 'h2', :content => /eCookbook first release/ | |
54 end | |
55 | |
56 def test_show_not_found | |
57 get :show, :id => 999 | |
58 assert_response 404 | |
59 end | |
60 | |
61 def test_get_new | |
62 @request.session[:user_id] = 2 | |
63 get :new, :project_id => 1 | |
64 assert_response :success | |
65 assert_template 'new' | |
66 end | |
67 | |
68 def test_post_new | |
69 ActionMailer::Base.deliveries.clear | |
70 Setting.notified_events << 'news_added' | |
71 | |
72 @request.session[:user_id] = 2 | |
73 post :new, :project_id => 1, :news => { :title => 'NewsControllerTest', | |
74 :description => 'This is the description', | |
75 :summary => '' } | |
76 assert_redirected_to 'projects/ecookbook/news' | |
77 | |
78 news = News.find_by_title('NewsControllerTest') | |
79 assert_not_nil news | |
80 assert_equal 'This is the description', news.description | |
81 assert_equal User.find(2), news.author | |
82 assert_equal Project.find(1), news.project | |
83 assert_equal 1, ActionMailer::Base.deliveries.size | |
84 end | |
85 | |
86 def test_get_edit | |
87 @request.session[:user_id] = 2 | |
88 get :edit, :id => 1 | |
89 assert_response :success | |
90 assert_template 'edit' | |
91 end | |
92 | |
93 def test_post_edit | |
94 @request.session[:user_id] = 2 | |
95 post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' } | |
96 assert_redirected_to 'news/1' | |
97 news = News.find(1) | |
98 assert_equal 'Description changed by test_post_edit', news.description | |
99 end | |
100 | |
101 def test_post_new_with_validation_failure | |
102 @request.session[:user_id] = 2 | |
103 post :new, :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/ | |
112 end | |
113 | |
114 def test_add_comment | |
115 @request.session[:user_id] = 2 | |
116 post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' } | |
117 assert_redirected_to 'news/1' | |
118 | |
119 comment = News.find(1).comments.find(:first, :order => 'created_on DESC') | |
120 assert_not_nil comment | |
121 assert_equal 'This is a NewsControllerTest comment', comment.comments | |
122 assert_equal User.find(2), comment.author | |
123 end | |
124 | |
125 def test_empty_comment_should_not_be_added | |
126 @request.session[:user_id] = 2 | |
127 assert_no_difference 'Comment.count' do | |
128 post :add_comment, :id => 1, :comment => { :comments => '' } | |
129 assert_response :success | |
130 assert_template 'show' | |
131 end | |
132 end | |
133 | |
134 def test_destroy_comment | |
135 comments_count = News.find(1).comments.size | |
136 @request.session[:user_id] = 2 | |
137 post :destroy_comment, :id => 1, :comment_id => 2 | |
138 assert_redirected_to 'news/1' | |
139 assert_nil Comment.find_by_id(2) | |
140 assert_equal comments_count - 1, News.find(1).comments.size | |
141 end | |
142 | |
143 def test_destroy | |
144 @request.session[:user_id] = 2 | |
145 post :destroy, :id => 1 | |
146 assert_redirected_to 'projects/ecookbook/news' | |
147 assert_nil News.find_by_id(1) | |
148 end | |
149 | |
150 def test_preview | |
151 get :preview, :project_id => 1, | |
152 :news => {:title => '', | |
153 :description => 'News description', | |
154 :summary => ''} | |
155 assert_response :success | |
156 assert_template 'common/_preview' | |
157 assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, | |
158 :content => /News description/ | |
159 end | |
160 end |