Sha256: 6ca8f456e74ed327fb8724b8c81aeb7726631df0867c2dd2d10840065b84b557

Contents?: true

Size: 1.7 KB

Versions: 13

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::RecaptchaService do

  let(:api_url)     { nil }
  let(:secret)      { 'asecretkey' }
  let(:site)        { instance_double('Site', metafields: { google: { recaptcha_api_url: api_url, 'recaptcha_secret' => secret } }) }
  let(:request)     { instance_double('Request', ip: '127.0.0.1') }
  let(:service)     { described_class.new(site, request) }

  describe '#verify' do

    let(:code) { nil }

    subject { service.verify(code) }

    it { is_expected.to eq false }

    context 'the code is not nil' do

      let(:code)    { '42' }
      let(:success) { false }

      before do
        expect(HTTParty).to receive(:get).with('https://www.google.com/recaptcha/api/siteverify', {
          query: {
            secret:   'asecretkey',
            response: '42',
            remoteip: '127.0.0.1'
          }
        }).and_return(instance_double('Response', parsed_response: { 'success' => success }))
      end

      context 'the code is verified' do

        let(:success) { true }
        it { is_expected.to eq true }

      end

      context 'the code is not verified' do

        let(:success) { false }
        it { is_expected.to eq false }

      end

    end

    context 'using a different API url' do

      let(:code)    { '42' }
      let(:api_url) { 'https://recaptcha.net/api' }

      before do
        expect(HTTParty).to receive(:get).with('https://recaptcha.net/api', {
          query: {
            secret:   'asecretkey',
            response: '42',
            remoteip: '127.0.0.1'
          }
        }).and_return(instance_double('Response', parsed_response: { 'success' => true }))
      end

      it { is_expected.to eq true }

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.8.0.alpha1 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.7.1 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.7.0 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.6.1 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.6.0 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.6.0.rc1 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.6.0.beta1 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.5.3 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.5.2 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.5.1 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.5.0 spec/unit/services/recaptcha_service_spec.rb
locomotivecms_steam-1.5.0.rc1 spec/unit/services/recaptcha_service_spec.rb