displays captcha only on new, not edit

This commit is contained in:
rgarcia
2015-07-28 12:39:39 +02:00
parent b007d12006
commit f4f0593fda
3 changed files with 19 additions and 1 deletions

View File

@@ -1,4 +1,8 @@
module RecaptchaHelper
def recaptchable?
@debate.new_record?
end
def recaptcha_keys?
Recaptcha.configuration.public_key.present? &&

View File

@@ -1,3 +1,3 @@
<% if recaptcha_keys? %>
<% if recaptchable? and recaptcha_keys? %>
<%= recaptcha_tags ajax: true, hl: I18n.locale %>
<% end %>

View File

@@ -2,6 +2,20 @@ require 'rails_helper'
describe RecaptchaHelper do
describe '#recaptchable?' do
it 'should be true if new record' do
assign(:debate, build(:debate))
expect(helper.recaptchable?).to be true
end
it 'should be false if existing record' do
assign(:debate, create(:debate))
expect(helper.recaptchable?).to be false
end
end
describe "#recaptcha_keys?" do
it "should be true if Recaptcha keys are configured" do