Skip to content

Fix invisible_recaptcha_tags to work in testing modes - #234

Merged
grosser merged 6 commits into
ambethia:masterfrom
Rakefire:bugfix/allow-invisible_recaptcha_tags-to-be-used-in-test
Sep 1, 2017
Merged

grosser merged 6 commits into
ambethia:masterfrom
Rakefire:bugfix/allow-invisible_recaptcha_tags-to-be-used-in-test

Conversation

@rickychilcott

Copy link
Copy Markdown
Contributor

Add relevant javascript and markup options to invisible_recaptcha_tags ONLY we are not in a testing mode

@rickychilcott

Copy link
Copy Markdown
Contributor Author

I ran into a bug when I tried to run (previously passing) tests after adding the recaptcha gem and specifically using the invisible_recaptcha_tags method. This PR cleans up the markup so that it only passes through the needed details to get the UI to look the same, but not load the non-test related javascript.

Thanks for your work on this gem @ambethia!

@rickychilcott

Copy link
Copy Markdown
Contributor Author

Also, let me know if you want a test for this. I just wrap the one section with an if clause, but I'm willing to prove it works.

@grosser

grosser commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator

looks reasonable to me ... a test would be nice though ...

Comment thread lib/recaptcha/client_helper.rb Outdated
script_url += "?hl=#{hl}" unless hl.to_s == ""
html << %(<script src="#{script_url}" async defer></script>\n) unless options.delete(:script) == false
fallback_uri = "#{script_url.chomp('.js')}/fallback?k=#{site_key}"
attributes["class"] = %(g-recaptcha #{options.delete(:class)})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just use quotes instead of %(

Comment thread test/client_helper_test.rb Outdated
it "doesn't render script tag when in test mode" do
html = invisible_recaptcha_tags(env: "test")
html.wont_include("<script")
html.wont_include(" data-sitekey=\"#{Recaptcha.configuration.site_key}\"")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can make this more generic "data-sitekey"

Comment thread test/client_helper_test.rb Outdated
html.must_include(" data-sitekey=\"#{Recaptcha.configuration.site_key}\"")
end

it "doesn't render script tag when in test mode" do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more like "when verification is disabled" ?

@grosser

grosser commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator

sweet!

@rickychilcott
rickychilcott force-pushed the bugfix/allow-invisible_recaptcha_tags-to-be-used-in-test branch from 5fa644b to 198547a Compare September 1, 2017 22:28
@grosser
grosser merged commit c5eb2f1 into ambethia:master Sep 1, 2017
@rickychilcott

Copy link
Copy Markdown
Contributor Author

Thanks for the review @grosser!

@grosser

grosser commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator

4.4.0 ... hope nobody comes and complains about their "usecase" :D

wfschmitt pushed a commit to wfschmitt/recaptcha that referenced this pull request Sep 24, 2017
…recaptcha_tags-to-be-used-in-test

Fix invisible_recaptcha_tags to work in testing modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants