legato 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 304acd2f0f716bf682b425bea037c4445afc97fd
4
- data.tar.gz: 4443a2410d7c782ae282bd4913ae5f5e6730cadd
3
+ metadata.gz: b9077eb3bf7200ccae8aaa176ae3199c983501ca
4
+ data.tar.gz: efd2b61790708f18b5be1bf612ae3267b99de0bd
5
5
  SHA512:
6
- metadata.gz: d978c8ac87bcab86a9ac8003b7afb18735f8f7281203bb186f23d0cc773a33b2ac1cd5750f502ad1ed0490a47189c6311d63f5e09f005452614dc69a750ac501
7
- data.tar.gz: c1d37f5c5b819ae0c14fc7a88b486165c5ad000d1762550ee8e12a15cbe63d36668c7fc69b743dcc22cda394a3cf76862ba651db1f522849a7e0e7749bb02b8c
6
+ metadata.gz: d90896b83ec99911d48a493cd990c731f5a6e05a11551162510ac2956339c343a0262730e065dddcc0690fbcefcdd024a8228c45e4c146c6055d85ba481ce0c0
7
+ data.tar.gz: 88fd641061a3b056833dba164ee8c7b22a9318c9b6fd922b687626f82f6f26da61c8cf85237ebb4f941200edba58b1f1eda96221f3028c4934744719dc978c7a
@@ -1,3 +1,9 @@
1
+ ## Legato 0.6.1 ##
2
+
3
+ * Fix bug in `Query` where calling `results` did not retain previous basic options
4
+
5
+ *Tony Pitale*
6
+
1
7
  ## Legato 0.6.0 ##
2
8
 
3
9
  * Fix bug in `Query` where calling `results` after loading a collection would not load new data into the collection
@@ -5,6 +5,11 @@ module Legato
5
5
  MONTH = 2592000
6
6
  REQUEST_FIELDS = 'columnHeaders/name,rows,totalResults,totalsForAllResults'
7
7
 
8
+ BASIC_OPTION_KEYS = [
9
+ :sort, :limit, :offset, :start_date, :end_date, :quota_user,
10
+ :user_ip, :sampling_level, :segment_id
11
+ ]
12
+
8
13
  VALID_TRACKING_SCOPES = {
9
14
  'ga' => 'ga',
10
15
  'mcf' => 'mcf',
@@ -101,11 +106,16 @@ module Legato
101
106
  end
102
107
 
103
108
  def apply_basic_options(options)
104
- [:sort, :limit, :offset, :start_date, :end_date, :quota_user, :user_ip, :sampling_level, :segment_id].each do |key| #:segment
109
+ BASIC_OPTION_KEYS.each do |key| #:segment
105
110
  self.send("#{key}=".to_sym, options[key]) if options.has_key?(key)
106
111
  end
107
112
  end
108
113
 
114
+ # return a hash of basic options to merge
115
+ def basic_options
116
+ Hash[BASIC_OPTION_KEYS.map { |k| [k, send(k)] }].reject {|_,v| v.nil?}
117
+ end
118
+
109
119
  # def apply_filter_options(filter_options)
110
120
  # join_character = Legato.and_join_character
111
121
  #
@@ -173,7 +183,7 @@ module Legato
173
183
  options, profile = profile, self.profile if profile.is_a?(Hash)
174
184
 
175
185
  query.profile = profile
176
- query.apply_options(options)
186
+ query.apply_options(self.basic_options.merge(options))
177
187
  query
178
188
  end
179
189
 
@@ -1,3 +1,3 @@
1
1
  module Legato
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -16,149 +16,154 @@ describe Legato::Query do
16
16
  end
17
17
 
18
18
  context "a query" do
19
+ let(:klass) { Class.new.tap { |k| k.extend(Legato::Model)} }
20
+ let(:query) { Legato::Query.new(klass) }
21
+
22
+ let(:default_options) { {:start_date => query.start_date, :end_date => query.end_date} }
23
+
19
24
  before :each do
20
- @klass = Class.new
21
- @klass.extend(Legato::Model)
22
- @block = lambda {eql(:key, 1000)}
25
+ @klass = klass
23
26
  @klass.stubs(:filters).returns({:high => @block})
24
27
  @klass.stubs(:segments).returns([])
25
28
 
26
- @query = Legato::Query.new(@klass)
29
+ @block = lambda {eql(:key, 1000)}
30
+
31
+ @query = query
27
32
  end
28
33
 
29
34
  it 'knows the parent class' do
30
- @query.parent_klass.should == @klass
35
+ query.parent_klass.should == @klass
31
36
  end
32
37
 
33
38
  it 'defaults to an empty filter set' do
34
- @query.filters.to_params.should == Legato::FilterSet.new.to_params
39
+ query.filters.to_params.should == Legato::FilterSet.new.to_params
35
40
  end
36
41
 
37
42
  it 'has filters defined from the parent class' do
38
- @query.respond_to?(:high).should eq(true)
43
+ query.respond_to?(:high).should eq(true)
39
44
  end
40
45
 
41
46
  it "has filter methods that call apply with the given block" do
42
- @query.stubs(:apply_filter)
43
- @query.high('hi')
44
- @query.should have_received(:apply_filter).with('hi')
47
+ query.stubs(:apply_filter)
48
+ query.high('hi')
49
+ query.should have_received(:apply_filter).with('hi')
45
50
  end
46
51
 
47
52
  it 'does not load results by default' do
48
- @query.loaded?.should == false
53
+ query.loaded?.should == false
49
54
  end
50
55
 
51
56
  it 'delegates the instance klass from the parent klass' do
52
57
  klass = Class.new
53
- @query.parent_klass.stubs(:instance_klass).returns(klass)
54
- @query.instance_klass.should == klass
58
+ query.parent_klass.stubs(:instance_klass).returns(klass)
59
+ query.instance_klass.should == klass
55
60
  end
56
61
 
57
62
  it "loads a collection of results" do
58
63
  response = stub(:collection => [], :total_results => 0, :totals_for_all_results => {})
59
64
  user = stub(:request => response)
60
- @query.stubs(:profile => stub(:user => user))
65
+ query.stubs(:profile => stub(:user => user))
61
66
 
62
- @query.load
67
+ query.load
63
68
 
64
- @query.loaded?.should eq(true)
65
- @query.profile.user.should have_received(:request).with(@query)
69
+ query.loaded?.should eq(true)
70
+ query.profile.user.should have_received(:request).with(query)
66
71
  response.should have_received(:collection)
67
72
  response.should have_received(:total_results)
68
73
  response.should have_received(:totals_for_all_results)
69
74
  end
70
75
 
71
76
  it "returns the collection" do
72
- @query.stubs(:request_for_query).returns(stub(:collection => [1,2,3], :total_results => 3, :totals_for_all_results => {'foo' => 34.2}))
73
- @query.load
74
- @query.collection.should == [1,2,3]
75
- @query.to_a.should == [1,2,3]
77
+ query.stubs(:request_for_query).returns(stub(:collection => [1,2,3], :total_results => 3, :totals_for_all_results => {'foo' => 34.2}))
78
+ query.load
79
+ query.collection.should == [1,2,3]
80
+ query.to_a.should == [1,2,3]
76
81
  end
77
82
 
78
83
  it "returns the total number of results" do
79
- @query.stubs(:request_for_query).returns(stub(:collection => [1,2,3], :total_results => 3, :totals_for_all_results => {'foo' => 34.2}))
80
- @query.load
81
- @query.total_results.should == 3
84
+ query.stubs(:request_for_query).returns(stub(:collection => [1,2,3], :total_results => 3, :totals_for_all_results => {'foo' => 34.2}))
85
+ query.load
86
+ query.total_results.should == 3
82
87
  end
83
88
 
84
89
  it "returns the totals for all results" do
85
- @query.stubs(:request_for_query).returns(stub(:collection => [1,2,3], :total_results => 3, :totals_for_all_results => {'foo' => 34.2}))
86
- @query.load
87
- @query.totals_for_all_results.should == {'foo' => 34.2}
90
+ query.stubs(:request_for_query).returns(stub(:collection => [1,2,3], :total_results => 3, :totals_for_all_results => {'foo' => 34.2}))
91
+ query.load
92
+ query.totals_for_all_results.should == {'foo' => 34.2}
88
93
  end
89
94
 
90
95
  it "behaves like an enumerable delegating to the collection" do
91
96
  collection = []
92
97
  collection.stubs(:each)
93
- @query.stubs(:collection).returns(collection)
94
- @query.stubs(:loaded?).returns(true)
98
+ query.stubs(:collection).returns(collection)
99
+ query.stubs(:loaded?).returns(true)
95
100
 
96
- @query.each {}
101
+ query.each {}
97
102
 
98
103
  collection.should have_received(:each)
99
104
  end
100
105
 
101
106
  it 'has a profile id after being given a profile' do
102
107
  profile = stub(:id => '1234567890')
103
- @query.stubs(:profile).returns(profile)
108
+ query.stubs(:profile).returns(profile)
104
109
 
105
- @query.profile_id.should == 'ga:1234567890'
110
+ query.profile_id.should == 'ga:1234567890'
106
111
 
107
112
  profile.should have_received(:id)
108
113
  end
109
114
 
110
115
  it 'has no profile id by default' do
111
- @query.stubs(:profile).returns(nil)
112
- @query.profile_id.should be_nil
116
+ query.stubs(:profile).returns(nil)
117
+ query.profile_id.should be_nil
113
118
  end
114
119
 
115
120
  it 'sets the profile and applies options, returns itself' do
116
- @query.stubs(:profile=)
117
- @query.stubs(:apply_options)
121
+ query.stubs(:profile=)
122
+ query.stubs(:apply_options)
118
123
 
119
- @query.results('profile').should == @query
124
+ query.results('profile').should == query
120
125
 
121
- @query.should have_received(:profile=).with('profile')
122
- @query.should have_received(:apply_options).with({})
126
+ query.should have_received(:profile=).with('profile')
127
+ query.should have_received(:apply_options).with(default_options)
123
128
  end
124
129
 
125
130
  it 'sets options and returns self' do
126
- profile = @query.profile
127
- @query.stubs(:profile=)
128
- @query.stubs(:apply_options)
131
+ profile = query.profile
132
+ query.stubs(:profile=)
133
+ query.stubs(:apply_options)
129
134
 
130
- @query.results({:sort => [:city]}).should == @query
135
+ query.results({:sort => [:city]}).should == query
131
136
 
132
- @query.should have_received(:profile=).with(profile)
133
- @query.should have_received(:apply_options).with({:sort => [:city]})
137
+ query.should have_received(:profile=).with(profile)
138
+ query.should have_received(:apply_options).with(default_options.merge({:sort => [:city]}))
134
139
  end
135
140
 
136
141
  it 'creates a new query if collection has already been loaded' do
137
- @query.stubs(:loaded?).returns(true)
142
+ query.stubs(:loaded?).returns(true)
138
143
 
139
- new_query = @query.results({offset: 10_000})
144
+ new_query = query.results({offset: 10_000})
140
145
 
141
- expect(new_query).to_not eql(@query)
146
+ expect(new_query).to_not eql(query)
142
147
  expect(new_query.offset).to eql(10_000)
143
148
  end
144
149
 
145
150
  context "when modifying dimensions" do
146
151
  it 'changes the query dimensions' do
147
- @query.dimensions << :city
148
- @query.dimensions.include?(:city).should eq(true)
152
+ query.dimensions << :city
153
+ query.dimensions.include?(:city).should eq(true)
149
154
  end
150
155
 
151
156
  it 'does not change the parent class dimensions' do
152
157
  empty_dimensions = Legato::ListParameter.new(:dimensions, [])
153
158
 
154
- @query.dimensions << :city
159
+ query.dimensions << :city
155
160
  @klass.dimensions.should eq(empty_dimensions)
156
161
  end
157
162
 
158
163
  it 'accepts an array of dimensions' do
159
- @query.dimensions << [:city, :browser]
160
- @query.dimensions.include?(:city).should eq(true)
161
- @query.dimensions.include?(:browser).should eq(true)
164
+ query.dimensions << [:city, :browser]
165
+ query.dimensions.include?(:city).should eq(true)
166
+ query.dimensions.include?(:browser).should eq(true)
162
167
  end
163
168
 
164
169
  it 'does not share metrics across queries' do
@@ -172,21 +177,21 @@ describe Legato::Query do
172
177
 
173
178
  context "when modifying metrics" do
174
179
  it 'changes the query metrics' do
175
- @query.metrics << :pageviews
176
- @query.metrics.include?(:pageviews).should eq(true)
180
+ query.metrics << :pageviews
181
+ query.metrics.include?(:pageviews).should eq(true)
177
182
  end
178
183
 
179
184
  it 'does not change the parent class metrics' do
180
185
  empty_metrics = Legato::ListParameter.new(:metrics, [])
181
186
 
182
- @query.metrics << :pageviews
187
+ query.metrics << :pageviews
183
188
  @klass.metrics.should eq(empty_metrics)
184
189
  end
185
190
 
186
191
  it 'accepts an array of metrics' do
187
- @query.metrics << [:pageviews, :sessions]
188
- @query.metrics.include?(:pageviews).should eq(true)
189
- @query.metrics.include?(:sessions).should eq(true)
192
+ query.metrics << [:pageviews, :sessions]
193
+ query.metrics.include?(:pageviews).should eq(true)
194
+ query.metrics.include?(:sessions).should eq(true)
190
195
  end
191
196
 
192
197
  it 'does not share metrics across queries' do
@@ -201,45 +206,45 @@ describe Legato::Query do
201
206
  context 'when applying filters' do
202
207
  before :each do
203
208
  @filter = Legato::Filter.new(:key, :eql, 1000, nil)
204
- @query.stubs(:eql).returns(@filter)
209
+ query.stubs(:eql).returns(@filter)
205
210
 
206
211
  @filters = stub(:<<)
207
- @query.stubs(:filters).returns(@filters)
212
+ query.stubs(:filters).returns(@filters)
208
213
  end
209
214
 
210
215
  it 'returns the query' do
211
- @query.apply_filter(&@block).should == @query
216
+ query.apply_filter(&@block).should == query
212
217
  end
213
218
 
214
219
  it 'executes the block' do
215
- @query.apply_filter(&@block)
216
- @query.should have_received(:eql).with(:key, 1000)
220
+ query.apply_filter(&@block)
221
+ query.should have_received(:eql).with(:key, 1000)
217
222
  end
218
223
 
219
224
  it 'accepts a profile as the first argument' do
220
225
  profile = Legato::Management::Profile.new({}, stub)
221
- @query.apply_filter(profile, &@block)
222
- @query.should have_received(:eql)
223
- @query.profile.should == profile
226
+ query.apply_filter(profile, &@block)
227
+ query.should have_received(:eql)
228
+ query.profile.should == profile
224
229
  end
225
230
 
226
231
  it 'accepts a profile as the last argument' do
227
232
  profile = Legato::Management::Profile.new({}, stub)
228
233
  block_with_arg = lambda {|count| eql(:key, count)}
229
- @query.apply_filter(100, profile, &block_with_arg)
230
- @query.should have_received(:eql).with(:key, 100)
231
- @query.profile.should == profile
234
+ query.apply_filter(100, profile, &block_with_arg)
235
+ query.should have_received(:eql).with(:key, 100)
236
+ query.profile.should == profile
232
237
  end
233
238
 
234
239
  it 'does not override the existing profile if none is provide' do
235
- @query.profile = Legato::Management::Profile.new({}, stub)
240
+ query.profile = Legato::Management::Profile.new({}, stub)
236
241
  block_with_arg = lambda {|count| eql(:key, count)}
237
- @query.apply_filter(100, &block_with_arg)
238
- @query.profile.should_not == nil
242
+ query.apply_filter(100, &block_with_arg)
243
+ query.profile.should_not == nil
239
244
  end
240
245
 
241
246
  it 'adds to the filter set' do
242
- @query.apply_filter(&@block)
247
+ query.apply_filter(&@block)
243
248
 
244
249
  @filters.should have_received(:<<).with(@filter)
245
250
  end
@@ -248,7 +253,7 @@ describe Legato::Query do
248
253
  block = lambda {|*browsers| browsers.map {|browser| eql(:browser, browser)}}
249
254
  @filter.stubs(:join_character=)
250
255
 
251
- @query.apply_filter('chrome', 'safari', &block)
256
+ query.apply_filter('chrome', 'safari', &block)
252
257
 
253
258
  @filter.should have_received(:join_character=).with(Legato.and_join_character)
254
259
  @filter.should have_received(:join_character=).with(Legato.or_join_character)
@@ -257,86 +262,86 @@ describe Legato::Query do
257
262
 
258
263
  context "when applying options" do
259
264
  it "returns the query" do
260
- @query.apply_options({}).should == @query
265
+ query.apply_options({}).should == query
261
266
  end
262
267
 
263
268
  it "stores the sort" do
264
- @query.apply_options({:sort => [:page_path]})
265
- @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
269
+ query.apply_options({:sort => [:page_path]})
270
+ query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
266
271
  end
267
272
 
268
273
  it 'replaces the sort' do
269
- @query.sort = [:pageviews]
270
- @query.apply_options({:sort => [:page_path]})
271
- @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
274
+ query.sort = [:pageviews]
275
+ query.apply_options({:sort => [:page_path]})
276
+ query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
272
277
  end
273
278
 
274
279
  it "does not replace sort if option is omitted" do
275
- @query.sort = [:pageviews]
276
- @query.apply_options({})
277
- @query.sort.should == Legato::ListParameter.new(:sort, [:pageviews])
280
+ query.sort = [:pageviews]
281
+ query.apply_options({})
282
+ query.sort.should == Legato::ListParameter.new(:sort, [:pageviews])
278
283
  end
279
284
 
280
285
  it "moves :sort option into sort" do
281
- @query.apply_options({:sort => [:page_path]})
282
- @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
286
+ query.apply_options({:sort => [:page_path]})
287
+ query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
283
288
  end
284
289
 
285
290
  it "sets the limit" do
286
- @query.apply_options({:limit => 100})
287
- @query.limit.should == 100
291
+ query.apply_options({:limit => 100})
292
+ query.limit.should == 100
288
293
  end
289
294
 
290
295
  it "replaces the limit" do
291
- @query.limit = 200
292
- @query.apply_options({:limit => 100})
293
- @query.limit.should == 100
296
+ query.limit = 200
297
+ query.apply_options({:limit => 100})
298
+ query.limit.should == 100
294
299
  end
295
300
 
296
301
  it "does not replace the limit if option is omitted" do
297
- @query.limit = 200
298
- @query.apply_options({})
299
- @query.limit.should == 200
302
+ query.limit = 200
303
+ query.apply_options({})
304
+ query.limit.should == 200
300
305
  end
301
306
 
302
307
  it "sets the offset" do
303
- @query.apply_options({:offset => 100})
304
- @query.offset.should == 100
308
+ query.apply_options({:offset => 100})
309
+ query.offset.should == 100
305
310
  end
306
311
 
307
312
  it "replaces the offset" do
308
- @query.offset = 200
309
- @query.apply_options({:offset => 100})
310
- @query.offset.should == 100
313
+ query.offset = 200
314
+ query.apply_options({:offset => 100})
315
+ query.offset.should == 100
311
316
  end
312
317
 
313
318
  it "does not replace offset if option is omitted" do
314
- @query.offset = 200
315
- @query.apply_options({})
316
- @query.offset.should == 200
319
+ query.offset = 200
320
+ query.apply_options({})
321
+ query.offset.should == 200
317
322
  end
318
323
 
319
324
  it "sets the quota_user" do
320
- @query.apply_options({:quota_user => 'an id'})
321
- @query.quota_user.should == 'an id'
325
+ query.apply_options({:quota_user => 'an id'})
326
+ query.quota_user.should == 'an id'
322
327
  end
323
328
 
324
329
  it "replaces the quota_user" do
325
- @query.quota_user = 'an id'
326
- @query.apply_options({:quota_user => 'a different id'})
327
- @query.quota_user.should == 'a different id'
330
+ query.quota_user = 'an id'
331
+ query.apply_options({:quota_user => 'a different id'})
332
+ query.quota_user.should == 'a different id'
328
333
  end
329
334
 
330
335
  it "does not replace quota_user if option is omitted" do
331
- @query.quota_user = 'an id'
332
- @query.apply_options({})
333
- @query.quota_user.should == 'an id'
336
+ query.quota_user = 'an id'
337
+ query.apply_options({})
338
+ query.quota_user.should == 'an id'
334
339
  end
335
340
 
336
341
  it "sets the segment_id" do
337
342
  segment_id = '123122534'
338
- @query.apply_options({:segment_id => segment_id})
339
- @query.segment_id.should == "gaid::#{segment_id}"
343
+ query.apply_options({:segment_id => segment_id})
344
+ query.segment_id.should == "gaid::#{segment_id}"
340
345
  end
341
346
 
342
347
  context "with Time" do
@@ -349,46 +354,46 @@ describe Legato::Query do
349
354
  end
350
355
 
351
356
  it "replaces the start date" do
352
- @query.apply_options({:start_date => (@now-2000)})
353
- @query.start_date.should == (@now-2000)
357
+ query.apply_options({:start_date => (@now-2000)})
358
+ query.start_date.should == (@now-2000)
354
359
  end
355
360
 
356
361
  it "does not replace the start date if option is omitted" do
357
- @query.apply_options({})
358
- Legato.format_time(@query.start_date).should == Legato.format_time(@now-Legato::Query::MONTH)
362
+ query.apply_options({})
363
+ Legato.format_time(query.start_date).should == Legato.format_time(@now-Legato::Query::MONTH)
359
364
  end
360
365
 
361
366
  it "replaces the end date" do
362
- @query.apply_options({:end_date => (@now+2000)})
363
- @query.end_date.should == (@now+2000)
367
+ query.apply_options({:end_date => (@now+2000)})
368
+ query.end_date.should == (@now+2000)
364
369
  end
365
370
 
366
371
  it "does not replace the end date if option is omitted" do
367
- @query.apply_options({})
368
- Legato.format_time(@query.end_date).should == Legato.format_time(@now)
372
+ query.apply_options({})
373
+ Legato.format_time(query.end_date).should == Legato.format_time(@now)
369
374
  end
370
375
  end
371
376
  end
372
377
 
373
378
  context "with the scope set" do
374
379
  it 'raises when an invalid scope is passed in' do
375
- @query.tracking_scope = "what"
376
- expect { @query.base_url }.to raise_error
380
+ query.tracking_scope = "what"
381
+ expect { query.base_url }.to raise_error
377
382
  end
378
383
 
379
384
  it 'sets the correct endpoint url' do
380
- @query.tracking_scope = "mcf"
381
- expect(@query.base_url).to eql("https://www.googleapis.com/analytics/v3/data/mcf")
385
+ query.tracking_scope = "mcf"
386
+ expect(query.base_url).to eql("https://www.googleapis.com/analytics/v3/data/mcf")
382
387
  end
383
388
 
384
389
  it 'has the correct api endpoint' do
385
- @query.tracking_scope = "ga"
386
- expect(@query.base_url).to eql("https://www.googleapis.com/analytics/v3/data/ga")
390
+ query.tracking_scope = "ga"
391
+ expect(query.base_url).to eql("https://www.googleapis.com/analytics/v3/data/ga")
387
392
  end
388
393
 
389
394
  it 'has the realtime api endpoint' do
390
- @query.tracking_scope = "rt"
391
- expect(@query.base_url).to eql("https://www.googleapis.com/analytics/v3/data/realtime")
395
+ query.tracking_scope = "rt"
396
+ expect(query.base_url).to eql("https://www.googleapis.com/analytics/v3/data/realtime")
392
397
  end
393
398
  end
394
399
 
@@ -397,15 +402,15 @@ describe Legato::Query do
397
402
 
398
403
  context "as a hash of parameters" do
399
404
  before :each do
400
- @query.stubs(:metrics).returns(nil)
401
- @query.stubs(:dimensions).returns(nil)
402
- @query.stubs(:filters).returns(stub(:to_params => nil))
405
+ query.stubs(:metrics).returns(nil)
406
+ query.stubs(:dimensions).returns(nil)
407
+ query.stubs(:filters).returns(stub(:to_params => nil))
403
408
  end
404
409
 
405
410
  it 'includes the profile id' do
406
- @query.stubs(:profile_id).returns('ga:1234567890')
411
+ query.stubs(:profile_id).returns('ga:1234567890')
407
412
 
408
- @query.to_params.should == {
413
+ query.to_params.should == {
409
414
  'ids' => 'ga:1234567890',
410
415
  'start-date' => Legato.format_time(Time.now-Legato::Query::MONTH),
411
416
  'fields' => Legato::Query::REQUEST_FIELDS,
@@ -415,9 +420,9 @@ describe Legato::Query do
415
420
 
416
421
  it 'includes the start and end dates' do
417
422
  now = Time.now
418
- @query.start_date = now
419
- @query.end_date = now
420
- @query.to_params.should == {
423
+ query.start_date = now
424
+ query.end_date = now
425
+ query.to_params.should == {
421
426
  'start-date' => Legato.format_time(now),
422
427
  'fields' => Legato::Query::REQUEST_FIELDS,
423
428
  'end-date' => Legato.format_time(now)
@@ -425,10 +430,10 @@ describe Legato::Query do
425
430
  end
426
431
 
427
432
  it "supports string formatted dates" do
428
- @query.start_date = "2014-01-01"
429
- @query.end_date = "yesterday"
433
+ query.start_date = "2014-01-01"
434
+ query.end_date = "yesterday"
430
435
 
431
- @query.to_params.should == {
436
+ query.to_params.should == {
432
437
  'start-date' => "2014-01-01",
433
438
  'end-date' => "yesterday",
434
439
  'fields' => Legato::Query::REQUEST_FIELDS,
@@ -436,86 +441,86 @@ describe Legato::Query do
436
441
  end
437
442
 
438
443
  it 'includes the limit' do
439
- @query.limit = 1000
440
- @query.to_params['max-results'].should == 1000
444
+ query.limit = 1000
445
+ query.to_params['max-results'].should == 1000
441
446
  end
442
447
 
443
448
  it 'includes the offset' do
444
- @query.offset = 50
445
- @query.to_params['start-index'].should == 50
449
+ query.offset = 50
450
+ query.to_params['start-index'].should == 50
446
451
  end
447
452
 
448
453
  it 'includes the quotaUser if quota_user is set' do
449
- @query.quota_user = 'an id'
450
- @query.to_params['quotaUser'].should == 'an id'
454
+ query.quota_user = 'an id'
455
+ query.to_params['quotaUser'].should == 'an id'
451
456
  end
452
457
 
453
458
  it 'excludes the quotaUser if quota_user is not set' do
454
- @query.to_params.keys.should_not include('quotaUser')
459
+ query.to_params.keys.should_not include('quotaUser')
455
460
  end
456
461
 
457
462
  it 'includes the samplingLevel if sampling_level is set' do
458
- @query.sampling_level = 'FASTER'
459
- @query.to_params['samplingLevel'].should == 'FASTER'
463
+ query.sampling_level = 'FASTER'
464
+ query.to_params['samplingLevel'].should == 'FASTER'
460
465
  end
461
466
 
462
467
  it 'excludes the samplingLevel if sampling_level is not set' do
463
- @query.to_params.keys.should_not include('samplingLevel')
468
+ query.to_params.keys.should_not include('samplingLevel')
464
469
  end
465
470
 
466
471
  it 'includes filters' do
467
472
  filters = stub(:to_params => 'filter set parameters')
468
- @query.stubs(:filters).returns(filters)
473
+ query.stubs(:filters).returns(filters)
469
474
 
470
- @query.to_params['filters'].should == 'filter set parameters'
475
+ query.to_params['filters'].should == 'filter set parameters'
471
476
  end
472
477
 
473
478
  it 'includes the session level conditional segment' do
474
479
  segment_filters = stub(:to_params => 'ga::parameter', :any? => true)
475
- @query.stubs(:segment_filters).returns(segment_filters)
480
+ query.stubs(:segment_filters).returns(segment_filters)
476
481
 
477
- @query.to_params['segment'].should == 'sessions::condition::ga::parameter'
482
+ query.to_params['segment'].should == 'sessions::condition::ga::parameter'
478
483
  end
479
484
 
480
485
  it 'includes segment_id' do
481
- @query.stubs(:segment_id).returns('gaid::12453453')
486
+ query.stubs(:segment_id).returns('gaid::12453453')
482
487
 
483
- @query.to_params['segment'].should == 'gaid::12453453'
488
+ query.to_params['segment'].should == 'gaid::12453453'
484
489
  end
485
490
 
486
491
  it 'includes segment_id and segment_filters' do
487
492
  segment_filters = stub(:to_params => 'ga::parameter', :any? => true)
488
- @query.stubs(:segment_filters).returns(segment_filters)
489
- @query.stubs(:segment_id).returns('gaid::12453453')
493
+ query.stubs(:segment_filters).returns(segment_filters)
494
+ query.stubs(:segment_id).returns('gaid::12453453')
490
495
 
491
- @query.to_params['segment'].should == 'gaid::12453453'
496
+ query.to_params['segment'].should == 'gaid::12453453'
492
497
  end
493
498
 
494
499
  it 'includes metrics' do
495
500
  metrics = Legato::ListParameter.new(:metrics)
496
501
  metrics.stubs(:to_params).returns({'metrics' => 'pageviews,exits'})
497
502
  metrics.stubs(:empty?).returns(false)
498
- @query.stubs(:metrics).returns(metrics)
503
+ query.stubs(:metrics).returns(metrics)
499
504
 
500
- @query.to_params['metrics'].should == 'pageviews,exits'
505
+ query.to_params['metrics'].should == 'pageviews,exits'
501
506
  end
502
507
 
503
508
  it 'includes dimensions' do
504
509
  dimensions = Legato::ListParameter.new(:dimensions)
505
510
  dimensions.stubs(:to_params).returns({'dimensions' => 'browser,country'})
506
511
  dimensions.stubs(:empty?).returns(false)
507
- @query.stubs(:dimensions).returns(dimensions)
512
+ query.stubs(:dimensions).returns(dimensions)
508
513
 
509
- @query.to_params['dimensions'].should == 'browser,country'
514
+ query.to_params['dimensions'].should == 'browser,country'
510
515
  end
511
516
 
512
517
  it 'includes sort' do
513
518
  sort = Legato::ListParameter.new(:sort)
514
519
  sort.stubs(:to_params).returns({'sort' => 'pageviews'})
515
520
  sort.stubs(:empty?).returns(false)
516
- @query.stubs(:sort).returns(sort)
521
+ query.stubs(:sort).returns(sort)
517
522
 
518
- @query.to_params['sort'].should == 'pageviews'
523
+ query.to_params['sort'].should == 'pageviews'
519
524
  end
520
525
  end
521
526
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale