forked from erik-megarad/negative-captcha
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making negative_captcha hashes predictable for tests.
- Loading branch information
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rubygems' | ||
require 'active_support' | ||
require 'action_view' | ||
require 'test/unit' | ||
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/negative-captcha')) | ||
|
||
class TestableNegativeCaptchaTest < Test::Unit::TestCase | ||
def test_can_be_predictable_for_tests | ||
NegativeCaptcha.test_mode = true | ||
fields = [:name, :comment] | ||
|
||
captcha = NegativeCaptcha.new(:fields => fields) | ||
assert captcha.fields.is_a?(Hash) | ||
assert_equal captcha.fields.keys.sort{|a,b|a.to_s<=>b.to_s}, fields.sort{|a,b|a.to_s<=>b.to_s} | ||
|
||
filled_form = NegativeCaptcha.new( | ||
:fields => fields, | ||
:timestamp => captcha.timestamp, | ||
:params => {:timestamp => captcha.timestamp, :spinner => captcha.spinner}.merge(captcha.fields.inject({}){|hash, name, encrypted_name| hash[encrypted_name] = name; hash}) | ||
) | ||
|
||
assert_equal "", filled_form.error | ||
assert filled_form.valid? | ||
end | ||
end |