Commit 9883b50d74365e16d3139b25cdc9fe5e34312eb7

Authored by Victor Costa
1 parent 610b3e1c

rails3: fix comment_controller

app/views/comment/_comment_form.html.erb
@@ -53,7 +53,7 @@ function check_captcha(button, confirm_action) { @@ -53,7 +53,7 @@ function check_captcha(button, confirm_action) {
53 <div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %>"> 53 <div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %>">
54 54
55 <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link && @comment.reply_of_id.blank? %> 55 <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link && @comment.reply_of_id.blank? %>
56 -<% remote_form_for(:comment, comment, :url => {:profile => profile.identifier, :controller => 'comment', :action => (edition_mode ? 'update' : 'create'), :id => (edition_mode ? comment.id : @page.id)}, :html => { :class => 'comment_form' } ) do |f| %> 56 +<%= remote_form_for(:comment, comment, :url => {:profile => profile.identifier, :controller => 'comment', :action => (edition_mode ? 'update' : 'create'), :id => (edition_mode ? comment.id : @page.id)}, :html => { :class => 'comment_form' } ) do |f| %>
57 57
58 <%= required_fields_message %> 58 <%= required_fields_message %>
59 59
test/functional/comment_controller_test.rb
@@ -214,7 +214,7 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -214,7 +214,7 @@ class CommentControllerTest &lt; ActionController::TestCase
214 environment.enable('captcha_for_logged_users') 214 environment.enable('captcha_for_logged_users')
215 environment.save! 215 environment.save!
216 216
217 - xhr :post, :create, :profile => profile.identifier, :id =>article.id, :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true' 217 + xhr :post, :create, :profile => profile.identifier, :id =>article.id, :comment => {:body => "Some comment..."}, :confirm => 'true'
218 assert_match /post_comment_box opened/, @response.body 218 assert_match /post_comment_box opened/, @response.body
219 end 219 end
220 220
@@ -225,14 +225,14 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -225,14 +225,14 @@ class CommentControllerTest &lt; ActionController::TestCase
225 @controller.stubs(:verify_recaptcha).returns(false) 225 @controller.stubs(:verify_recaptcha).returns(false)
226 226
227 assert_difference 'Comment.count', 1 do 227 assert_difference 'Comment.count', 1 do
228 - xhr :post, :create, :profile => profile.identifier, :id => article.id, :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true' 228 + xhr :post, :create, :profile => profile.identifier, :id => article.id, :comment => {:body => "Some comment..."}, :confirm => 'true'
229 end 229 end
230 230
231 environment.enable('captcha_for_logged_users') 231 environment.enable('captcha_for_logged_users')
232 environment.save! 232 environment.save!
233 233
234 assert_no_difference 'Comment.count' do 234 assert_no_difference 'Comment.count' do
235 - xhr :post, :create, :profile => profile.identifier, :id =>article.id, :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true' 235 + xhr :post, :create, :profile => profile.identifier, :id =>article.id, :comment => {:body => "Some comment..."}, :confirm => 'true'
236 end 236 end
237 assert_not_nil assigns(:comment) 237 assert_not_nil assigns(:comment)
238 end 238 end
@@ -242,13 +242,15 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -242,13 +242,15 @@ class CommentControllerTest &lt; ActionController::TestCase
242 article.save! 242 article.save!
243 243
244 @controller.stubs(:verify_recaptcha).returns(false) 244 @controller.stubs(:verify_recaptcha).returns(false)
  245 + logout
245 assert_no_difference 'Comment.count' do 246 assert_no_difference 'Comment.count' do
246 - xhr :post, :create, :profile => profile.identifier, :id => article.id, :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true' 247 + xhr :post, :create, :profile => profile.identifier, :id => article.id, :comment => {:body => "Some comment..."}, :confirm => 'true'
247 end 248 end
248 249
249 @controller.stubs(:verify_recaptcha).returns(true) 250 @controller.stubs(:verify_recaptcha).returns(true)
  251 + login_as profile.identifier
250 assert_difference 'Comment.count', 1 do 252 assert_difference 'Comment.count', 1 do
251 - xhr :post, :create, :profile => profile.identifier, :id => article.id, :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true' 253 + xhr :post, :create, :profile => profile.identifier, :id => article.id, :comment => {:body => "Some comment..."}, :confirm => 'true'
252 end 254 end
253 end 255 end
254 256
@@ -258,8 +260,9 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -258,8 +260,9 @@ class CommentControllerTest &lt; ActionController::TestCase
258 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true) 260 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true)
259 261
260 commenter = create_user('otheruser').person 262 commenter = create_user('otheruser').person
  263 + login_as(commenter.identifier)
261 assert_difference 'ApproveComment.count', 1 do 264 assert_difference 'ApproveComment.count', 1 do
262 - xhr :post, :create, :profile => community.identifier, :id => page.id, :comment => {:body => 'Some comment...', :author => commenter}, :confirm => 'true' 265 + xhr :post, :create, :profile => community.identifier, :id => page.id, :comment => {:body => 'Some comment...'}, :confirm => 'true'
263 end 266 end
264 end 267 end
265 268
@@ -279,8 +282,9 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -279,8 +282,9 @@ class CommentControllerTest &lt; ActionController::TestCase
279 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true) 282 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true)
280 283
281 commenter = create_user('otheruser').person 284 commenter = create_user('otheruser').person
  285 + login_as(commenter.identifier)
282 assert_difference 'ApproveComment.count', 1 do 286 assert_difference 'ApproveComment.count', 1 do
283 - xhr :post, :create, :profile => community.identifier, :id => page.id, :comment => {:body => 'Some comment...', :author => commenter}, :confirm => 'true' 287 + xhr :post, :create, :profile => community.identifier, :id => page.id, :comment => {:body => 'Some comment...'}, :confirm => 'true'
284 end 288 end
285 task = Task.last 289 task = Task.last
286 assert_equal commenter, task.requestor 290 assert_equal commenter, task.requestor
@@ -293,8 +297,9 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -293,8 +297,9 @@ class CommentControllerTest &lt; ActionController::TestCase
293 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true) 297 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true)
294 298
295 commenter = create_user('otheruser').person 299 commenter = create_user('otheruser').person
  300 + login_as(commenter.identifier)
296 assert_difference 'ApproveComment.count', 1 do 301 assert_difference 'ApproveComment.count', 1 do
297 - xhr :post, :create, :profile => community.identifier, :id => page.id, :comment => {:body => 'Some comment...', :author => commenter}, :confirm => 'true' 302 + xhr :post, :create, :profile => community.identifier, :id => page.id, :comment => {:body => 'Some comment...'}, :confirm => 'true'
298 end 303 end
299 task = Task.last 304 task = Task.last
300 assert_equal community, task.target 305 assert_equal community, task.target
@@ -472,7 +477,7 @@ class CommentControllerTest &lt; ActionController::TestCase @@ -472,7 +477,7 @@ class CommentControllerTest &lt; ActionController::TestCase
472 comment = fast_create(Comment, :body => 'Original comment', :source_id => page.id, :source_type => 'Article', :author_id => profile.id) 477 comment = fast_create(Comment, :body => 'Original comment', :source_id => page.id, :source_type => 'Article', :author_id => profile.id)
473 478
474 get :edit, :id => comment.id, :profile => profile.identifier, :comment => { :body => 'Comment edited' } 479 get :edit, :id => comment.id, :profile => profile.identifier, :comment => { :body => 'Comment edited' }
475 - assert_tag :tag => 'textarea', :attributes => {:id => 'comment_body'}, :content => 'Original comment' 480 + assert_tag :tag => 'textarea', :attributes => {:id => 'comment_body'}, :content => /Original comment/
476 end 481 end
477 482
478 should 'not crash on edit comment if comment does not exist' do 483 should 'not crash on edit comment if comment does not exist' do