cookie_monster 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWFiOThjMzI5Y2FjOGUwYjcxOWRiMzU4NzVjYzY2YzM5NTllNmRjYw==
4
+ NjQ1OThkM2MxYTM3YzA2YWI0NzljYjRjNjgwZjljNzM5N2MwNjRiZg==
5
5
  data.tar.gz: !binary |-
6
- OGIwZTMwYmMwODg2M2FlYmE3M2IyNzFjYzRjMDBiYjcxZjRlODAyMw==
6
+ ZWNjYWJkYWQzZGNjYWE2ZDBmZDQ4ZWFlZGYxMWE2OThiYjdjNjUzNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NmIwNTVjM2Q3ZWJkZjE1MTFkNmZiNzBlMmViYzMzODJmNTIyOWMxZWE1Y2Fh
10
- NjVjZDRlOTBkMGI3NGRhNDk0ODNmMjhkN2I0NTE2YTE1ZTVhYzY5ODA3Y2Nh
11
- MjA5ZWU3YTMwODkzMWEyOTU5NTAxYzA2OGE2M2VlY2QyOWZiNjM=
9
+ MzRiZmU2NTY4NDJhNTQzNTRmMTJmMzgxYWE2YmJmOTkwY2QyNGE5NmI4YWY5
10
+ YjkzNGI5ZDNlNmY2NmQ5MDM0OTc2NGQzZjlmZTY2MWY3ZjY5NTk0MjA5ZjBj
11
+ NmUzMTc1Mjk4MWU1YjUxY2RjYmRjNTZlZWUyNGJjNDc5MDU1MzQ=
12
12
  data.tar.gz: !binary |-
13
- ODU5Y2RiZjk0NmE2Nzg5YzVjYWFlODA4NTY1OWQ3NTg1ODEwMDI1MzI5ZWQ3
14
- ZjU0ZTFiMGEyYWEzYjQwMjQ4NzNiNGIwNzJlMzBhMWExZTY0YTBmN2E1NmI0
15
- ZGMxNWNmODUwZmRhZTc1M2QxM2EzMDU0MWUxYjhmYWI4NjMyMmE=
13
+ ZjFjNTg0NGM2MjRiOTBhM2IzNmQwZWZkYTVjNzQ5NGNmYTYxYzI0MzgxMzA2
14
+ MWQwZDM1YWVmNDI1MjFjMzAwZTQyNWY0NzllMDNlMTg0NzQ4NWVmZmRhMmYz
15
+ MGQ3NDBjMWJkY2JjMDU2OTRkNzM3MTllMjMwNTQxZGJlYzAxZmY=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cookie_monster (0.1.2)
4
+ cookie_monster (0.1.3)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,21 +1,14 @@
1
1
  module CookieMonster
2
2
  class Jar < Base
3
- attr_reader :request, :response
3
+ attr_reader :cookies
4
4
 
5
- def initialize(options)
6
- @request = options.delete(:request)
7
- @response = options.delete(:response)
8
- @options = options
5
+ def initialize(cookies)
6
+ @cookies = cookies
9
7
  end
10
8
 
11
9
  def [](key)
12
- response_cookies = @response.respond_to?(:cookies) ? @response.cookies.with_indifferent_access : {}
13
- request_cookies = @request.respond_to?(:cookies) ? @request.cookies.with_indifferent_access : {}
14
-
15
- if response_cookies[key]
16
- cookie = response_cookies[key]
17
- elsif request_cookies[key]
18
- cookie = request_cookies[key]
10
+ if @cookies[key]
11
+ cookie = @cookies[key]
19
12
  else
20
13
  return nil
21
14
  end
@@ -34,7 +27,7 @@ module CookieMonster
34
27
 
35
28
  encrypted_value = Encryption.new(value).encrypt
36
29
 
37
- @response.set_cookie key, {
30
+ @cookies[key] = {
38
31
  :value => encrypted_value,
39
32
  :httponly => options[:httponly],
40
33
  :expires => options[:expires],
@@ -3,7 +3,7 @@ module CookieMonster
3
3
  private
4
4
 
5
5
  def cookie_monster
6
- @cookie_monster ||= CookieMonster::Jar.new(request: request, response: response, expires: 1.day.from_now)
6
+ @cookie_monster ||= CookieMonster::Jar.new(cookies)
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module CookieMonster
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -1,12 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class FakeRequest
4
- def cookies
5
- { foo: 'a cookie' }
6
- end
7
- end
8
-
9
- class FakeResponse
3
+ class FakeCookies
10
4
  attr_reader :cookies
11
5
  def initialize
12
6
  @cookies = {
@@ -14,25 +8,25 @@ class FakeResponse
14
8
  }
15
9
  end
16
10
 
17
- def set_cookie key, options
11
+ def [](key)
12
+ @cookies[key]
13
+ end
14
+
15
+ def []=(key, options)
18
16
  @cookies[key] = options
19
17
  end
20
18
  end
21
19
 
22
20
  class JarTest < Test::Unit::TestCase
23
21
  def setup
24
- @options = {
25
- request: FakeRequest.new,
26
- response: FakeResponse.new
27
- }
28
- @jar = CookieMonster::Jar.new(@options)
22
+ @jar = CookieMonster::Jar.new(FakeCookies.new)
29
23
  end
30
24
 
31
25
  def test_setting_a_cookie
32
26
  CookieMonster.configuration.expects(:iv).at_least_once.returns('x' * 16)
33
27
  @jar[:hello] = 'testing a cookie'
34
28
  assert_equal CookieMonster::Encryption.new('testing a cookie').encrypt,
35
- @jar.response.cookies[:hello][:value]
29
+ @jar.cookies[:hello][:value]
36
30
  end
37
31
 
38
32
  def test_reading_a_cookie_set_in_response_first
@@ -41,11 +35,7 @@ class JarTest < Test::Unit::TestCase
41
35
  end
42
36
 
43
37
  def test_reading_a_cookie_from_request
44
- assert_equal 'already set', @jar[:a_cookie]
45
- end
46
-
47
- def test_indifferent_access
48
- assert_equal @jar[:a_cookie], @jar['a_cookie']
38
+ assert_equal 'already set', @jar['a_cookie']
49
39
  end
50
40
 
51
41
  def test_setting_a_more_complicated_data_type
@@ -56,6 +46,6 @@ class JarTest < Test::Unit::TestCase
56
46
 
57
47
  def test_including_other_options
58
48
  @jar[:cookie] = 'something', { expires: 'some point in the future' }
59
- assert_equal 'some point in the future', @jar.response.cookies[:cookie][:expires]
49
+ assert_equal 'some point in the future', @jar.cookies[:cookie][:expires]
60
50
  end
61
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookie_monster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Griffin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-24 00:00:00.000000000 Z
11
+ date: 2013-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport