grecaptcha is not defined in rails 6 on test environment
dangxuanphuc opened this issue · comments
Phuc Dang Xuan commented
When I run rspec, run to command grecaptcha.execute()
in js file then get the error grecaptcha is not defined. Though, I enabled the recaptcha on the test environment Recaptcha.configuration.skip_verify_env.delete("test")
. Why?
Michael Grosser commented
no idea, please update if you find out what happened
…On Wed, Mar 24, 2021 at 2:59 AM Đặng Xuân Phúc ***@***.***> wrote:
When I run rspec, run to command grecaptcha.execute() in js file then get
the error grecaptcha is not defined. Though, I enabled the recaptcha on the
test environment Recaptcha.configuration.skip_verify_env.delete("test").
Why?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#389>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACYZYA3QTJJ6G6VCNUDL3TFGZZFANCNFSM4ZW5GZ7A>
.
Phuc Dang Xuan commented
My issue has several causes and corresponding solution:
event.preventDefault()
During the submit button click event, I put this command in front ofgrecaptcha.execute()
making the data submission impossible.- By default, reCAPTCHA is skipped in test environtment. To enable it during test, add this command to
config/initializers/recaptcha.rb
:
Recaptcha.configuration.skip_verify_env.delete("test")
- Finally,
verify_recaptcha
method always return false when run rspec. Solution:
allow_any_instance_of(Controller).to receive(:verify_recaptcha?).and_return(true)