Commit daee09893595ce2e96c11fad90f4cb335027802a
Committed by
Antonio Terceiro
1 parent
719968cb
Exists in
staging
and in
42 other branches
ActionItem1137: adding icaptcha_field on contact
Showing
3 changed files
with
18 additions
and
1 deletions
Show diff stats
app/controllers/public/contact_controller.rb
@@ -2,9 +2,10 @@ class ContactController < PublicController | @@ -2,9 +2,10 @@ class ContactController < PublicController | ||
2 | 2 | ||
3 | needs_profile | 3 | needs_profile |
4 | 4 | ||
5 | + inverse_captcha :field => 'e_mail' | ||
5 | def new | 6 | def new |
6 | @contact | 7 | @contact |
7 | - if request.post? | 8 | + if request.post? && params[self.icaptcha_field].blank? |
8 | @contact = Contact.new(params[:contact]) | 9 | @contact = Contact.new(params[:contact]) |
9 | @contact.dest = profile | 10 | @contact.dest = profile |
10 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : _('Missing') | 11 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : _('Missing') |
app/views/contact/new.rhtml
@@ -16,6 +16,8 @@ | @@ -16,6 +16,8 @@ | ||
16 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> | 16 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> |
17 | <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> | 17 | <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> |
18 | 18 | ||
19 | + <%= icaptcha_field() %> | ||
20 | + | ||
19 | <%= submit_button(:send, _('Send')) %> | 21 | <%= submit_button(:send, _('Send')) %> |
20 | 22 | ||
21 | <% end %> | 23 | <% end %> |
test/functional/contact_controller_test.rb
@@ -97,5 +97,19 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -97,5 +97,19 @@ class ContactControllerTest < Test::Unit::TestCase | ||
97 | get :new, :profile => profile.identifier | 97 | get :new, :profile => profile.identifier |
98 | assert_no_tag :tag => 'select', :attributes => {:name => 'state'} | 98 | assert_no_tag :tag => 'select', :attributes => {:name => 'state'} |
99 | end | 99 | end |
100 | + | ||
101 | + should 'be able to post contact while inverse captcha field filled' do | ||
102 | + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | ||
103 | + | ||
104 | + assert_response :redirect | ||
105 | + assert_redirected_to :action => 'new' | ||
106 | + end | ||
107 | + | ||
108 | + should 'not be able to post contact while inverse captcha field filled' do | ||
109 | + post :new, :profile => enterprise.identifier, @controller.icaptcha_field => 'filled', :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | ||
110 | + | ||
111 | + assert_response :success | ||
112 | + assert_template 'new' | ||
113 | + end | ||
100 | 114 | ||
101 | end | 115 | end |