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 +4 -4
- data/.travis.yml +1 -1
- data/lib/macmillan/utils/middleware/uuid.rb +9 -8
- data/spec/lib/macmillan/utils/middleware/uuid_spec.rb +8 -7
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 264d16416f0255bd1acd4e7726ba9b8cac771965
|
4
|
+
data.tar.gz: 0faf3e3ed4d047880dadf0b35ed94491e59f7215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d497fef0654cefb7b49eb8a4ff481983b3e926dd47df8ae626ea33de97a128556f27548ec7d110f9d20b5f35bc7cf185f3ffff5b6e93504cb7dd442023a0ee49
|
7
|
+
data.tar.gz: a2770670c0a9ef6d84b04746882f138a4d2b7a7422370582c502d8ae5f7b2af169ac756bd95a4fe143cdf2c50b5fbb8b7160b3db93b0939646733af34c40d914
|
data/.travis.yml
CHANGED
@@ -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] =
|
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
|
55
|
-
@
|
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
|
59
|
-
|
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
|
66
|
+
def uuid_from_cookies
|
67
67
|
request.cookies[cookie_key]
|
68
68
|
end
|
69
69
|
|
70
70
|
def store_cookie?
|
71
|
-
|
71
|
+
final_user_uuid != uuid_from_cookies
|
72
72
|
end
|
73
73
|
|
74
74
|
def save_cookie
|
75
|
-
|
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) { ->(
|
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
|
-
|
24
|
-
|
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
|
-
|
49
|
-
|
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
|
-
|
65
|
-
|
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.
|
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-
|
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:
|