cookie_cutter 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
|
|
1
|
+
module CookieCutter
|
2
|
+
module TestSupport
|
3
|
+
class FakeCookieJar
|
4
|
+
class << self
|
5
|
+
def find
|
6
|
+
@instance ||= FakeCookieJar.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def empty!
|
10
|
+
@instance = nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](name)
|
15
|
+
cookie = @cookies[name]
|
16
|
+
cookie ? cookie[:value] : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(name, value)
|
20
|
+
@cookies[name] = value
|
21
|
+
@deleted_cookies.delete_if{|n| name == n}
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(name, options)
|
25
|
+
@cookies.delete(name)
|
26
|
+
@deleted_cookies << name
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(*args)
|
30
|
+
@cookies = {}
|
31
|
+
@deleted_cookies = []
|
32
|
+
if args.any?
|
33
|
+
cookies = args.first
|
34
|
+
cookies.keys.each do |cookie_name|
|
35
|
+
self[cookie_name] = { value: cookies[cookie_name] }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def deleted?(name)
|
41
|
+
@deleted_cookies.include?(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_hash
|
45
|
+
@cookies
|
46
|
+
end
|
47
|
+
|
48
|
+
def metadata_for(name)
|
49
|
+
@cookies[name]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'cookie_cutter/test_support/fake_cookie_jar'
|
2
|
+
|
3
|
+
module CookieCutter
|
4
|
+
module TestSupport
|
5
|
+
module Stubs
|
6
|
+
module Finders
|
7
|
+
def find(*args)
|
8
|
+
new(TestSupport::FakeCookieJar.find)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_all
|
13
|
+
TestSupport::FakeCookieJar.empty!
|
14
|
+
CookieCutter::Base::class_eval do
|
15
|
+
extend Finders
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/base_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'cookie_cutter'
|
3
|
-
|
3
|
+
require 'cookie_cutter/test_support'
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
|
6
6
|
class SingleValuedCookie < CookieCutter::Base
|
@@ -21,7 +21,7 @@ class MyMixedCaseCookie < CookieCutter::Base
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe CookieCutter::Base do
|
24
|
-
let(:cookie_jar) { FakeCookieJar.new }
|
24
|
+
let(:cookie_jar) { CookieCutter::TestSupport::FakeCookieJar.new }
|
25
25
|
it 'should not not update the cookie_jar when no value is set' do
|
26
26
|
SingleValuedCookie.new(cookie_jar)
|
27
27
|
cookie_jar.to_hash.should be_empty
|
@@ -129,7 +129,7 @@ describe CookieCutter::Base do
|
|
129
129
|
cookie_jar[:svc].should == "ordinary value"
|
130
130
|
end
|
131
131
|
it 'can be read via ordinary cookie jar' do
|
132
|
-
single_value_cookie = SingleValuedCookie.new(FakeCookieJar.new({ svc: "preset value" }))
|
132
|
+
single_value_cookie = SingleValuedCookie.new(CookieCutter::TestSupport::FakeCookieJar.new({ svc: "preset value" }))
|
133
133
|
single_value_cookie.value.should == "preset value"
|
134
134
|
end
|
135
135
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookie_cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -78,9 +78,11 @@ files:
|
|
78
78
|
- lib/cookie_cutter/base.rb
|
79
79
|
- lib/cookie_cutter/cookie.rb
|
80
80
|
- lib/cookie_cutter/cookie_attribute.rb
|
81
|
+
- lib/cookie_cutter/test_support.rb
|
82
|
+
- lib/cookie_cutter/test_support/fake_cookie_jar.rb
|
83
|
+
- lib/cookie_cutter/test_support/stubs.rb
|
81
84
|
- lib/cookie_cutter/version.rb
|
82
85
|
- spec/base_spec.rb
|
83
|
-
- spec/support/fake_cookie_jar.rb
|
84
86
|
homepage: http://github.com/andyalm/cookie_cutter
|
85
87
|
licenses: []
|
86
88
|
post_install_message:
|
@@ -95,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
97
|
version: '0'
|
96
98
|
segments:
|
97
99
|
- 0
|
98
|
-
hash:
|
100
|
+
hash: -915929631811276243
|
99
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
102
|
none: false
|
101
103
|
requirements:
|
@@ -104,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
106
|
version: '0'
|
105
107
|
segments:
|
106
108
|
- 0
|
107
|
-
hash:
|
109
|
+
hash: -915929631811276243
|
108
110
|
requirements: []
|
109
111
|
rubyforge_project:
|
110
112
|
rubygems_version: 1.8.24
|
@@ -114,4 +116,3 @@ summary: Provides a way to define the structure, lifetime, and other properties
|
|
114
116
|
a cookie all in one place.
|
115
117
|
test_files:
|
116
118
|
- spec/base_spec.rb
|
117
|
-
- spec/support/fake_cookie_jar.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
class FakeCookieJar
|
2
|
-
def [](name)
|
3
|
-
cookie = @cookies[name]
|
4
|
-
if cookie
|
5
|
-
cookie[:value]
|
6
|
-
else
|
7
|
-
nil
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def []=(name, value)
|
12
|
-
@cookies[name] = value
|
13
|
-
end
|
14
|
-
|
15
|
-
def delete(name, options)
|
16
|
-
@deleted_cookies << name
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(*args)
|
20
|
-
@cookies = {}
|
21
|
-
@deleted_cookies = []
|
22
|
-
if args.any?
|
23
|
-
cookies = args.first
|
24
|
-
cookies.keys.each do |cookie_name|
|
25
|
-
self[cookie_name] = { value: cookies[cookie_name] }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def deleted?(name)
|
31
|
-
@deleted_cookies.include?(name)
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_hash
|
35
|
-
@cookies
|
36
|
-
end
|
37
|
-
|
38
|
-
def metadata_for(name)
|
39
|
-
@cookies[name]
|
40
|
-
end
|
41
|
-
end
|