macmillan-utils 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a52b592a6dc2fa6a8e43dab0d7bdcb0a124faec2
4
- data.tar.gz: d69410c60657a9a6926737cf947a3f9dee7ffcfe
3
+ metadata.gz: 264d16416f0255bd1acd4e7726ba9b8cac771965
4
+ data.tar.gz: 0faf3e3ed4d047880dadf0b35ed94491e59f7215
5
5
  SHA512:
6
- metadata.gz: 8af1e77116a173bc52941b007216f674848039649e48e3d738f2a86c78b33638065aa7890c35bb10d2102e3347a2720fb557625149acb05457805bc340a9451a
7
- data.tar.gz: bbc21e028c0be122c1edbd0aa6269bea942e425818ad2c340bd01c84935d13531e39cf590877aa06f6096b5af4326aa30f7a1354a4f895389469c073a44ac57b
6
+ metadata.gz: d497fef0654cefb7b49eb8a4ff481983b3e926dd47df8ae626ea33de97a128556f27548ec7d110f9d20b5f35bc7cf185f3ffff5b6e93504cb7dd442023a0ee49
7
+ data.tar.gz: a2770670c0a9ef6d84b04746882f138a4d2b7a7422370582c502d8ae5f7b2af169ac756bd95a4fe143cdf2c50b5fbb8b7160b3db93b0939646733af34c40d914
data/.travis.yml CHANGED
@@ -8,7 +8,7 @@ rvm:
8
8
  - 2.2
9
9
  - 2.3.0
10
10
  - 2.3.1
11
- - jruby
11
+ - jruby-9.0.0.0
12
12
  - rbx-2
13
13
 
14
14
  # Ensure we don't build for *every* commit (doesn't apply to PR builds)
@@ -31,7 +31,7 @@ module Macmillan
31
31
  @user_id_method = user_id_method
32
32
  @cookie_key = cookie_key
33
33
 
34
- env[cookie_key] = user_uuid
34
+ env[cookie_key] = final_user_uuid
35
35
  end
36
36
 
37
37
  def response
@@ -51,28 +51,29 @@ module Macmillan
51
51
  request.env[user_env_key]
52
52
  end
53
53
 
54
- def user_uuid
55
- @user_uuid ||= begin
54
+ def final_user_uuid
55
+ @final_user_uuid ||= begin
56
56
  if user
57
57
  Digest::SHA1.hexdigest(user.public_send(user_id_method).to_s)
58
- elsif cookie_uuid
59
- cookie_uuid
58
+ elsif uuid_from_cookies
59
+ uuid_from_cookies
60
60
  else
61
61
  SecureRandom.uuid
62
62
  end
63
63
  end
64
64
  end
65
65
 
66
- def cookie_uuid
66
+ def uuid_from_cookies
67
67
  request.cookies[cookie_key]
68
68
  end
69
69
 
70
70
  def store_cookie?
71
- user_uuid != cookie_uuid
71
+ final_user_uuid != uuid_from_cookies
72
72
  end
73
73
 
74
74
  def save_cookie
75
- response.set_cookie(cookie_key, { value: user_uuid, path: '/', expires: DateTime.now.next_year.to_time })
75
+ cookie_value = { value: final_user_uuid, path: '/', expires: DateTime.now.next_year.to_time }
76
+ response.set_cookie(cookie_key, cookie_value)
76
77
  end
77
78
 
78
79
  def clean_old_cookies
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Macmillan::Utils::Middleware::Uuid do
4
- let(:app) { ->(env) { [200, env, 'app'] } }
4
+ let(:app) { ->(_env) { app_return } }
5
+ let(:app_return) { [200, {}, ['app']] }
5
6
  let(:request) { req_for('http://example.com') }
6
7
  let(:user) { double(email: 'bob.flemming@cough.com', user_id: '12345') }
7
8
  let(:user_uuid) { Digest::SHA1.hexdigest(user.user_id.to_s) }
@@ -20,8 +21,8 @@ RSpec.describe Macmillan::Utils::Middleware::Uuid do
20
21
  end
21
22
 
22
23
  it 'stores the user_uuid in the env' do
23
- _status, headers, _body = subject.call(request.env)
24
- expect(headers['user.uuid']).to eq(user_uuid)
24
+ expect(app).to receive(:call).with(hash_including('user.uuid' => user_uuid)).and_return(app_return)
25
+ _status, _headers, _body = subject.call(request.env)
25
26
  end
26
27
  end
27
28
 
@@ -45,8 +46,8 @@ RSpec.describe Macmillan::Utils::Middleware::Uuid do
45
46
 
46
47
  context 'who has not visited before' do
47
48
  it 'stores the auto-generated UUID in the env' do
48
- _status, headers, _body = subject.call(request.env)
49
- expect(headers['user.uuid']).to eq('wibble')
49
+ expect(app).to receive(:call).with(hash_including('user.uuid' => 'wibble')).and_return(app_return)
50
+ _status, _headers, _body = subject.call(request.env)
50
51
  end
51
52
 
52
53
  it 'sets the user_uuid cookie' do
@@ -61,8 +62,8 @@ RSpec.describe Macmillan::Utils::Middleware::Uuid do
61
62
  end
62
63
 
63
64
  it 'stores the user_uuid (from the cookie) in the env' do
64
- _status, headers, _body = subject.call(request.env)
65
- expect(headers['user.uuid']).to eq('qwerty')
65
+ expect(app).to receive(:call).with(hash_including('user.uuid' => 'qwerty')).and_return(app_return)
66
+ _status, _headers, _body = subject.call(request.env)
66
67
  end
67
68
 
68
69
  it 'does not try to replace the cookie' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macmillan-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.29
4
+ version: 1.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Springer Nature
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -303,4 +303,3 @@ test_files:
303
303
  - spec/lib/macmillan/utils/statsd_decorator_spec.rb
304
304
  - spec/lib/macmillan/utils/statsd_middleware_spec.rb
305
305
  - spec/spec_helper.rb
306
- has_rdoc: