Class: Authlogic::TestCase::MockEncryptedCookieJar

Inherits:
MockCookieJar
  • Object
show all
Defined in:
lib/authlogic/test_case/mock_cookie_jar.rb

Overview

Which ActionDispatch class is this a mock of? TODO: Document as with other mocks above.

Instance Attribute Summary collapse

Attributes inherited from MockCookieJar

#set_cookies

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MockCookieJar

#delete, #encrypted, #signed

Constructor Details

#initialize(parent_jar) ⇒ MockEncryptedCookieJar

Returns a new instance of MockEncryptedCookieJar.


65
66
67
68
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 65

def initialize(parent_jar)
  @parent_jar = parent_jar
  parent_jar.each { |k, v| self[k] = v }
end

Instance Attribute Details

#parent_jarObject (readonly)

helper for testing


63
64
65
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 63

def parent_jar
  @parent_jar
end

Class Method Details

.decrypt(str) ⇒ Object


87
88
89
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 87

def self.decrypt(str)
  str.unpack("U*").map(&:pred).pack("U*")
end

.encrypt(str) ⇒ Object

simple caesar cipher for testing


83
84
85
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 83

def self.encrypt(str)
  str.unpack("U*").map(&:succ).pack("U*")
end

Instance Method Details

#[](val) ⇒ Object


70
71
72
73
74
75
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 70

def [](val)
  encrypted_message = @parent_jar[val]
  if encrypted_message
    self.class.decrypt(encrypted_message)
  end
end

#[]=(key, options) ⇒ Object


77
78
79
80
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 77

def []=(key, options)
  options[:value] = self.class.encrypt(options[:value])
  @parent_jar[key] = options
end