adknowledge 0.0.3
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +114 -0
- data/Rakefile +6 -0
- data/adknowledge.gemspec +33 -0
- data/lib/adknowledge/config.rb +9 -0
- data/lib/adknowledge/integrated.rb +193 -0
- data/lib/adknowledge/performance.rb +255 -0
- data/lib/adknowledge/version.rb +3 -0
- data/lib/adknowledge.rb +9 -0
- data/lib/faraday_middleware/adknowledge.rb +33 -0
- data/spec/adknowledge/integrated_spec.rb +378 -0
- data/spec/adknowledge/performance_spec.rb +320 -0
- data/spec/adknowledge_spec.rb +0 -0
- data/spec/cassettes/map_multi_success.yml +68 -0
- data/spec/cassettes/map_single_success.yml +51 -0
- data/spec/cassettes/performance.yml +41 -0
- data/spec/spec_helper.rb +16 -0
- metadata +284 -0
@@ -0,0 +1,378 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Adknowledge::Integrated do
|
4
|
+
before do
|
5
|
+
Adknowledge.token = '3a9f34d1eee18880bbc74254ddf06448'
|
6
|
+
end
|
7
|
+
|
8
|
+
let :email_hashes do
|
9
|
+
[
|
10
|
+
{ recipient: '004c58927df600d73d58c817bafc2155',
|
11
|
+
list: 9250,
|
12
|
+
domain: 'hotmail.com',
|
13
|
+
countrycode: 'US',
|
14
|
+
state: 'MO'
|
15
|
+
},
|
16
|
+
{ recipient: 'a2a8c7a5ce7c4249663803c7d040401f',
|
17
|
+
list: 9250,
|
18
|
+
domain: 'mail.com',
|
19
|
+
countrycode: 'CA'
|
20
|
+
}
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
let :request_xml do
|
25
|
+
%q[
|
26
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
27
|
+
<request>
|
28
|
+
<email>
|
29
|
+
<recipient>004c58927df600d73d58c817bafc2155</recipient>
|
30
|
+
<list>9250</list>
|
31
|
+
<domain>hotmail.com</domain>
|
32
|
+
<countrycode>US</countrycode>
|
33
|
+
<state>MO</state>
|
34
|
+
</email>
|
35
|
+
<email>
|
36
|
+
<recipient>a2a8c7a5ce7c4249663803c7d040401f</recipient>
|
37
|
+
<list>9250</list>
|
38
|
+
<domain>rr.com</domain>
|
39
|
+
<countrycode>CA</countrycode>
|
40
|
+
</email>
|
41
|
+
</request>].gsub(/\n/, '')
|
42
|
+
end
|
43
|
+
|
44
|
+
let :domain1 do
|
45
|
+
"fga.example.com"
|
46
|
+
end
|
47
|
+
|
48
|
+
let :integrated do
|
49
|
+
described_class.new domain: domain1,
|
50
|
+
subid: 101,
|
51
|
+
test: true,
|
52
|
+
recipients: email_hashes
|
53
|
+
end
|
54
|
+
|
55
|
+
context "#recipients=" do
|
56
|
+
subject do
|
57
|
+
described_class.new
|
58
|
+
end
|
59
|
+
|
60
|
+
context "valid" do
|
61
|
+
|
62
|
+
let :email_hashes do
|
63
|
+
[
|
64
|
+
{ recipient: '004c58927df600d73d58c817bafc2155',
|
65
|
+
list: 9250,
|
66
|
+
domain: 'hotmail.com',
|
67
|
+
countrycode: 'US',
|
68
|
+
state: 'MO'
|
69
|
+
},
|
70
|
+
{ recipient: 'a2a8c7a5ce7c4249663803c7d040401f',
|
71
|
+
list: 9250,
|
72
|
+
domain: 'rr.com',
|
73
|
+
countrycode: 'CA'
|
74
|
+
}
|
75
|
+
]
|
76
|
+
end
|
77
|
+
|
78
|
+
before do
|
79
|
+
subject.recipients = email_hashes
|
80
|
+
end
|
81
|
+
|
82
|
+
it "sets the request" do
|
83
|
+
expect(subject.request).to eql request_xml
|
84
|
+
end
|
85
|
+
|
86
|
+
it "keeps the recipients" do
|
87
|
+
expect(subject.recipients).to eql email_hashes
|
88
|
+
end
|
89
|
+
end # valid
|
90
|
+
|
91
|
+
context "missing mandatory field" do
|
92
|
+
|
93
|
+
let :email_hashes do
|
94
|
+
[
|
95
|
+
{ recipient: '004c58927df600d73d58c817bafc2155',
|
96
|
+
list: 9250
|
97
|
+
},
|
98
|
+
{ recipient: 'a2a8c7a5ce7c4249663803c7d040401f',
|
99
|
+
list: 9250,
|
100
|
+
domain: 'rr.com',
|
101
|
+
countrycode: 'CA'
|
102
|
+
}
|
103
|
+
]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "raises an exception" do
|
107
|
+
expect{
|
108
|
+
subject.recipients = email_hashes
|
109
|
+
}.to raise_error ArgumentError
|
110
|
+
end
|
111
|
+
|
112
|
+
end # missing mandatory field
|
113
|
+
|
114
|
+
end # #recipients=
|
115
|
+
|
116
|
+
context "#query_params" do
|
117
|
+
|
118
|
+
let :domain2 do
|
119
|
+
"fga.examplemail.com"
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with domain option" do
|
123
|
+
|
124
|
+
let :query_params do
|
125
|
+
{ token: "3a9f34d1eee18880bbc74254ddf06448",
|
126
|
+
idomain: domain1,
|
127
|
+
cdomain: domain1,
|
128
|
+
request: request_xml,
|
129
|
+
subid: 101,
|
130
|
+
test: 1
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
subject do
|
135
|
+
integrated.query_params
|
136
|
+
end
|
137
|
+
|
138
|
+
it "has the token" do
|
139
|
+
expect(subject[:token]).to eql "3a9f34d1eee18880bbc74254ddf06448"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "has the idomain" do
|
143
|
+
expect(subject[:idomain]).to eql domain1
|
144
|
+
end
|
145
|
+
|
146
|
+
it "has the cdomain" do
|
147
|
+
expect(subject[:cdomain]).to eql domain1
|
148
|
+
end
|
149
|
+
|
150
|
+
it "has the test option" do
|
151
|
+
expect(subject[:test]).to eql 1
|
152
|
+
end
|
153
|
+
|
154
|
+
it "has the subid" do
|
155
|
+
expect(subject[:subid]).to eql 101
|
156
|
+
end
|
157
|
+
|
158
|
+
end # with domain option
|
159
|
+
|
160
|
+
context "with cdomain/idomian" do
|
161
|
+
|
162
|
+
let :query_params do
|
163
|
+
{ token: "3a9f34d1eee18880bbc74254ddf06448",
|
164
|
+
idomain: domain1,
|
165
|
+
cdomain: domain2,
|
166
|
+
request: request_xml,
|
167
|
+
subid: 102,
|
168
|
+
test: false
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
let :integrated do
|
173
|
+
described_class.new idomain: domain1,
|
174
|
+
cdomain: domain2,
|
175
|
+
subid: 102,
|
176
|
+
test: false,
|
177
|
+
recipients: email_hashes
|
178
|
+
end
|
179
|
+
|
180
|
+
subject do
|
181
|
+
integrated.query_params
|
182
|
+
end
|
183
|
+
|
184
|
+
it "has the cdomain" do
|
185
|
+
expect(subject[:cdomain]).to eql domain2
|
186
|
+
end
|
187
|
+
|
188
|
+
it "has the idomain" do
|
189
|
+
expect(subject[:idomain]).to eql domain1
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end # #query_params
|
195
|
+
|
196
|
+
context "before map" do
|
197
|
+
|
198
|
+
context "#mapped?" do
|
199
|
+
|
200
|
+
subject do
|
201
|
+
integrated.mapped?
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should be false" do
|
205
|
+
expect(subject).to be_false
|
206
|
+
end
|
207
|
+
|
208
|
+
end # #mapped?
|
209
|
+
|
210
|
+
context "#mapped_recipients" do
|
211
|
+
|
212
|
+
subject do
|
213
|
+
integrated.mapped_recipients
|
214
|
+
end
|
215
|
+
|
216
|
+
it "has no mapped recipients" do
|
217
|
+
expect(subject).to be_empty
|
218
|
+
end
|
219
|
+
|
220
|
+
end # #mapped_recipients
|
221
|
+
|
222
|
+
context "#errored_recipients" do
|
223
|
+
|
224
|
+
subject do
|
225
|
+
integrated.errored_recipients
|
226
|
+
end
|
227
|
+
|
228
|
+
it "has no errored recipients" do
|
229
|
+
expect(subject).to be_empty
|
230
|
+
end
|
231
|
+
|
232
|
+
end # #errored_recipients
|
233
|
+
|
234
|
+
end # before map
|
235
|
+
|
236
|
+
context "after map" do
|
237
|
+
|
238
|
+
context "single results" do
|
239
|
+
|
240
|
+
before do
|
241
|
+
VCR.use_cassette :map_single_success, record: :once do
|
242
|
+
integrated.map!
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "#mapped?" do
|
247
|
+
|
248
|
+
subject do
|
249
|
+
integrated.mapped?
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should be true" do
|
253
|
+
expect(subject).to be_true
|
254
|
+
end
|
255
|
+
|
256
|
+
end # #mapped?
|
257
|
+
|
258
|
+
context "#mapped_recipients" do
|
259
|
+
|
260
|
+
subject do
|
261
|
+
integrated.mapped_recipients
|
262
|
+
end
|
263
|
+
|
264
|
+
it "has a mapped recipient" do
|
265
|
+
expect(subject.size).to eql 1
|
266
|
+
end
|
267
|
+
|
268
|
+
it "has a creative" do
|
269
|
+
expect(subject.first['creative']).to be_a Hash
|
270
|
+
expect(subject.first['creative']['body']).to be_a String
|
271
|
+
expect(subject.first['creative']['subject']).to eql "Faxes delivered to your email."
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context "#errored_recipients" do
|
276
|
+
|
277
|
+
subject do
|
278
|
+
integrated.errored_recipients
|
279
|
+
end
|
280
|
+
|
281
|
+
it "has an errored recipient" do
|
282
|
+
expect(subject.size).to eql 1
|
283
|
+
end
|
284
|
+
|
285
|
+
it "has an error error" do
|
286
|
+
expect(subject.first['error']).to be_a Hash
|
287
|
+
expect(subject.first['error']['num']).to eql "10"
|
288
|
+
expect(subject.first['error']['str']).to eql "Domain is suppressed\n"
|
289
|
+
end
|
290
|
+
|
291
|
+
end # #errored_recipients
|
292
|
+
|
293
|
+
end # single results
|
294
|
+
|
295
|
+
context "multiple results" do
|
296
|
+
|
297
|
+
let :email_hashes do
|
298
|
+
[
|
299
|
+
{ recipient: '004c58927df600d73d58c817bafc2155',
|
300
|
+
list: 9250,
|
301
|
+
domain: 'hotmail.com',
|
302
|
+
countrycode: 'US',
|
303
|
+
state: 'MO'
|
304
|
+
},
|
305
|
+
{ recipient: '004c58927df600d73d58c817bafc2156',
|
306
|
+
list: 9250,
|
307
|
+
domain: 'aol.com'
|
308
|
+
},
|
309
|
+
{ recipient: 'a2a8c7a5ce7c4249663803c7d040401f',
|
310
|
+
list: 9250,
|
311
|
+
domain: 'mail.com',
|
312
|
+
countrycode: 'CA'
|
313
|
+
},
|
314
|
+
{ recipient: 'a2a8c7a5ce7c4249663803c7d040401e',
|
315
|
+
list: 9250,
|
316
|
+
domain: 'mail.com'
|
317
|
+
}
|
318
|
+
]
|
319
|
+
end
|
320
|
+
|
321
|
+
before do
|
322
|
+
VCR.use_cassette :map_multi_success, record: :once do
|
323
|
+
integrated.map!
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context "#mapped?" do
|
328
|
+
|
329
|
+
subject do
|
330
|
+
integrated.mapped?
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should be true" do
|
334
|
+
expect(subject).to be_true
|
335
|
+
end
|
336
|
+
|
337
|
+
end # #mapped?
|
338
|
+
|
339
|
+
context "#mapped_recipients" do
|
340
|
+
|
341
|
+
subject do
|
342
|
+
integrated.mapped_recipients
|
343
|
+
end
|
344
|
+
|
345
|
+
it "has a mapped recipient" do
|
346
|
+
expect(subject.size).to eql 2
|
347
|
+
end
|
348
|
+
|
349
|
+
it "has a creative" do
|
350
|
+
expect(subject.first['creative']).to be_a Hash
|
351
|
+
expect(subject.first['creative']['body']).to be_a String
|
352
|
+
expect(subject.first['creative']['subject']).to eql "Early-bird cruise specials"
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
context "#errored_recipients" do
|
357
|
+
|
358
|
+
subject do
|
359
|
+
integrated.errored_recipients
|
360
|
+
end
|
361
|
+
|
362
|
+
it "has an errored recipient" do
|
363
|
+
expect(subject.size).to eql 2
|
364
|
+
end
|
365
|
+
|
366
|
+
it "has an error error" do
|
367
|
+
expect(subject.first['error']).to be_a Hash
|
368
|
+
expect(subject.first['error']['num']).to eql "10"
|
369
|
+
expect(subject.first['error']['str']).to eql "Domain is suppressed\n"
|
370
|
+
end
|
371
|
+
|
372
|
+
end # #errored_recipients
|
373
|
+
|
374
|
+
end # multiple results
|
375
|
+
|
376
|
+
end # after map
|
377
|
+
|
378
|
+
end # Adknowledge::Integrated
|
@@ -0,0 +1,320 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Adknowledge::Performance do
|
4
|
+
before do
|
5
|
+
Adknowledge.token = 'b6d8610998e883b3a460fd2fcf71ead4'
|
6
|
+
end
|
7
|
+
|
8
|
+
context '#select' do
|
9
|
+
it 'changes metric selection' do
|
10
|
+
expect{
|
11
|
+
subject.select(:revenue)
|
12
|
+
}.to change(subject, :measures).
|
13
|
+
from({}).
|
14
|
+
to({revenue:1})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'supports multiple selections' do
|
18
|
+
expect{
|
19
|
+
subject.select(:revenue, :paid_clicks)
|
20
|
+
}.to change(subject, :measures).
|
21
|
+
from({}).
|
22
|
+
to({revenue:1, paid_clicks:1})
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'supports chained selections' do
|
26
|
+
subject.select(:revenue)
|
27
|
+
expect{
|
28
|
+
subject.select(:paid_clicks)
|
29
|
+
}.to change(subject, :measures).
|
30
|
+
from({revenue:1}).
|
31
|
+
to({revenue:1, paid_clicks:1})
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'errors on invalid measure' do
|
35
|
+
expect{ subject.select(:unvalid) }.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
end # #select
|
38
|
+
|
39
|
+
context '#group_by' do
|
40
|
+
it 'changes the dimension groupings' do
|
41
|
+
expect{
|
42
|
+
subject.group_by(:subid)
|
43
|
+
}.to change(subject, :dimensions).
|
44
|
+
from({}).
|
45
|
+
to({subid:1})
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'supports multiple groupings' do
|
49
|
+
expect{
|
50
|
+
subject.group_by(:report_date, :revenue_type)
|
51
|
+
}.to change(subject, :dimensions).
|
52
|
+
from({}).
|
53
|
+
to({report_date:1, revenue_type:1})
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'supports chained groupings' do
|
57
|
+
subject.group_by(:report_date)
|
58
|
+
expect{
|
59
|
+
subject.group_by(:revenue_type)
|
60
|
+
}.to change(subject, :dimensions).
|
61
|
+
from({report_date:1}).
|
62
|
+
to({report_date:1, revenue_type:1})
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'errors on invalid dimension' do
|
66
|
+
expect{ subject.select(:inpossible) }.to raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
end # #group_by
|
69
|
+
|
70
|
+
context '#where' do
|
71
|
+
it 'changes the filter criteria' do
|
72
|
+
expect{
|
73
|
+
subject.where(start_date:0)
|
74
|
+
}.to change(subject, :filter).
|
75
|
+
from({product_guid: '*', product_id: '2'}).
|
76
|
+
to({product_guid: '*', product_id: '2', start_date:'0'})
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'supports chained filtering' do
|
80
|
+
subject.where(start_date:0)
|
81
|
+
expect{
|
82
|
+
subject.where(domain_group:'AOL Group')
|
83
|
+
}.to change(subject, :filter).
|
84
|
+
from({product_guid: '*', product_id: '2', start_date:'0'}).
|
85
|
+
to({product_guid: '*', product_id: '2', start_date:'0', domain_group:'AOL Group'})
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'errors on invalid filter' do
|
89
|
+
expect{ subject.where(revenue:0) }.to raise_error(ArgumentError)
|
90
|
+
end
|
91
|
+
end # #where
|
92
|
+
|
93
|
+
context '#limit' do
|
94
|
+
it 'sets the limit option' do
|
95
|
+
expect{
|
96
|
+
subject.limit(10)
|
97
|
+
}.to change(subject, :options).
|
98
|
+
from({}).
|
99
|
+
to({limit:"10"})
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'supports chaining' do
|
103
|
+
expect(
|
104
|
+
subject.limit(10)
|
105
|
+
).to be_a Adknowledge::Performance
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'errors on invalid limit' do
|
109
|
+
expect{ subject.limit(:test) }.to raise_error(ArgumentError)
|
110
|
+
end
|
111
|
+
end # #limit
|
112
|
+
|
113
|
+
context '#sort' do
|
114
|
+
it 'sets the sort option' do
|
115
|
+
expect{
|
116
|
+
subject.sort(3)
|
117
|
+
}.to change(subject, :sort_option).
|
118
|
+
from(nil).
|
119
|
+
to("3")
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'supports chaining' do
|
123
|
+
expect(
|
124
|
+
subject.sort(5)
|
125
|
+
).to be_a Adknowledge::Performance
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'errors on invalid sort' do
|
129
|
+
expect{ subject.limit('test') }.to raise_error(ArgumentError)
|
130
|
+
end
|
131
|
+
end # #sort
|
132
|
+
|
133
|
+
context '#full' do
|
134
|
+
it 'sets the full option' do
|
135
|
+
expect{
|
136
|
+
subject.full(true)
|
137
|
+
}.to change(subject, :options).
|
138
|
+
from({}).
|
139
|
+
to({full:"1"})
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'supports chaining' do
|
143
|
+
expect(
|
144
|
+
subject.full(false)
|
145
|
+
).to be_a Adknowledge::Performance
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'errors on invalid full' do
|
149
|
+
expect{ subject.full('test') }.to raise_error(ArgumentError)
|
150
|
+
end
|
151
|
+
end # #full
|
152
|
+
|
153
|
+
context '#nocache' do
|
154
|
+
it 'sets the nocache option' do
|
155
|
+
expect{
|
156
|
+
subject.nocache(true)
|
157
|
+
}.to change(subject, :options).
|
158
|
+
from({}).
|
159
|
+
to({nocache:"1"})
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'supports chaining' do
|
163
|
+
expect(
|
164
|
+
subject.nocache(false)
|
165
|
+
).to be_a Adknowledge::Performance
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'errors on invalid nocache' do
|
169
|
+
expect{ subject.nocache('test') }.to raise_error(ArgumentError)
|
170
|
+
end
|
171
|
+
end # #nocache
|
172
|
+
|
173
|
+
context '#display_all' do
|
174
|
+
it 'sets the display_all option' do
|
175
|
+
expect{
|
176
|
+
subject.display_all(true)
|
177
|
+
}.to change(subject, :options).
|
178
|
+
from({}).
|
179
|
+
to({all:"1"})
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'supports chaining' do
|
183
|
+
expect(
|
184
|
+
subject.display_all(false)
|
185
|
+
).to be_a Adknowledge::Performance
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'errors on invalid display_all' do
|
189
|
+
expect{ subject.display_all('test') }.to raise_error(ArgumentError)
|
190
|
+
end
|
191
|
+
end # #display_all
|
192
|
+
|
193
|
+
context '#pivot' do
|
194
|
+
before do
|
195
|
+
subject.group_by :country_cd
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'sets a basic pivot' do
|
199
|
+
expect{
|
200
|
+
subject.pivot :country_cd
|
201
|
+
}.to change(subject, :pivot_options).
|
202
|
+
from({}).
|
203
|
+
to({pivot: "country_cd"})
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'only allows a single basic pivot' do
|
207
|
+
expect{ subject.pivot(:one, :two) }.to raise_error(ArgumentError)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'only allows grouped dimensions to be pivoted on' do
|
211
|
+
expect{ subject.pivot(:report_date) }.to raise_error(ArgumentError)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'sets a sum pivot' do
|
215
|
+
subject.group_by :country_cd
|
216
|
+
expect{
|
217
|
+
subject.pivot(sum: :revenue)
|
218
|
+
}.to change(subject, :pivot_options).
|
219
|
+
from({}).
|
220
|
+
to({sum: :revenue})
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'only allows measurements to be summed' do
|
224
|
+
expect{ subject.pivot(sum: :ilresponsible) }.to raise_error(ArgumentError)
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'replaces a previous pivot' do
|
228
|
+
subject.pivot :country_cd
|
229
|
+
expect{
|
230
|
+
subject.pivot(sum: :paid_clicks)
|
231
|
+
}.to change(subject, :pivot_options).
|
232
|
+
from({pivot: "country_cd"}).
|
233
|
+
to({sum: :paid_clicks})
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'only allows "sum "or "count"' do
|
237
|
+
expect{ subject.pivot unlogical: :paid_clicks }.to raise_error(ArgumentError)
|
238
|
+
end
|
239
|
+
end # #pivot
|
240
|
+
|
241
|
+
context '#query_params' do
|
242
|
+
|
243
|
+
let :performance do
|
244
|
+
described_class.new.where(start_date:1).
|
245
|
+
select(:revenue,:paid_clicks).
|
246
|
+
where(domain_group: 'AOL Group').
|
247
|
+
group_by(:subid, :report_date).
|
248
|
+
pivot(:report_date).
|
249
|
+
nocache(true).
|
250
|
+
display_all(true).
|
251
|
+
full(true).
|
252
|
+
sort(2).
|
253
|
+
limit(20)
|
254
|
+
end
|
255
|
+
|
256
|
+
let :query_params do
|
257
|
+
{ token:'b6d8610998e883b3a460fd2fcf71ead4',
|
258
|
+
start_date:'1',
|
259
|
+
measures:'revenue,paid_clicks',
|
260
|
+
domain_group: 'AOL Group',
|
261
|
+
dimensions:'subid,report_date',
|
262
|
+
product_guid: '*',
|
263
|
+
pivot: 'report_date',
|
264
|
+
product_id: '2',
|
265
|
+
nocache:'1',
|
266
|
+
full:'1',
|
267
|
+
sort:'2',
|
268
|
+
all:'1',
|
269
|
+
limit:'20'
|
270
|
+
}
|
271
|
+
end
|
272
|
+
|
273
|
+
subject do
|
274
|
+
performance.query_params
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'creates query_params' do
|
278
|
+
expect(subject).to eql(query_params)
|
279
|
+
end
|
280
|
+
end # #query_params
|
281
|
+
|
282
|
+
context '#records' do
|
283
|
+
|
284
|
+
let :performance do
|
285
|
+
described_class.new.where(start_date:1).
|
286
|
+
select(:revenue,:paid_clicks).
|
287
|
+
group_by(:subid, :report_date).
|
288
|
+
limit(20)
|
289
|
+
end
|
290
|
+
|
291
|
+
before do
|
292
|
+
VCR.use_cassette :performance, record: :once do
|
293
|
+
performance.records
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
subject do
|
298
|
+
performance.records
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'has results' do
|
302
|
+
expect(subject).to be_an Array
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'has the correct dimensions' do
|
306
|
+
expect(subject.first).to have_key 'subid'
|
307
|
+
expect(subject.first).to have_key 'report_date'
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'has the correct measures' do
|
311
|
+
expect(subject.first).to have_key 'paid_clicks'
|
312
|
+
expect(subject.first).to have_key 'revenue'
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'has the correct count' do
|
316
|
+
expect(subject.size).to eql 20
|
317
|
+
end
|
318
|
+
|
319
|
+
end
|
320
|
+
end
|
File without changes
|