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 53 <div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %>">
54 54  
55 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 58 <%= required_fields_message %>
59 59  
... ...
test/functional/comment_controller_test.rb
... ... @@ -214,7 +214,7 @@ class CommentControllerTest &lt; ActionController::TestCase
214 214 environment.enable('captcha_for_logged_users')
215 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 218 assert_match /post_comment_box opened/, @response.body
219 219 end
220 220  
... ... @@ -225,14 +225,14 @@ class CommentControllerTest &lt; ActionController::TestCase
225 225 @controller.stubs(:verify_recaptcha).returns(false)
226 226  
227 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 229 end
230 230  
231 231 environment.enable('captcha_for_logged_users')
232 232 environment.save!
233 233  
234 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 236 end
237 237 assert_not_nil assigns(:comment)
238 238 end
... ... @@ -242,13 +242,15 @@ class CommentControllerTest &lt; ActionController::TestCase
242 242 article.save!
243 243  
244 244 @controller.stubs(:verify_recaptcha).returns(false)
  245 + logout
245 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 248 end
248 249  
249 250 @controller.stubs(:verify_recaptcha).returns(true)
  251 + login_as profile.identifier
250 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 254 end
253 255 end
254 256  
... ... @@ -258,8 +260,9 @@ class CommentControllerTest &lt; ActionController::TestCase
258 260 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true)
259 261  
260 262 commenter = create_user('otheruser').person
  263 + login_as(commenter.identifier)
261 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 266 end
264 267 end
265 268  
... ... @@ -279,8 +282,9 @@ class CommentControllerTest &lt; ActionController::TestCase
279 282 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true)
280 283  
281 284 commenter = create_user('otheruser').person
  285 + login_as(commenter.identifier)
282 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 288 end
285 289 task = Task.last
286 290 assert_equal commenter, task.requestor
... ... @@ -293,8 +297,9 @@ class CommentControllerTest &lt; ActionController::TestCase
293 297 page = community.articles.create!(:name => 'myarticle', :moderate_comments => true)
294 298  
295 299 commenter = create_user('otheruser').person
  300 + login_as(commenter.identifier)
296 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 303 end
299 304 task = Task.last
300 305 assert_equal community, task.target
... ... @@ -472,7 +477,7 @@ class CommentControllerTest &lt; ActionController::TestCase
472 477 comment = fast_create(Comment, :body => 'Original comment', :source_id => page.id, :source_type => 'Article', :author_id => profile.id)
473 478  
474 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 481 end
477 482  
478 483 should 'not crash on edit comment if comment does not exist' do
... ...