Permalink
Browse files

get tests passing with new time behavior

  • Loading branch information...
1 parent ea07eda commit 7f6b49365b64eb3b4f5e2e2355eeaeb8d4d50af7 @technoweenie technoweenie committed Aug 9, 2012
Showing with 22 additions and 9 deletions.
  1. +4 −4 lib/multipass.rb
  2. +18 −5 test/multipass_test.rb
View
@@ -67,21 +67,21 @@ def encode(options = {})
def decode(data)
json = options = nil
json = @crypto_key.decrypt(self.class.decode_64(data, @url_safe))
-
+
if json.nil?
raise MultiPass::DecryptError.new(data)
end
options = decode_json(data, json)
-
+
if !options.is_a?(Hash)
raise MultiPass::JSONError.new(data, json, options)
end
options.keys.each do |key|
options[key.to_sym] = unencode_javascript_unicode_escape(options.delete(key))
end
-
+
# Force everything coming out of json into a Time object if it isn't already
# with YAJL, it parses dates for us (ugh)
if options.has_key?(:expires) && options[:expires].is_a?(String) && !options[:expires].empty?
@@ -156,4 +156,4 @@ def decode_json(data, s)
raise MultiPass::JSONError.new(data, s)
end
end
-end
+end
View
@@ -1,23 +1,34 @@
+# encoding: UTF-8
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'
require 'test/unit'
require 'multipass'
#require 'active_support'
+module MultiPassTestHelper
+ def assert_multipass(expected, actual)
+ assert_equal expected[:email], actual[:email]
+ assert_equal expected[:expires].to_s, actual[:expires].to_s
+ end
+end
+
module MultiPassTests
+ include MultiPassTestHelper
+
def test_encodes_multipass
expected = MultiPass.encode_64(@key.encrypt(@output.to_json), @mp.url_safe?)
assert_equal expected, @mp.encode(@input)
end
def test_decodes_multipass
encoded = @mp.encode(@input)
- assert_equal @input, @mp.decode(encoded)
+ assert_multipass @input, @mp.decode(encoded)
end
def test_decodes_multipass_with_class_method
encoded = @mp.encode(@input)
- assert_equal @input, MultiPass.decode('example', 'abc', encoded)
+ assert_multipass @input, MultiPass.decode('example', 'abc', encoded)
end
def test_decodes_unicode
@@ -80,6 +91,8 @@ def setup
end
class ErrorTest < Test::Unit::TestCase
+ include MultiPassTestHelper
+
def setup
@key = EzCrypto::Key.with_password('example', 'abc')
@mp = MultiPass.new('example', 'abc')
@@ -133,12 +146,12 @@ def test_expiration_error_stores_json
def test_expiration_error_stores_options
begin
- opt = {:expires => (Time.now - 5).to_s, :email => 'ricky@bobby.com'}
+ opt = {:expires => Time.now - 5, :email => 'ricky@bobby.com'}
json = opt.to_json
data = @key.encrypt64(json)
@mp.decode data
rescue MultiPass::ExpiredError => e
- assert_equal opt, e.options
+ assert_multipass opt, e.options
end
end
-end
+end

0 comments on commit 7f6b493

Please sign in to comment.