File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed
Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,8 @@ class PrimoCentralController < CatalogController
1111 helper_method :tags_strip
1212 helper_method :solr_range_queries_to_a
1313
14- def self . recaptcha_on?
15- Proc . new { |context | ::FeatureFlags . recaptcha_on? ( context . params ) }
16- end
17-
1814 def recaptcha
19- ::FeatureFlags . recaptcha? ( params )
15+ return unless ::FeatureFlags . recaptcha? ( params )
2016 # Do not enable for logged in users.
2117 return if current_user
2218
Original file line number Diff line number Diff line change @@ -27,6 +27,6 @@ def self.recaptcha?(params = nil)
2727 if !params . nil? && params . has_key? ( "recaptcha" )
2828 return ( params [ "recaptcha" ] == "false" ) ? false : true
2929 end
30- !!Rails . configuration . features . fetch ( :recaptcha , false )
30+ !!Rails . configuration . features . fetch ( :recaptcha_on , false )
3131 end
3232end
Original file line number Diff line number Diff line change 5353 end
5454
5555 describe "recaptcha enabled" do
56+ around do |example |
57+ original = Rails . configuration . features [ :recaptcha_on ]
58+ Rails . configuration . features [ :recaptcha_on ] = true
59+ example . run
60+ ensure
61+ Rails . configuration . features [ :recaptcha_on ] = original
62+ end
63+
5664 before do
5765 stub_const ( "ENV" , ENV . to_h . merge ( "RECAPTCHA_SITE_KEY" => "foo" ) )
5866 allow ( controller ) . to receive ( :verify_recaptcha ) . and_return ( false )
7078 end
7179 end
7280 end
81+
82+ describe "recaptcha disabled" do
83+ around do |example |
84+ original = Rails . configuration . features [ :recaptcha_on ]
85+ Rails . configuration . features [ :recaptcha_on ] = false
86+ example . run
87+ ensure
88+ Rails . configuration . features [ :recaptcha_on ] = original
89+ end
90+
91+ before do
92+ stub_const ( "ENV" , ENV . to_h . merge ( "RECAPTCHA_SITE_KEY" => "foo" ) )
93+ end
94+
95+ it "skips recaptcha checks" do
96+ expect ( controller ) . not_to receive ( :verify_recaptcha )
97+
98+ get :index , params : { q : "foo" }
99+
100+ expect ( response ) . to have_http_status ( :ok )
101+ end
102+ end
73103end
You can’t perform that action at this time.
0 commit comments