Commit 8849f0f95ffae506fb0547c93648ca9af53c9d6c
Committed by
Daniela Feitosa
1 parent
00641c73
Exists in
master
and in
29 other branches
Always ask captcha question on comments
(ActionItem2027)
Showing
15 changed files
with
49 additions
and
6 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -76,8 +76,13 @@ class ContentViewerController < ApplicationController |
76 | 76 | |
77 | 77 | @form_div = params[:form] |
78 | 78 | |
79 | - if request.post? && params[:comment] && params[self.icaptcha_field].blank? && params[:confirm] == 'true' && @page.accept_comments? | |
80 | - add_comment | |
79 | + if params[:comment] && params[self.icaptcha_field].blank? && params[:confirm] == 'true' | |
80 | + @comment = Comment.new(params[:comment]) | |
81 | + if request.post? && @page.accept_comments? | |
82 | + add_comment | |
83 | + end | |
84 | + else | |
85 | + @comment = Comment.new | |
81 | 86 | end |
82 | 87 | |
83 | 88 | if request.post? && params[:remove_comment] |
... | ... | @@ -114,7 +119,6 @@ class ContentViewerController < ApplicationController |
114 | 119 | protected |
115 | 120 | |
116 | 121 | def add_comment |
117 | - @comment = Comment.new(params[:comment]) | |
118 | 122 | @comment.author = user if logged_in? |
119 | 123 | @comment.article = @page |
120 | 124 | if @comment.save | ... | ... |
app/models/comment.rb
app/views/content_viewer/_comment_form.rhtml
... | ... | @@ -38,6 +38,10 @@ |
38 | 38 | |
39 | 39 | <%= required labelled_form_field(_('Title'), text_field(:comment, :title)) %> |
40 | 40 | <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %> |
41 | + | |
42 | + <%= required labelled_form_field(_("What is the result of '%s = ?'") % @comment.captcha.task, text_field(:comment, :captcha_solution)) %> | |
43 | + <%= hidden_field(:comment, :captcha_secret) %> | |
44 | + | |
41 | 45 | <% button_bar do %> |
42 | 46 | <%= submit_button('add', _('Post comment'), :onclick => "this.form.confirm.value = 'true'; this.disabled = true; this.form.submit(); return true;") %> |
43 | 47 | <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> | ... | ... |
features/comment.feature
... | ... | @@ -81,3 +81,16 @@ Feature: comment |
81 | 81 | Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened" |
82 | 82 | And I should be exactly on /booking/article-with-comment |
83 | 83 | And I should be moved to anchor "comment_form" |
84 | + | |
85 | + Scenario: ask captcha question | |
86 | + Given I am on /booking/article-with-comment | |
87 | + When I follow "Post a comment" within ".post-comment-button" | |
88 | + Then I should see "What is the result of " | |
89 | + | |
90 | + @selenium | |
91 | + Scenario: keep comments field filled while trying to do a comment | |
92 | + Given I am on /booking/article-with-comment | |
93 | + And I fill in "Name" with "Joey Ramone" | |
94 | + When I press "Post comment" | |
95 | + Then the "Name" field should contain "Joey Ramone" | |
96 | + And I should see "errors prohibited" | ... | ... |
features/comment_reply.feature
... | ... | @@ -64,9 +64,11 @@ Feature: comment |
64 | 64 | |
65 | 65 | @selenium |
66 | 66 | Scenario: reply a comment |
67 | - Given I am logged in as "booking" | |
67 | + Given skip comments captcha | |
68 | 68 | And I go to /booking/another-article |
69 | 69 | And I follow "Reply" within ".comment-balloon" |
70 | + And I fill in "Name" within "comment-balloon" with "Joey" | |
71 | + And I fill in "e-mail" within "comment-balloon" with "joey@ramones.com" | |
70 | 72 | And I fill in "Title" within "comment-balloon" with "Hey ho, let's go!" |
71 | 73 | And I fill in "Enter your comment" within "comment-balloon" with "Hey ho, let's go!" |
72 | 74 | When I press "Post comment" within ".comment-balloon" | ... | ... |
features/step_definitions/noosfero_steps.rb
... | ... | @@ -359,6 +359,7 @@ Given /^the articles of "(.+)" are moderated$/ do |organization| |
359 | 359 | end |
360 | 360 | |
361 | 361 | Given /^the following comments?$/ do |table| |
362 | + Comment.skip_captcha! | |
362 | 363 | table.hashes.each do |item| |
363 | 364 | data = item.dup |
364 | 365 | article = Article.find_by_name(data.delete("article")) |
... | ... | @@ -416,4 +417,6 @@ Given /^the search index is empty$/ do |
416 | 417 | ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) |
417 | 418 | end |
418 | 419 | |
419 | - | |
420 | +Given /^skip comments captcha$/ do | |
421 | + Comment.any_instance.stubs(:skip_captcha?).returns(true) | |
422 | +end | ... | ... |
test/functional/content_viewer_controller_test.rb
test/functional/search_controller_test.rb
test/unit/article_test.rb
test/unit/category_finder_test.rb
... | ... | @@ -8,7 +8,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
8 | 8 | @finder = CategoryFinder.new(@category) |
9 | 9 | @product_category = fast_create(ProductCategory, :name => 'Products') |
10 | 10 | |
11 | - Profile.rebuild_solr_index | |
11 | + Profile.rebuild_index | |
12 | + Comment.skip_captcha! | |
12 | 13 | end |
13 | 14 | |
14 | 15 | should 'search for articles in a specific category' do | ... | ... |
test/unit/category_test.rb
test/unit/comment_notifier_test.rb
... | ... | @@ -10,6 +10,7 @@ class CommentNotifierTest < Test::Unit::TestCase |
10 | 10 | ActionMailer::Base.deliveries = [] |
11 | 11 | @profile = create_user('user_comment_test').person |
12 | 12 | @article = fast_create(Article, :name => 'Article test', :profile_id => @profile.id, :notify_comments => true) |
13 | + Comment.skip_captcha! | |
13 | 14 | end |
14 | 15 | |
15 | 16 | should 'deliver mail after make aarticle commment' do | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -327,4 +327,11 @@ class CommentTest < Test::Unit::TestCase |
327 | 327 | assert_nil Comment.new(:email => 'my@email.com').author_url |
328 | 328 | end |
329 | 329 | |
330 | + should 'have the captcha_solution be solved' do | |
331 | + c = Comment.new | |
332 | + assert !c.valid? && c.errors.invalid?(:captcha_solution) | |
333 | + c.skip_captcha! | |
334 | + assert !c.valid? && !c.errors.invalid?(:captcha_solution) | |
335 | + end | |
336 | + | |
330 | 337 | end | ... | ... |
test/unit/community_test.rb
test/unit/forum_helper_test.rb
... | ... | @@ -12,6 +12,7 @@ class ForumHelperTest < Test::Unit::TestCase |
12 | 12 | @environment = Environment.default |
13 | 13 | @profile = create_user('forum_helper_test').person |
14 | 14 | @forum = fast_create(Forum, :profile_id => profile.id, :name => 'Forum test') |
15 | + Comment.skip_captcha! | |
15 | 16 | end |
16 | 17 | |
17 | 18 | attr :profile | ... | ... |