Class Merb::Test::CookieJar
In: merb-core/lib/merb-core/test/helpers/cookie_jar.rb
Parent: Object

Methods

for   new   update  

Public Class methods

:api: private

[Source]

    # File merb-core/lib/merb-core/test/helpers/cookie_jar.rb, line 75
75:       def initialize
76:         @jars = {}
77:       end

Public Instance methods

:api: private

[Source]

     # File merb-core/lib/merb-core/test/helpers/cookie_jar.rb, line 102
102:       def for(jar, uri)
103:         cookies = {}
104:         
105:         @jars[jar] ||= []
106:         # The cookies are sorted by most specific first. So, we loop through
107:         # all the cookies in order and add it to a hash by cookie name if
108:         # the cookie can be sent to the current URI. It's added to the hash
109:         # so that when we are done, the cookies will be unique by name and
110:         # we'll have grabbed the most specific to the URI.
111:         @jars[jar].each do |cookie|
112:           cookies[cookie.name] = cookie.raw if cookie.matches?(uri)
113:         end
114:         
115:         cookies.values.join(';')
116:       end

:api: private

[Source]

    # File merb-core/lib/merb-core/test/helpers/cookie_jar.rb, line 80
80:       def update(jar, uri, raw_cookies)
81:         return unless raw_cookies
82:         # Initialize all the the received cookies
83:         cookies = []
84:         raw_cookies.each do |raw|
85:           c = Cookie.new(raw, uri.host)
86:           cookies << c if c.valid?(uri)
87:         end
88:         
89:         @jars[jar] ||= []
90:         
91:         # Remove all the cookies that will be updated
92:         @jars[jar].delete_if do |existing|
93:           cookies.find { |c| [c.name, c.domain, c.path] == [existing.name, existing.domain, existing.path] }
94:         end
95:         
96:         @jars[jar].concat cookies
97:         
98:         @jars[jar].sort!
99:       end

[Validate]