diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 41814ab48..672f41d20 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,4 +1,5 @@ class DebatesController < ApplicationController + include RecaptchaHelper before_action :set_debate, only: [:show, :edit, :update] before_action :authenticate_user!, except: [:show, :index] before_action :validate_ownership, only: [:edit, :update] @@ -51,7 +52,7 @@ class DebatesController < ApplicationController end def verify_captcha? - return true unless Rails.application.secrets.recaptcha_public_key + return true unless recaptcha_keys? verify_recaptcha(model: @debate) end diff --git a/app/helpers/recaptcha_helper.rb b/app/helpers/recaptcha_helper.rb new file mode 100644 index 000000000..9e6fa90e6 --- /dev/null +++ b/app/helpers/recaptcha_helper.rb @@ -0,0 +1,8 @@ +module RecaptchaHelper + + def recaptcha_keys? + Recaptcha.configuration.public_key.present? && + Recaptcha.configuration.private_key.present? + end + +end \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0e94e1709..aa8c240b0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,14 +5,13 @@ <%= content_for?(:title) ? yield(:title) : "Participación" %> - <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "vendor/modernizr" %> <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> - + <%= render 'layouts/header' %> @@ -29,5 +28,5 @@ <%= yield %> - + \ No newline at end of file diff --git a/app/views/shared/_captcha.html.erb b/app/views/shared/_captcha.html.erb index 0c390b7e4..7200bf6da 100644 --- a/app/views/shared/_captcha.html.erb +++ b/app/views/shared/_captcha.html.erb @@ -1,3 +1,3 @@ -<% if Rails.application.secrets.recaptcha_public_key %> - <%= recaptcha_tags ajax: true %> +<% if recaptcha_keys? %> + <%= recaptcha_tags ajax: true, hl: I18n.locale %> <% end %> \ No newline at end of file diff --git a/spec/helpers/recaptcha_helper_spec.rb b/spec/helpers/recaptcha_helper_spec.rb new file mode 100644 index 000000000..545e9e827 --- /dev/null +++ b/spec/helpers/recaptcha_helper_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +describe RecaptchaHelper do + + describe "#recaptcha_keys?" do + + it "should be true if Recaptcha keys are configured" do + allow(Recaptcha.configuration).to receive(:public_key).and_return("akjasf") + allow(Recaptcha.configuration).to receive(:private_key).and_return("akjasf4532") + + expect(helper.recaptcha_keys?).to be true + end + + it "should be false if Recaptcha keys are not configured" do + allow(Recaptcha.configuration).to receive(:public_key).and_return(nil) + allow(Recaptcha.configuration).to receive(:private_key).and_return(nil) + + expect(helper.recaptcha_keys?).to be false + end + + end +end