Class: CookieCutter::TestSupport::FakeCookieJar

Inherits:
Object
  • Object
show all
Defined in:
lib/cookie_cutter/test_support/fake_cookie_jar.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FakeCookieJar

Returns a new instance of FakeCookieJar.



29
30
31
32
33
34
35
36
37
38
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 29

def initialize(*args)
  @cookies = {}
  @deleted_cookies = []
  if args.any?
    cookies = args.first
    cookies.keys.each do |cookie_name|
      self[cookie_name] = { value: cookies[cookie_name] }
    end
  end
end

Class Method Details

.empty!Object



9
10
11
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 9

def empty!
  @instance = nil
end

.findObject



5
6
7
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 5

def find
  @instance ||= FakeCookieJar.new
end

Instance Method Details

#[](name) ⇒ Object



14
15
16
17
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 14

def [](name)
  cookie = @cookies[name]
  cookie ? cookie[:value] : nil
end

#[]=(name, value) ⇒ Object



19
20
21
22
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 19

def []=(name, value)
  @cookies[name] = value
  @deleted_cookies.delete_if{|n| name == n}
end

#delete(name, options) ⇒ Object



24
25
26
27
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 24

def delete(name, options)
  @cookies.delete(name)
  @deleted_cookies << name
end

#deleted?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 40

def deleted?(name)
  @deleted_cookies.include?(name)
end

#metadata_for(name) ⇒ Object



48
49
50
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 48

def (name)
  @cookies[name]
end

#to_hashObject



44
45
46
# File 'lib/cookie_cutter/test_support/fake_cookie_jar.rb', line 44

def to_hash
  @cookies
end