Skip to content

Commit

Permalink
Resolve conflict and fix test in ntalbott's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason L Perry committed Dec 31, 2008
2 parents 7508155 + 3ecb728 commit 931694f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/recaptcha.rb
Expand Up @@ -46,7 +46,7 @@ def recaptcha_tags(options = {})

module Controller
# Your private API key must be specified in the environment variable +RECAPTCHA_PRIVATE_KEY+
def verify_recaptcha(model = nil, options = {})
def verify_recaptcha(options = {})
return true if SKIP_VERIFY_ENV.include? ENV['RAILS_ENV']
private_key = options[:private_key] ||= ENV['RECAPTCHA_PRIVATE_KEY']
raise ReCaptchaError, "No private key specified." unless private_key
Expand All @@ -60,9 +60,10 @@ def verify_recaptcha(model = nil, options = {})
answer, error = recaptcha.body.split.map { |s| s.chomp }
unless answer == 'true'
session[:recaptcha_error] = error
model.valid? if model
error_msg = options[:error_msg] ||= "Captcha response is incorrect, please try again."
model.errors.add_to_base error_msg if model
if model = options[:model]
model.valid?
model.errors.add_to_base "Captcha response is incorrect, please try again."
end
return false
else
session[:recaptcha_error] = nil
Expand Down
2 changes: 1 addition & 1 deletion test/verify_recaptcha_test.rb
Expand Up @@ -53,7 +53,7 @@ def test_errors_should_be_added_to_model
model.expects(:valid?)
model.expects(:errors).returns(errors)

assert !@controller.verify_recaptcha(model)
assert !@controller.verify_recaptcha(:model => model)
assert_equal "bad-news", @controller.session[:recaptcha_error]
end

Expand Down

0 comments on commit 931694f

Please sign in to comment.