Mercurial > hg > soundsoftware-site
comparison test/functional/news_controller_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
44 assert_response :success | 44 assert_response :success |
45 assert_template 'index' | 45 assert_template 'index' |
46 assert_not_nil assigns(:newss) | 46 assert_not_nil assigns(:newss) |
47 end | 47 end |
48 | 48 |
49 def test_index_with_invalid_project_should_respond_with_404 | |
50 get :index, :project_id => 999 | |
51 assert_response 404 | |
52 end | |
53 | |
49 def test_show | 54 def test_show |
50 get :show, :id => 1 | 55 get :show, :id => 1 |
51 assert_response :success | 56 assert_response :success |
52 assert_template 'show' | 57 assert_template 'show' |
53 assert_tag :tag => 'h2', :content => /eCookbook first release/ | 58 assert_tag :tag => 'h2', :content => /eCookbook first release/ |
59 end | |
60 | |
61 def test_show_should_show_attachments | |
62 attachment = Attachment.first | |
63 attachment.container = News.find(1) | |
64 attachment.save! | |
65 | |
66 get :show, :id => 1 | |
67 assert_response :success | |
68 assert_tag 'a', :content => attachment.filename | |
54 end | 69 end |
55 | 70 |
56 def test_show_not_found | 71 def test_show_not_found |
57 get :show, :id => 999 | 72 get :show, :id => 999 |
58 assert_response 404 | 73 assert_response 404 |
65 assert_template 'new' | 80 assert_template 'new' |
66 end | 81 end |
67 | 82 |
68 def test_post_create | 83 def test_post_create |
69 ActionMailer::Base.deliveries.clear | 84 ActionMailer::Base.deliveries.clear |
70 Setting.notified_events << 'news_added' | 85 @request.session[:user_id] = 2 |
71 | 86 |
72 @request.session[:user_id] = 2 | 87 with_settings :notified_events => %w(news_added) do |
73 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', | 88 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', |
74 :description => 'This is the description', | 89 :description => 'This is the description', |
75 :summary => '' } | 90 :summary => '' } |
91 end | |
76 assert_redirected_to '/projects/ecookbook/news' | 92 assert_redirected_to '/projects/ecookbook/news' |
77 | 93 |
78 news = News.find_by_title('NewsControllerTest') | 94 news = News.find_by_title('NewsControllerTest') |
79 assert_not_nil news | 95 assert_not_nil news |
80 assert_equal 'This is the description', news.description | 96 assert_equal 'This is the description', news.description |
81 assert_equal User.find(2), news.author | 97 assert_equal User.find(2), news.author |
82 assert_equal Project.find(1), news.project | 98 assert_equal Project.find(1), news.project |
83 assert_equal 1, ActionMailer::Base.deliveries.size | 99 assert_equal 1, ActionMailer::Base.deliveries.size |
100 end | |
101 | |
102 def test_post_create_with_attachment | |
103 set_tmp_attachments_directory | |
104 @request.session[:user_id] = 2 | |
105 assert_difference 'News.count' do | |
106 assert_difference 'Attachment.count' do | |
107 post :create, :project_id => 1, | |
108 :news => { :title => 'Test', :description => 'This is the description' }, | |
109 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
110 end | |
111 end | |
112 attachment = Attachment.first(:order => 'id DESC') | |
113 news = News.first(:order => 'id DESC') | |
114 assert_equal news, attachment.container | |
115 end | |
116 | |
117 def test_post_create_with_validation_failure | |
118 @request.session[:user_id] = 2 | |
119 post :create, :project_id => 1, :news => { :title => '', | |
120 :description => 'This is the description', | |
121 :summary => '' } | |
122 assert_response :success | |
123 assert_template 'new' | |
124 assert_not_nil assigns(:news) | |
125 assert assigns(:news).new_record? | |
126 assert_error_tag :content => /title can't be blank/i | |
84 end | 127 end |
85 | 128 |
86 def test_get_edit | 129 def test_get_edit |
87 @request.session[:user_id] = 2 | 130 @request.session[:user_id] = 2 |
88 get :edit, :id => 1 | 131 get :edit, :id => 1 |
96 assert_redirected_to '/news/1' | 139 assert_redirected_to '/news/1' |
97 news = News.find(1) | 140 news = News.find(1) |
98 assert_equal 'Description changed by test_post_edit', news.description | 141 assert_equal 'Description changed by test_post_edit', news.description |
99 end | 142 end |
100 | 143 |
101 def test_post_create_with_validation_failure | 144 def test_put_update_with_attachment |
145 set_tmp_attachments_directory | |
102 @request.session[:user_id] = 2 | 146 @request.session[:user_id] = 2 |
103 post :create, :project_id => 1, :news => { :title => '', | 147 assert_no_difference 'News.count' do |
104 :description => 'This is the description', | 148 assert_difference 'Attachment.count' do |
105 :summary => '' } | 149 put :update, :id => 1, |
150 :news => { :description => 'This is the description' }, | |
151 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
152 end | |
153 end | |
154 attachment = Attachment.first(:order => 'id DESC') | |
155 assert_equal News.find(1), attachment.container | |
156 end | |
157 | |
158 def test_update_with_failure | |
159 @request.session[:user_id] = 2 | |
160 put :update, :id => 1, :news => { :description => '' } | |
106 assert_response :success | 161 assert_response :success |
107 assert_template 'new' | 162 assert_template 'edit' |
108 assert_not_nil assigns(:news) | 163 assert_error_tag :content => /description can't be blank/i |
109 assert assigns(:news).new_record? | |
110 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, | |
111 :content => /1 error/ | |
112 end | 164 end |
113 | 165 |
114 def test_destroy | 166 def test_destroy |
115 @request.session[:user_id] = 2 | 167 @request.session[:user_id] = 2 |
116 delete :destroy, :id => 1 | 168 delete :destroy, :id => 1 |