Sha256: 1e86e54c87014a76ce27a90d9bf8ac598a746c469fbf4f78202f419fafaddd99

Contents?: true

Size: 1.45 KB

Versions: 48

Compression:

Stored size: 1.45 KB

Contents

require 'test_helper'

class RecaptchaValidatorTest < ActiveSupport::TestCase

  class TestModel
    include ActiveModel::Model
    include ActiveModel::Validations

    attr_accessor :recaptcha

    validates :recaptcha, 'incline/recaptcha' => true
  end

  def setup
    @item = TestModel.new(recaptcha: Incline::Recaptcha::DISABLED)
  end

  test 'initial value should be valid' do
    assert @item.valid?
  end

  test 'recaptcha validator ignores blank values' do
    @item.recaptcha = nil
    assert @item.valid?
    @item.recaptcha = ''
    assert @item.valid?
    @item.recaptcha = '   '
    assert @item.valid?
  end

  test 'recaptcha validator has two error messages' do
    @item.recaptcha = '127.0.0.1' # no response
    assert_not @item.valid?
    assert @item.errors[:base].to_s =~ /requires recaptcha challenge to be completed/i

    @item.recaptcha = '127.0.0.1|invalid' # invalid response
    assert_not @item.valid?
    assert @item.errors[:base].to_s =~ /invalid response from recaptcha challenge/i

    # make sure it did not fail because of the IP address portion.
    @item.recaptcha = '127.0.0.1|disabled'
    assert @item.valid?
  end

  test 'recaptcha validator changes value' do
    assert_not_equal :verified, @item.recaptcha

    # the validator changes the value to :verified when it passes.
    assert @item.valid?
    assert_equal :verified, @item.recaptcha

    # that way future calls to valid? will continue to pass.
    assert @item.valid?
  end


end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
incline-0.3.14 test/validators/recaptcha_validator_test.rb
incline-0.3.13 test/validators/recaptcha_validator_test.rb
incline-0.3.12 test/validators/recaptcha_validator_test.rb
incline-0.3.11 test/validators/recaptcha_validator_test.rb
incline-0.3.10 test/validators/recaptcha_validator_test.rb
incline-0.3.9 test/validators/recaptcha_validator_test.rb
incline-0.3.8 test/validators/recaptcha_validator_test.rb
incline-0.3.7 test/validators/recaptcha_validator_test.rb
incline-0.3.6 test/validators/recaptcha_validator_test.rb
incline-0.3.5 test/validators/recaptcha_validator_test.rb
incline-0.3.4 test/validators/recaptcha_validator_test.rb
incline-0.3.3 test/validators/recaptcha_validator_test.rb
incline-0.3.2 test/validators/recaptcha_validator_test.rb
incline-0.3.1 test/validators/recaptcha_validator_test.rb
incline-0.3.0 test/validators/recaptcha_validator_test.rb
incline-0.2.36 test/validators/recaptcha_validator_test.rb
incline-0.2.35 test/validators/recaptcha_validator_test.rb
incline-0.2.34 test/validators/recaptcha_validator_test.rb
incline-0.2.28 test/validators/recaptcha_validator_test.rb
incline-0.2.27 test/validators/recaptcha_validator_test.rb