Sha256: 6d266b9036944b63fbc2dcca674f4e1234b7551ee7a5dc01da318383780fc9e4

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'test_helper'

class TestWithCaptcha < ActionController::TestCase
  include Devise::Test::ControllerHelpers
  tests Captcha::SessionsController

  setup do
    @request.env["devise.mapping"] = Devise.mappings[:captcha_user]
  end

  test 'When captcha is enabled, it is inserted correctly' do
    post :create, params: {
      captcha_user: {
        email: "wrong@email.com",
        password: "wrongpassword"
      }
    }

    assert_equal "The captcha input was invalid.", flash[:alert]
    assert_redirected_to new_captcha_user_session_path
  end

  test 'When captcha is valid, it runs as normal' do
    @controller.define_singleton_method(:verify_recaptcha) do
      true
    end

    post :create, params: {
      captcha: "ABCDE",
      captcha_user: {
        email: "wrong@email.com",
        password: "wrongpassword"
      }
    }

    assert_equal "Invalid Email or password.", flash[:alert]
  end
end

class TestWithoutCaptcha < ActionController::TestCase
  include Devise::Test::ControllerHelpers
  tests Devise::SessionsController

  setup do
    @request.env["devise.mapping"] = Devise.mappings[:user]
  end

  test 'When captcha is not enabled, it is not inserted' do
    post :create, params: { 
      user: {
        email: "wrong@email.com",
        password: "wrongpassword"
      }
    }

    assert_equal "Invalid Email or password.", flash[:alert]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise-security-0.11.1 test/test_captcha_controller.rb
devise-security-0.11.0 test/test_captcha_controller.rb