analytics-ruby 2.0.13 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/History.md +15 -0
- data/Makefile +1 -1
- data/analytics-ruby-2.0.13.gem +0 -0
- data/analytics-ruby-2.1.0.gem +0 -0
- data/lib/segment/analytics.rb +1 -1
- data/lib/segment/analytics/client.rb +19 -2
- data/lib/segment/analytics/version.rb +1 -1
- data/lib/segment/analytics/worker.rb +2 -2
- data/spec/segment/analytics/client_spec.rb +160 -140
- data/spec/segment/analytics/request_spec.rb +191 -0
- data/spec/segment/analytics/response_spec.rb +30 -0
- data/spec/segment/analytics/worker_spec.rb +33 -27
- data/spec/segment/analytics_spec.rb +40 -29
- metadata +25 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f272d5ddcbdd3fbded71fa72482a8d5b27679d9d
|
4
|
+
data.tar.gz: 70a98af711f968d00e0e7a68144afddb98fe00e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e61136a5eb4d08866638bb0084e4fe9977d08f15a2498ce642335b2eed4f33adcefe0c53100924bee3b4774ede158a0a8fc8a149dd20e5b8e740198add41cf7
|
7
|
+
data.tar.gz: 8e93c453d66121654cb841da5937ac62409ba089b9c1d9cda708d7db1065b077a406d72198e2ba8b53f5dfacd8340271729c36bcd5d785692ab85f00f82ad645
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
analytics-ruby (2.0.
|
4
|
+
analytics-ruby (2.0.13)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (3.2.
|
9
|
+
activesupport (3.2.22)
|
10
10
|
i18n (~> 0.6, >= 0.6.4)
|
11
11
|
multi_json (~> 1.0)
|
12
12
|
diff-lcs (1.2.5)
|
13
13
|
i18n (0.7.0)
|
14
|
-
multi_json (1.11.
|
14
|
+
multi_json (1.11.2)
|
15
15
|
predicated (0.2.6)
|
16
16
|
rake (10.4.2)
|
17
|
-
rspec (2.
|
18
|
-
rspec-core (~> 2.
|
19
|
-
rspec-expectations (~> 2.
|
20
|
-
rspec-mocks (~> 2.
|
21
|
-
rspec-core (2.
|
22
|
-
rspec-expectations (2.
|
17
|
+
rspec (2.99.0)
|
18
|
+
rspec-core (~> 2.99.0)
|
19
|
+
rspec-expectations (~> 2.99.0)
|
20
|
+
rspec-mocks (~> 2.99.0)
|
21
|
+
rspec-core (2.99.2)
|
22
|
+
rspec-expectations (2.99.2)
|
23
23
|
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
-
rspec-mocks (2.
|
25
|
-
ruby2ruby (2.
|
24
|
+
rspec-mocks (2.99.4)
|
25
|
+
ruby2ruby (2.2.0)
|
26
26
|
ruby_parser (~> 3.1)
|
27
27
|
sexp_processor (~> 4.0)
|
28
|
-
ruby_parser (3.
|
28
|
+
ruby_parser (3.7.2)
|
29
29
|
sexp_processor (~> 4.1)
|
30
|
-
sexp_processor (4.
|
31
|
-
thread_safe (0.3.
|
30
|
+
sexp_processor (4.6.0)
|
31
|
+
thread_safe (0.3.5)
|
32
32
|
tzinfo (1.2.1)
|
33
33
|
thread_safe (~> 0.1)
|
34
34
|
wrong (0.7.1)
|
@@ -50,4 +50,4 @@ DEPENDENCIES
|
|
50
50
|
wrong (~> 0.0)
|
51
51
|
|
52
52
|
BUNDLED WITH
|
53
|
-
1.
|
53
|
+
1.11.2
|
data/History.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
|
2
|
+
2.1.0 / 2016-06-17
|
3
|
+
==================
|
4
|
+
|
5
|
+
* Fix: Ensure error handler is called before Client#flush finishes.
|
6
|
+
* Feature: Support setting a custom message ID.
|
7
|
+
|
8
|
+
2.0.13 / 2015-09-15
|
9
|
+
==================
|
10
|
+
|
11
|
+
* readme: updated install docs
|
12
|
+
* fix: page/screen to allow no name
|
13
|
+
* git: ignore ruby version
|
14
|
+
* travis-ci: remove old rubys
|
15
|
+
|
1
16
|
2.0.12 / 2015-01-10
|
2
17
|
==================
|
3
18
|
|
data/Makefile
CHANGED
Binary file
|
Binary file
|
data/lib/segment/analytics.rb
CHANGED
@@ -52,6 +52,7 @@ module Segment
|
|
52
52
|
# :properties - Hash of event properties. (optional)
|
53
53
|
# :timestamp - Time of when the event occurred. (optional)
|
54
54
|
# :user_id - String of the user id.
|
55
|
+
# :message_id - String of the message id that uniquely identified a message across the API. (optional)
|
55
56
|
def track attrs
|
56
57
|
symbolize_keys! attrs
|
57
58
|
check_user_id! attrs
|
@@ -60,6 +61,7 @@ module Segment
|
|
60
61
|
properties = attrs[:properties] || {}
|
61
62
|
timestamp = attrs[:timestamp] || Time.new
|
62
63
|
context = attrs[:context] || {}
|
64
|
+
message_id = attrs[:message_id].to_s if attrs[:message_id]
|
63
65
|
|
64
66
|
check_timestamp! timestamp
|
65
67
|
|
@@ -76,10 +78,11 @@ module Segment
|
|
76
78
|
:event => event,
|
77
79
|
:userId => attrs[:user_id],
|
78
80
|
:anonymousId => attrs[:anonymous_id],
|
79
|
-
:context =>
|
81
|
+
:context => context,
|
80
82
|
:options => attrs[:options],
|
81
83
|
:integrations => attrs[:integrations],
|
82
84
|
:properties => properties,
|
85
|
+
:messageId => message_id,
|
83
86
|
:timestamp => datetime_in_iso8601(timestamp),
|
84
87
|
:type => 'track'
|
85
88
|
})
|
@@ -95,6 +98,7 @@ module Segment
|
|
95
98
|
# :timestamp - Time of when the event occurred. (optional)
|
96
99
|
# :traits - Hash of user traits. (optional)
|
97
100
|
# :user_id - String of the user id
|
101
|
+
# :message_id - String of the message id that uniquely identified a message across the API. (optional)
|
98
102
|
def identify attrs
|
99
103
|
symbolize_keys! attrs
|
100
104
|
check_user_id! attrs
|
@@ -102,6 +106,7 @@ module Segment
|
|
102
106
|
traits = attrs[:traits] || {}
|
103
107
|
timestamp = attrs[:timestamp] || Time.new
|
104
108
|
context = attrs[:context] || {}
|
109
|
+
message_id = attrs[:message_id].to_s if attrs[:message_id]
|
105
110
|
|
106
111
|
check_timestamp! timestamp
|
107
112
|
|
@@ -117,6 +122,7 @@ module Segment
|
|
117
122
|
:context => context,
|
118
123
|
:traits => traits,
|
119
124
|
:options => attrs[:options],
|
125
|
+
:messageId => message_id,
|
120
126
|
:timestamp => datetime_in_iso8601(timestamp),
|
121
127
|
:type => 'identify'
|
122
128
|
})
|
@@ -131,6 +137,7 @@ module Segment
|
|
131
137
|
# :previous_id - String of the id to alias from
|
132
138
|
# :timestamp - Time of when the alias occured (optional)
|
133
139
|
# :user_id - String of the id to alias to
|
140
|
+
# :message_id - String of the message id that uniquely identified a message across the API. (optional)
|
134
141
|
def alias(attrs)
|
135
142
|
symbolize_keys! attrs
|
136
143
|
|
@@ -138,6 +145,7 @@ module Segment
|
|
138
145
|
to = attrs[:user_id]
|
139
146
|
timestamp = attrs[:timestamp] || Time.new
|
140
147
|
context = attrs[:context] || {}
|
148
|
+
message_id = attrs[:message_id].to_s if attrs[:message_id]
|
141
149
|
|
142
150
|
check_presence! from, 'previous_id'
|
143
151
|
check_presence! to, 'user_id'
|
@@ -150,6 +158,7 @@ module Segment
|
|
150
158
|
:integrations => attrs[:integrations],
|
151
159
|
:context => context,
|
152
160
|
:options => attrs[:options],
|
161
|
+
:messageId => message_id,
|
153
162
|
:timestamp => datetime_in_iso8601(timestamp),
|
154
163
|
:type => 'alias'
|
155
164
|
})
|
@@ -164,6 +173,7 @@ module Segment
|
|
164
173
|
# :previous_id - String of the id to alias from
|
165
174
|
# :timestamp - Time of when the alias occured (optional)
|
166
175
|
# :user_id - String of the id to alias to
|
176
|
+
# :message_id - String of the message id that uniquely identified a message across the API. (optional)
|
167
177
|
def group(attrs)
|
168
178
|
symbolize_keys! attrs
|
169
179
|
check_user_id! attrs
|
@@ -173,6 +183,7 @@ module Segment
|
|
173
183
|
traits = attrs[:traits] || {}
|
174
184
|
timestamp = attrs[:timestamp] || Time.new
|
175
185
|
context = attrs[:context] || {}
|
186
|
+
message_id = attrs[:message_id].to_s if attrs[:message_id]
|
176
187
|
|
177
188
|
fail ArgumentError, '.traits must be a hash' unless traits.is_a? Hash
|
178
189
|
isoify_dates! traits
|
@@ -188,6 +199,7 @@ module Segment
|
|
188
199
|
:integrations => attrs[:integrations],
|
189
200
|
:options => attrs[:options],
|
190
201
|
:context => context,
|
202
|
+
:messageId => message_id,
|
191
203
|
:timestamp => datetime_in_iso8601(timestamp),
|
192
204
|
:type => 'group'
|
193
205
|
})
|
@@ -205,6 +217,7 @@ module Segment
|
|
205
217
|
# :properties - Hash of page properties (optional)
|
206
218
|
# :timestamp - Time of when the pageview occured (optional)
|
207
219
|
# :user_id - String of the id to alias from
|
220
|
+
# :message_id - String of the message id that uniquely identified a message across the API. (optional)
|
208
221
|
def page(attrs)
|
209
222
|
symbolize_keys! attrs
|
210
223
|
check_user_id! attrs
|
@@ -213,6 +226,7 @@ module Segment
|
|
213
226
|
properties = attrs[:properties] || {}
|
214
227
|
timestamp = attrs[:timestamp] || Time.new
|
215
228
|
context = attrs[:context] || {}
|
229
|
+
message_id = attrs[:message_id].to_s if attrs[:message_id]
|
216
230
|
|
217
231
|
fail ArgumentError, '.properties must be a hash' unless properties.is_a? Hash
|
218
232
|
isoify_dates! properties
|
@@ -229,6 +243,7 @@ module Segment
|
|
229
243
|
:integrations => attrs[:integrations],
|
230
244
|
:options => attrs[:options],
|
231
245
|
:context => context,
|
246
|
+
:messageId => message_id,
|
232
247
|
:timestamp => datetime_in_iso8601(timestamp),
|
233
248
|
:type => 'page'
|
234
249
|
})
|
@@ -253,6 +268,7 @@ module Segment
|
|
253
268
|
properties = attrs[:properties] || {}
|
254
269
|
timestamp = attrs[:timestamp] || Time.new
|
255
270
|
context = attrs[:context] || {}
|
271
|
+
message_id = attrs[:message_id].to_s if attrs[:message_id]
|
256
272
|
|
257
273
|
fail ArgumentError, '.properties must be a hash' unless properties.is_a? Hash
|
258
274
|
isoify_dates! properties
|
@@ -269,6 +285,7 @@ module Segment
|
|
269
285
|
:options => attrs[:options],
|
270
286
|
:integrations => attrs[:integrations],
|
271
287
|
:context => context,
|
288
|
+
:messageId => message_id,
|
272
289
|
:timestamp => timestamp.iso8601,
|
273
290
|
:type => 'screen'
|
274
291
|
})
|
@@ -288,7 +305,7 @@ module Segment
|
|
288
305
|
# returns Boolean of whether the item was added to the queue.
|
289
306
|
def enqueue(action)
|
290
307
|
# add our request id for tracing purposes
|
291
|
-
action[:messageId]
|
308
|
+
action[:messageId] ||= uid
|
292
309
|
unless queue_full = @queue.length >= @max_queue_size
|
293
310
|
ensure_worker_running
|
294
311
|
@queue << action
|
@@ -3,37 +3,39 @@ require 'spec_helper'
|
|
3
3
|
module Segment
|
4
4
|
class Analytics
|
5
5
|
describe Client do
|
6
|
+
let(:client) { Client.new :write_key => WRITE_KEY }
|
7
|
+
let(:queue) { client.instance_variable_get :@queue }
|
8
|
+
|
6
9
|
describe '#initialize' do
|
7
|
-
it '
|
10
|
+
it 'errors if no write_key is supplied' do
|
8
11
|
expect { Client.new }.to raise_error(ArgumentError)
|
9
12
|
end
|
10
13
|
|
11
|
-
it '
|
12
|
-
|
14
|
+
it 'does not error if a write_key is supplied' do
|
15
|
+
expect do
|
16
|
+
Client.new :write_key => WRITE_KEY
|
17
|
+
end.to_not raise_error
|
13
18
|
end
|
14
19
|
|
15
|
-
it '
|
16
|
-
|
20
|
+
it 'does not error if a write_key is supplied as a string' do
|
21
|
+
expect do
|
22
|
+
Client.new 'write_key' => WRITE_KEY
|
23
|
+
end.to_not raise_error
|
17
24
|
end
|
18
25
|
end
|
19
26
|
|
20
27
|
describe '#track' do
|
21
|
-
|
22
|
-
|
23
|
-
@queue = @client.instance_variable_get :@queue
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should error without an event' do
|
27
|
-
expect { @client.track(:user_id => 'user') }.to raise_error(ArgumentError)
|
28
|
+
it 'errors without an event' do
|
29
|
+
expect { client.track(:user_id => 'user') }.to raise_error(ArgumentError)
|
28
30
|
end
|
29
31
|
|
30
|
-
it '
|
31
|
-
expect {
|
32
|
+
it 'errors without a user_id' do
|
33
|
+
expect { client.track(:event => 'Event') }.to raise_error(ArgumentError)
|
32
34
|
end
|
33
35
|
|
34
|
-
it '
|
36
|
+
it 'errors if properties is not a hash' do
|
35
37
|
expect {
|
36
|
-
|
38
|
+
client.track({
|
37
39
|
:user_id => 'user',
|
38
40
|
:event => 'Event',
|
39
41
|
:properties => [1,2,3]
|
@@ -41,32 +43,36 @@ module Segment
|
|
41
43
|
}.to raise_error(ArgumentError)
|
42
44
|
end
|
43
45
|
|
44
|
-
it '
|
46
|
+
it 'uses the timestamp given' do
|
45
47
|
time = Time.parse("1990-07-16 13:30:00.123 UTC")
|
46
48
|
|
47
|
-
|
49
|
+
client.track({
|
48
50
|
:event => 'testing the timestamp',
|
49
51
|
:user_id => 'joe',
|
50
52
|
:timestamp => time
|
51
53
|
})
|
52
54
|
|
53
|
-
msg =
|
55
|
+
msg = queue.pop
|
54
56
|
|
55
|
-
Time.parse(msg[:timestamp]).
|
57
|
+
expect(Time.parse(msg[:timestamp])).to eq(time)
|
56
58
|
end
|
57
59
|
|
58
|
-
it '
|
59
|
-
|
60
|
-
|
60
|
+
it 'does not error with the required options' do
|
61
|
+
expect do
|
62
|
+
client.track Queued::TRACK
|
63
|
+
queue.pop
|
64
|
+
end.to_not raise_error
|
61
65
|
end
|
62
66
|
|
63
|
-
it '
|
64
|
-
|
65
|
-
|
67
|
+
it 'does not error when given string keys' do
|
68
|
+
expect do
|
69
|
+
client.track Utils.stringify_keys(Queued::TRACK)
|
70
|
+
queue.pop
|
71
|
+
end.to_not raise_error
|
66
72
|
end
|
67
73
|
|
68
|
-
it '
|
69
|
-
|
74
|
+
it 'converts time and date traits into iso8601 format' do
|
75
|
+
client.track({
|
70
76
|
:user_id => 'user',
|
71
77
|
:event => 'Event',
|
72
78
|
:properties => {
|
@@ -77,38 +83,38 @@ module Segment
|
|
77
83
|
:nottime => 'x'
|
78
84
|
}
|
79
85
|
})
|
80
|
-
message =
|
81
|
-
|
82
|
-
message[:properties][:
|
83
|
-
message[:properties][:
|
84
|
-
message[:properties][:
|
85
|
-
message[:properties][:
|
86
|
+
message = queue.pop
|
87
|
+
|
88
|
+
expect(message[:properties][:time]).to eq('2013-01-01T00:00:00.000Z')
|
89
|
+
expect(message[:properties][:time_with_zone]).to eq('2013-01-01T00:00:00.000Z')
|
90
|
+
expect(message[:properties][:date_time]).to eq('2013-01-01T00:00:00.000Z')
|
91
|
+
expect(message[:properties][:date]).to eq('2013-01-01')
|
92
|
+
expect(message[:properties][:nottime]).to eq('x')
|
86
93
|
end
|
87
94
|
end
|
88
95
|
|
89
96
|
|
90
97
|
describe '#identify' do
|
91
|
-
|
92
|
-
|
93
|
-
@queue = @client.instance_variable_get :@queue
|
98
|
+
it 'errors without any user id' do
|
99
|
+
expect { client.identify({}) }.to raise_error(ArgumentError)
|
94
100
|
end
|
95
101
|
|
96
|
-
it '
|
97
|
-
expect
|
102
|
+
it 'does not error with the required options' do
|
103
|
+
expect do
|
104
|
+
client.identify Queued::IDENTIFY
|
105
|
+
queue.pop
|
106
|
+
end.to_not raise_error
|
98
107
|
end
|
99
108
|
|
100
|
-
it '
|
101
|
-
|
102
|
-
|
109
|
+
it 'does not error with the required options as strings' do
|
110
|
+
expect do
|
111
|
+
client.identify Utils.stringify_keys(Queued::IDENTIFY)
|
112
|
+
queue.pop
|
113
|
+
end.to_not raise_error
|
103
114
|
end
|
104
115
|
|
105
|
-
it '
|
106
|
-
|
107
|
-
@queue.pop
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should convert time and date traits into iso8601 format' do
|
111
|
-
@client.identify({
|
116
|
+
it 'converts time and date traits into iso8601 format' do
|
117
|
+
client.identify({
|
112
118
|
:user_id => 'user',
|
113
119
|
:traits => {
|
114
120
|
:time => Time.utc(2013),
|
@@ -118,65 +124,60 @@ module Segment
|
|
118
124
|
:nottime => 'x'
|
119
125
|
}
|
120
126
|
})
|
121
|
-
|
122
|
-
message
|
123
|
-
|
124
|
-
message[:traits][:
|
125
|
-
message[:traits][:
|
126
|
-
message[:traits][:
|
127
|
+
|
128
|
+
message = queue.pop
|
129
|
+
|
130
|
+
expect(message[:traits][:time]).to eq('2013-01-01T00:00:00.000Z')
|
131
|
+
expect(message[:traits][:time_with_zone]).to eq('2013-01-01T00:00:00.000Z')
|
132
|
+
expect(message[:traits][:date_time]).to eq('2013-01-01T00:00:00.000Z')
|
133
|
+
expect(message[:traits][:date]).to eq('2013-01-01')
|
134
|
+
expect(message[:traits][:nottime]).to eq('x')
|
127
135
|
end
|
128
136
|
end
|
129
137
|
|
130
138
|
describe '#alias' do
|
131
|
-
|
132
|
-
|
139
|
+
it 'errors without from' do
|
140
|
+
expect { client.alias :user_id => 1234 }.to raise_error(ArgumentError)
|
133
141
|
end
|
134
142
|
|
135
|
-
it '
|
136
|
-
expect {
|
143
|
+
it 'errors without to' do
|
144
|
+
expect { client.alias :previous_id => 1234 }.to raise_error(ArgumentError)
|
137
145
|
end
|
138
146
|
|
139
|
-
it '
|
140
|
-
expect {
|
147
|
+
it 'does not error with the required options' do
|
148
|
+
expect { client.alias ALIAS }.to_not raise_error
|
141
149
|
end
|
142
150
|
|
143
|
-
it '
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
it 'should not error with the required options as strings' do
|
148
|
-
@client.alias Utils.stringify_keys(ALIAS)
|
151
|
+
it 'does not error with the required options as strings' do
|
152
|
+
expect do
|
153
|
+
client.alias Utils.stringify_keys(ALIAS)
|
154
|
+
end.to_not raise_error
|
149
155
|
end
|
150
156
|
end
|
151
157
|
|
152
158
|
describe '#group' do
|
153
|
-
|
154
|
-
|
155
|
-
@queue = @client.instance_variable_get :@queue
|
156
|
-
end
|
157
|
-
|
158
|
-
after :each do
|
159
|
-
@client.flush
|
159
|
+
after do
|
160
|
+
client.flush
|
160
161
|
end
|
161
162
|
|
162
|
-
it '
|
163
|
-
expect {
|
163
|
+
it 'errors without group_id' do
|
164
|
+
expect { client.group :user_id => 'foo' }.to raise_error(ArgumentError)
|
164
165
|
end
|
165
166
|
|
166
|
-
it '
|
167
|
-
expect {
|
167
|
+
it 'errors without user_id' do
|
168
|
+
expect { client.group :group_id => 'foo' }.to raise_error(ArgumentError)
|
168
169
|
end
|
169
170
|
|
170
|
-
it '
|
171
|
-
|
171
|
+
it 'does not error with the required options' do
|
172
|
+
client.group Queued::GROUP
|
172
173
|
end
|
173
174
|
|
174
|
-
it '
|
175
|
-
|
175
|
+
it 'does not error with the required options as strings' do
|
176
|
+
client.group Utils.stringify_keys(Queued::GROUP)
|
176
177
|
end
|
177
178
|
|
178
|
-
it '
|
179
|
-
|
179
|
+
it 'converts time and date traits into iso8601 format' do
|
180
|
+
client.identify({
|
180
181
|
:user_id => 'user',
|
181
182
|
:group_id => 'group',
|
182
183
|
:traits => {
|
@@ -187,70 +188,65 @@ module Segment
|
|
187
188
|
:nottime => 'x'
|
188
189
|
}
|
189
190
|
})
|
190
|
-
|
191
|
-
message
|
192
|
-
|
193
|
-
message[:traits][:
|
194
|
-
message[:traits][:
|
195
|
-
message[:traits][:
|
191
|
+
|
192
|
+
message = queue.pop
|
193
|
+
|
194
|
+
expect(message[:traits][:time]).to eq('2013-01-01T00:00:00.000Z')
|
195
|
+
expect(message[:traits][:time_with_zone]).to eq('2013-01-01T00:00:00.000Z')
|
196
|
+
expect(message[:traits][:date_time]).to eq('2013-01-01T00:00:00.000Z')
|
197
|
+
expect(message[:traits][:date]).to eq('2013-01-01')
|
198
|
+
expect(message[:traits][:nottime]).to eq('x')
|
196
199
|
end
|
197
200
|
end
|
198
201
|
|
199
202
|
describe '#page' do
|
200
|
-
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'should error without user_id' do
|
205
|
-
expect { @client.page :name => 'foo' }.to raise_error(ArgumentError)
|
203
|
+
it 'errors without user_id' do
|
204
|
+
expect { client.page :name => 'foo' }.to raise_error(ArgumentError)
|
206
205
|
end
|
207
206
|
|
208
|
-
it '
|
209
|
-
|
207
|
+
it 'does not error with the required options' do
|
208
|
+
expect { client.page Queued::PAGE }.to_not raise_error
|
210
209
|
end
|
211
210
|
|
212
|
-
it '
|
213
|
-
|
211
|
+
it 'does not error with the required options as strings' do
|
212
|
+
expect do
|
213
|
+
client.page Utils.stringify_keys(Queued::PAGE)
|
214
|
+
end.to_not raise_error
|
214
215
|
end
|
215
216
|
end
|
216
217
|
|
217
218
|
describe '#screen' do
|
218
|
-
|
219
|
-
|
219
|
+
it 'errors without user_id' do
|
220
|
+
expect { client.screen :name => 'foo' }.to raise_error(ArgumentError)
|
220
221
|
end
|
221
222
|
|
222
|
-
it '
|
223
|
-
expect {
|
223
|
+
it 'does not error with the required options' do
|
224
|
+
expect { client.screen Queued::SCREEN }.to_not raise_error
|
224
225
|
end
|
225
226
|
|
226
|
-
it '
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
it 'should not error with the required options as strings' do
|
231
|
-
@client.screen Utils.stringify_keys(Queued::SCREEN)
|
227
|
+
it 'does not error with the required options as strings' do
|
228
|
+
expect do
|
229
|
+
client.screen Utils.stringify_keys(Queued::SCREEN)
|
230
|
+
end.to_not raise_error
|
232
231
|
end
|
233
232
|
end
|
234
233
|
|
235
234
|
describe '#flush' do
|
236
|
-
|
237
|
-
|
238
|
-
|
235
|
+
it 'waits for the queue to finish on a flush' do
|
236
|
+
client.identify Queued::IDENTIFY
|
237
|
+
client.track Queued::TRACK
|
238
|
+
client.flush
|
239
239
|
|
240
|
-
|
241
|
-
@client.identify Queued::IDENTIFY
|
242
|
-
@client.track Queued::TRACK
|
243
|
-
@client.flush
|
244
|
-
@client.queued_messages.should == 0
|
240
|
+
expect(client.queued_messages).to eq(0)
|
245
241
|
end
|
246
242
|
|
247
|
-
it '
|
248
|
-
|
243
|
+
it 'completes when the process forks' do
|
244
|
+
client.identify Queued::IDENTIFY
|
249
245
|
|
250
246
|
Process.fork do
|
251
|
-
|
252
|
-
|
253
|
-
|
247
|
+
client.track Queued::TRACK
|
248
|
+
client.flush
|
249
|
+
expect(client.queued_messages).to eq(0)
|
254
250
|
end
|
255
251
|
|
256
252
|
Process.wait
|
@@ -258,31 +254,55 @@ module Segment
|
|
258
254
|
end
|
259
255
|
|
260
256
|
context 'common' do
|
261
|
-
check_property = proc { |msg, k, v| msg[k] && msg[k]
|
257
|
+
check_property = proc { |msg, k, v| msg[k] && msg[k] == v }
|
262
258
|
|
263
|
-
|
264
|
-
@client = Client.new :write_key => WRITE_KEY
|
265
|
-
@queue = @client.instance_variable_get :@queue
|
266
|
-
end
|
259
|
+
let(:data) { { :user_id => 1, :group_id => 2, :previous_id => 3, :anonymous_id => 4, :message_id => 5, :event => "coco barked", :name => "coco" } }
|
267
260
|
|
261
|
+
it 'does not convert ids given as fixnums to strings' do
|
262
|
+
[:track, :screen, :page, :identify].each do |s|
|
263
|
+
client.send(s, data)
|
264
|
+
message = queue.pop(true)
|
268
265
|
|
269
|
-
|
266
|
+
expect(check_property.call(message, :userId, 1)).to eq(true)
|
267
|
+
expect(check_property.call(message, :anonymousId, 4)).to eq(true)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'converts message id to string' do
|
270
272
|
[:track, :screen, :page, :group, :identify, :alias].each do |s|
|
271
|
-
|
272
|
-
message =
|
273
|
-
|
274
|
-
check_property.call(message, :
|
275
|
-
|
276
|
-
|
273
|
+
client.send(s, data)
|
274
|
+
message = queue.pop(true)
|
275
|
+
|
276
|
+
expect(check_property.call(message, :messageId, '5')).to eq(true)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
context 'group' do
|
281
|
+
it 'does not convert ids given as fixnums to strings' do
|
282
|
+
client.group(data)
|
283
|
+
message = queue.pop(true)
|
284
|
+
|
285
|
+
expect(check_property.call(message, :userId, 1)).to eq(true)
|
286
|
+
expect(check_property.call(message, :groupId, 2)).to eq(true)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'alias' do
|
291
|
+
it 'does not convert ids given as fixnums to strings' do
|
292
|
+
client.alias(data)
|
293
|
+
message = queue.pop(true)
|
294
|
+
|
295
|
+
expect(check_property.call(message, :userId, 1)).to eq(true)
|
296
|
+
expect(check_property.call(message, :previousId, 3)).to eq(true)
|
277
297
|
end
|
278
298
|
end
|
279
299
|
|
280
|
-
it '
|
300
|
+
it 'sends integrations' do
|
281
301
|
[:track, :screen, :page, :group, :identify, :alias].each do |s|
|
282
|
-
|
283
|
-
message =
|
284
|
-
message[:integrations][:All].
|
285
|
-
message[:integrations][:Salesforce].
|
302
|
+
client.send s, :integrations => { :All => true, :Salesforce => false }, :user_id => 1, :group_id => 2, :previous_id => 3, :anonymous_id => 4, :event => "coco barked", :name => "coco"
|
303
|
+
message = queue.pop(true)
|
304
|
+
expect(message[:integrations][:All]).to eq(true)
|
305
|
+
expect(message[:integrations][:Salesforce]).to eq(false)
|
286
306
|
end
|
287
307
|
end
|
288
308
|
end
|