active_reporter 0.6.1 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -9
  3. data/lib/active_reporter/aggregator/array.rb +1 -1
  4. data/lib/active_reporter/aggregator/count.rb +2 -2
  5. data/lib/active_reporter/aggregator/count_if.rb +2 -2
  6. data/lib/active_reporter/aggregator/ratio.rb +1 -1
  7. data/lib/active_reporter/aggregator.rb +9 -9
  8. data/lib/active_reporter/calculator.rb +2 -2
  9. data/lib/active_reporter/dimension/base.rb +3 -3
  10. data/lib/active_reporter/dimension/bin/set.rb +3 -3
  11. data/lib/active_reporter/dimension/bin/table.rb +1 -1
  12. data/lib/active_reporter/dimension/bin.rb +23 -15
  13. data/lib/active_reporter/dimension/category.rb +1 -1
  14. data/lib/active_reporter/dimension/enum.rb +1 -1
  15. data/lib/active_reporter/dimension/number.rb +3 -3
  16. data/lib/active_reporter/dimension/time.rb +4 -4
  17. data/lib/active_reporter/dimension.rb +8 -8
  18. data/lib/active_reporter/evaluator.rb +2 -2
  19. data/lib/active_reporter/inflector.rb +1 -1
  20. data/lib/active_reporter/report/aggregation.rb +12 -12
  21. data/lib/active_reporter/report/definition.rb +6 -6
  22. data/lib/active_reporter/report/validation.rb +26 -15
  23. data/lib/active_reporter/report.rb +3 -3
  24. data/lib/active_reporter/serializer/base.rb +6 -6
  25. data/lib/active_reporter/serializer/csv.rb +2 -2
  26. data/lib/active_reporter/serializer/form_field.rb +5 -5
  27. data/lib/active_reporter/serializer/highcharts.rb +6 -6
  28. data/lib/active_reporter/serializer.rb +7 -7
  29. data/lib/active_reporter/tracker/base.rb +1 -1
  30. data/lib/active_reporter/tracker.rb +3 -3
  31. data/lib/active_reporter/version.rb +1 -1
  32. data/lib/active_reporter.rb +7 -3
  33. data/spec/acceptance/data_spec.rb +49 -49
  34. data/spec/active_reporter/aggregator_spec.rb +37 -37
  35. data/spec/active_reporter/dimension/base_spec.rb +29 -29
  36. data/spec/active_reporter/dimension/bin/set_spec.rb +29 -29
  37. data/spec/active_reporter/dimension/bin/table_spec.rb +7 -7
  38. data/spec/active_reporter/dimension/bin_spec.rb +12 -12
  39. data/spec/active_reporter/dimension/category_spec.rb +22 -22
  40. data/spec/active_reporter/dimension/enum_spec.rb +12 -12
  41. data/spec/active_reporter/dimension/number_spec.rb +11 -11
  42. data/spec/active_reporter/dimension/time_spec.rb +20 -20
  43. data/spec/active_reporter/report_spec.rb +162 -162
  44. data/spec/active_reporter/serializer/hash_table_spec.rb +13 -13
  45. data/spec/active_reporter/serializer/highcharts_spec.rb +30 -30
  46. data/spec/active_reporter/serializer/table_spec.rb +22 -22
  47. data/spec/dummy/Rakefile +1 -1
  48. data/spec/dummy/app/models/post_report.rb +1 -1
  49. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  50. data/spec/dummy/app/views/site/report.html.erb +5 -5
  51. data/spec/dummy/bin/bundle +2 -2
  52. data/spec/dummy/bin/rails +3 -3
  53. data/spec/dummy/bin/rake +2 -2
  54. data/spec/dummy/bin/setup +2 -2
  55. data/spec/dummy/config/application.rb +4 -4
  56. data/spec/dummy/config/boot.rb +3 -3
  57. data/spec/dummy/config/database.yml +3 -3
  58. data/spec/dummy/config/environment.rb +1 -1
  59. data/spec/dummy/config/environments/production.rb +4 -4
  60. data/spec/dummy/config/environments/test.rb +1 -1
  61. data/spec/dummy/config/initializers/assets.rb +1 -1
  62. data/spec/dummy/config/initializers/inflections.rb +4 -4
  63. data/spec/dummy/config/initializers/session_store.rb +1 -1
  64. data/spec/dummy/config/locales/en.yml +2 -2
  65. data/spec/dummy/config/routes.rb +9 -9
  66. data/spec/dummy/config.ru +1 -1
  67. data/spec/dummy/log/test.log +54769 -77257
  68. data/spec/spec_helper.rb +13 -13
  69. metadata +64 -44
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Report do
4
4
  let(:report_model) do
@@ -35,10 +35,10 @@ describe ActiveReporter::Report do
35
35
  let(:mar) { { min: mar_datetime, max: mar_datetime.next_month } }
36
36
  let(:apr) { { min: apr_datetime, max: apr_datetime.next_month } }
37
37
 
38
- describe '.autoreport_on' do
38
+ describe ".autoreport_on" do
39
39
  let(:report_model) { Class.new(ActiveReporter::Report) { autoreport_on :Post } }
40
40
 
41
- it 'infers dimensions from columns' do
41
+ it "infers dimensions from columns" do
42
42
  expect(report_model.dimensions.keys).to include(*%i[created_at updated_at title author likes])
43
43
  end
44
44
 
@@ -62,32 +62,32 @@ describe ActiveReporter::Report do
62
62
  expect(report_model.dimensions[:author][:axis_class]).to eq ActiveReporter::Dimension::Category
63
63
  end
64
64
 
65
- context 'with expression' do
65
+ context "with expression" do
66
66
  let!(:report_model) do
67
67
  Class.new(ActiveReporter::Report) do
68
68
  report_on :Post
69
69
  count_aggregator :count
70
70
  sum_aggregator :likes
71
71
  number_dimension :likes
72
- category_dimension :author, expression: 'authors.name', relation: ->(r) { r.joins(:author) }
72
+ category_dimension :author, expression: "authors.name", relation: ->(r) { r.joins(:author) }
73
73
  time_dimension :created_at
74
74
  ratio_calculator :likes_ratio, aggregator: :likes
75
75
  delta_tracker :likes_delta, aggregator: :likes
76
76
  end
77
77
  end
78
78
 
79
- it 'should properly store author expression' do
80
- expect(report_model.dimensions[:author][:opts][:expression]).to eq 'authors.name'
79
+ it "should properly store author expression" do
80
+ expect(report_model.dimensions[:author][:opts][:expression]).to eq "authors.name"
81
81
  end
82
82
  end
83
83
  end
84
84
 
85
- describe 'data access' do
85
+ describe "data access" do
86
86
  let(:groupers) { %w(author created_at) }
87
87
  let(:dimensions) { { created_at: { bin_width: { months: 1 }, only: { min: Date.new(year,1,1).to_s }}} }
88
88
 
89
- let(:author1) { 'Tammy' }
90
- let(:author2) { 'Timmy' }
89
+ let(:author1) { "Tammy" }
90
+ let(:author2) { "Timmy" }
91
91
 
92
92
  let!(:author1_dec18_post) { create(:post, author: author1, created_at: Date.new(year.pred,12,18), likes: 23) }
93
93
  let!(:author1_jan01_post) { create(:post, author: author1, created_at: Date.new(year,1,1), likes: 7) }
@@ -136,66 +136,66 @@ describe ActiveReporter::Report do
136
136
  let(:author2_mar_likes) { author2_mar_posts.sum(&:likes) }
137
137
  let(:author2_apr_likes) { author2_apr_posts.sum(&:likes) }
138
138
 
139
- it 'should return raw_data' do
139
+ it "should return raw_data" do
140
140
  expect(report.raw_data).to eq(
141
- [author1, jan, 'count'] => author1_jan_count,
142
- [author1, jan, 'likes'] => author1_jan_likes,
143
- [author1, mar, 'count'] => author1_mar_count,
144
- [author1, mar, 'likes'] => author1_mar_likes,
145
- [author2, jan, 'count'] => author2_jan_count,
146
- [author2, jan, 'likes'] => author2_jan_likes,
147
- [author2, feb, 'count'] => author2_feb_count,
148
- [author2, feb, 'likes'] => author2_feb_likes,
149
- [author2, mar, 'count'] => author2_mar_count,
150
- [author2, mar, 'likes'] => author2_mar_likes,
151
- [author2, apr, 'count'] => author2_apr_count,
152
- [author2, apr, 'likes'] => author2_apr_likes,
141
+ [author1, jan, "count"] => author1_jan_count,
142
+ [author1, jan, "likes"] => author1_jan_likes,
143
+ [author1, mar, "count"] => author1_mar_count,
144
+ [author1, mar, "likes"] => author1_mar_likes,
145
+ [author2, jan, "count"] => author2_jan_count,
146
+ [author2, jan, "likes"] => author2_jan_likes,
147
+ [author2, feb, "count"] => author2_feb_count,
148
+ [author2, feb, "likes"] => author2_feb_likes,
149
+ [author2, mar, "count"] => author2_mar_count,
150
+ [author2, mar, "likes"] => author2_mar_likes,
151
+ [author2, apr, "count"] => author2_apr_count,
152
+ [author2, apr, "likes"] => author2_apr_likes,
153
153
  )
154
154
  end
155
155
 
156
- it 'should return flat_data' do
156
+ it "should return flat_data" do
157
157
  expect(report.flat_data).to eq(
158
- [author1, jan, 'count'] => author1_jan_count,
159
- [author1, jan, 'likes'] => author1_jan_likes,
160
- [author1, feb, 'count'] => author1_feb_count,
161
- [author1, feb, 'likes'] => author1_feb_likes,
162
- [author1, mar, 'count'] => author1_mar_count,
163
- [author1, mar, 'likes'] => author1_mar_likes,
164
- [author1, apr, 'count'] => author1_apr_count,
165
- [author1, apr, 'likes'] => author1_apr_likes,
166
- [author2, jan, 'count'] => author2_jan_count,
167
- [author2, jan, 'likes'] => author2_jan_likes,
168
- [author2, feb, 'count'] => author2_feb_count,
169
- [author2, feb, 'likes'] => author2_feb_likes,
170
- [author2, mar, 'count'] => author2_mar_count,
171
- [author2, mar, 'likes'] => author2_mar_likes,
172
- [author2, apr, 'count'] => author2_apr_count,
173
- [author2, apr, 'likes'] => author2_apr_likes,
158
+ [author1, jan, "count"] => author1_jan_count,
159
+ [author1, jan, "likes"] => author1_jan_likes,
160
+ [author1, feb, "count"] => author1_feb_count,
161
+ [author1, feb, "likes"] => author1_feb_likes,
162
+ [author1, mar, "count"] => author1_mar_count,
163
+ [author1, mar, "likes"] => author1_mar_likes,
164
+ [author1, apr, "count"] => author1_apr_count,
165
+ [author1, apr, "likes"] => author1_apr_likes,
166
+ [author2, jan, "count"] => author2_jan_count,
167
+ [author2, jan, "likes"] => author2_jan_likes,
168
+ [author2, feb, "count"] => author2_feb_count,
169
+ [author2, feb, "likes"] => author2_feb_likes,
170
+ [author2, mar, "count"] => author2_mar_count,
171
+ [author2, mar, "likes"] => author2_mar_likes,
172
+ [author2, apr, "count"] => author2_apr_count,
173
+ [author2, apr, "likes"] => author2_apr_likes,
174
174
  )
175
175
  end
176
176
 
177
- it 'should return nested_data' do
177
+ it "should return nested_data" do
178
178
  expect(report.nested_data).to eq [
179
179
  { key: jan, values: [
180
- { key: author1, values: [{ key: 'count', value: author1_jan_count }, { key: 'likes', value: author1_jan_likes }] },
181
- { key: author2, values: [{ key: 'count', value: author2_jan_count }, { key: 'likes', value: author2_jan_likes }] },
180
+ { key: author1, values: [{ key: "count", value: author1_jan_count }, { key: "likes", value: author1_jan_likes }] },
181
+ { key: author2, values: [{ key: "count", value: author2_jan_count }, { key: "likes", value: author2_jan_likes }] },
182
182
  ] },
183
183
  { key: feb, values: [
184
- { key: author1, values: [{ key: 'count', value: author1_feb_count }, { key: 'likes', value: author1_feb_likes }] },
185
- { key: author2, values: [{ key: 'count', value: author2_feb_count }, { key: 'likes', value: author2_feb_likes }] },
184
+ { key: author1, values: [{ key: "count", value: author1_feb_count }, { key: "likes", value: author1_feb_likes }] },
185
+ { key: author2, values: [{ key: "count", value: author2_feb_count }, { key: "likes", value: author2_feb_likes }] },
186
186
  ] },
187
187
  { key: mar, values: [
188
- { key: author1, values: [{ key: 'count', value: author1_mar_count }, { key: 'likes', value: author1_mar_likes }] },
189
- { key: author2, values: [{ key: 'count', value: author2_mar_count }, { key: 'likes', value: author2_mar_likes }] },
188
+ { key: author1, values: [{ key: "count", value: author1_mar_count }, { key: "likes", value: author1_mar_likes }] },
189
+ { key: author2, values: [{ key: "count", value: author2_mar_count }, { key: "likes", value: author2_mar_likes }] },
190
190
  ] },
191
191
  { key: apr, values: [
192
- { key: author1, values: [{ key: 'count', value: author1_apr_count }, { key: 'likes', value: author1_apr_likes }] },
193
- { key: author2, values: [{ key: 'count', value: author2_apr_count }, { key: 'likes', value: author2_apr_likes }] },
192
+ { key: author1, values: [{ key: "count", value: author1_apr_count }, { key: "likes", value: author1_apr_likes }] },
193
+ { key: author2, values: [{ key: "count", value: author2_apr_count }, { key: "likes", value: author2_apr_likes }] },
194
194
  ] }
195
195
  ]
196
196
  end
197
197
 
198
- context 'with calculators' do
198
+ context "with calculators" do
199
199
  let(:parent_groupers) { %i(author) }
200
200
  let(:parent_dimensions) { { created_at: { only: { min: Date.new(year,1,1).to_s }}} }
201
201
  let(:aggregators) { %i(count likes) }
@@ -217,61 +217,61 @@ describe ActiveReporter::Report do
217
217
  let(:author2_mar_likes_ratio) { author2_mar_posts.none? || author2_posts_likes.zero? ? nil : (author2_mar_likes/author2_posts_likes.to_f)*100 }
218
218
  let(:author2_apr_likes_ratio) { author2_apr_posts.none? || author2_posts_likes.zero? ? nil : (author2_apr_likes/author2_posts_likes.to_f)*100 }
219
219
 
220
- it 'should calculate' do
220
+ it "should calculate" do
221
221
  expect(report.data).to eq [
222
222
  { key: jan, values: [
223
223
  { key: author1, values: [
224
- { key: 'count', value: author1_jan_count },
225
- { key: 'likes', value: author1_jan_likes },
226
- { key: 'likes_ratio', value: author1_jan_likes_ratio },
224
+ { key: "count", value: author1_jan_count },
225
+ { key: "likes", value: author1_jan_likes },
226
+ { key: "likes_ratio", value: author1_jan_likes_ratio },
227
227
  ] },
228
228
  { key: author2, values: [
229
- { key: 'count', value: author2_jan_count },
230
- { key: 'likes', value: author2_jan_likes },
231
- { key: 'likes_ratio', value: author2_jan_likes_ratio },
229
+ { key: "count", value: author2_jan_count },
230
+ { key: "likes", value: author2_jan_likes },
231
+ { key: "likes_ratio", value: author2_jan_likes_ratio },
232
232
  ] },
233
233
  ] },
234
234
  { key: feb, values: [
235
235
  { key: author1, values: [
236
- { key: 'count', value: author1_feb_count },
237
- { key: 'likes', value: author1_feb_likes },
238
- { key: 'likes_ratio', value: author1_feb_likes_ratio },
236
+ { key: "count", value: author1_feb_count },
237
+ { key: "likes", value: author1_feb_likes },
238
+ { key: "likes_ratio", value: author1_feb_likes_ratio },
239
239
  ] },
240
240
  { key: author2, values: [
241
- { key: 'count', value: author2_feb_count },
242
- { key: 'likes', value: author2_feb_likes },
243
- { key: 'likes_ratio', value: author2_feb_likes_ratio },
241
+ { key: "count", value: author2_feb_count },
242
+ { key: "likes", value: author2_feb_likes },
243
+ { key: "likes_ratio", value: author2_feb_likes_ratio },
244
244
  ] },
245
245
  ] },
246
246
  { key: mar, values: [
247
247
  { key: author1, values: [
248
- { key: 'count', value: author1_mar_count },
249
- { key: 'likes', value: author1_mar_likes },
250
- { key: 'likes_ratio', value: author1_mar_likes_ratio },
248
+ { key: "count", value: author1_mar_count },
249
+ { key: "likes", value: author1_mar_likes },
250
+ { key: "likes_ratio", value: author1_mar_likes_ratio },
251
251
  ] },
252
252
  { key: author2, values: [
253
- { key: 'count', value: author2_mar_count },
254
- { key: 'likes', value: author2_mar_likes },
255
- { key: 'likes_ratio', value: author2_mar_likes_ratio },
253
+ { key: "count", value: author2_mar_count },
254
+ { key: "likes", value: author2_mar_likes },
255
+ { key: "likes_ratio", value: author2_mar_likes_ratio },
256
256
  ] },
257
257
  ]},
258
258
  { key: apr, values: [
259
259
  { key: author1, values: [
260
- { key: 'count', value: author1_apr_count },
261
- { key: 'likes', value: author1_apr_likes },
262
- { key: 'likes_ratio', value: author1_apr_likes_ratio },
260
+ { key: "count", value: author1_apr_count },
261
+ { key: "likes", value: author1_apr_likes },
262
+ { key: "likes_ratio", value: author1_apr_likes_ratio },
263
263
  ] },
264
264
  { key: author2, values: [
265
- { key: 'count', value: author2_apr_count },
266
- { key: 'likes', value: author2_apr_likes },
267
- { key: 'likes_ratio', value: author2_apr_likes_ratio },
265
+ { key: "count", value: author2_apr_count },
266
+ { key: "likes", value: author2_apr_likes },
267
+ { key: "likes_ratio", value: author2_apr_likes_ratio },
268
268
  ] },
269
269
  ]},
270
270
  ]
271
271
  end
272
272
  end
273
273
 
274
- context 'with trackers' do
274
+ context "with trackers" do
275
275
  let(:aggregators) { %i(count likes) }
276
276
  let(:trackers) { %i(likes_delta) }
277
277
 
@@ -291,54 +291,54 @@ describe ActiveReporter::Report do
291
291
  let(:author2_mar_likes_delta) { author2_feb_likes.zero? || author2_mar_likes.zero? ? nil : (author2_mar_likes/author2_feb_likes.to_f)*100 }
292
292
  let(:author2_apr_likes_delta) { author2_mar_likes.zero? || author2_apr_likes.zero? ? nil : (author2_apr_likes/author2_mar_likes.to_f)*100 }
293
293
 
294
- it 'should calculate' do
294
+ it "should calculate" do
295
295
  expect(report.data).to eq [
296
296
  { key: jan, values: [
297
297
  { key: author1, values: [
298
- { key: 'count', value: author1_jan_count },
299
- { key: 'likes', value: author1_jan_likes },
300
- { key: 'likes_delta', value: author1_jan_likes_delta },
298
+ { key: "count", value: author1_jan_count },
299
+ { key: "likes", value: author1_jan_likes },
300
+ { key: "likes_delta", value: author1_jan_likes_delta },
301
301
  ] },
302
302
  { key: author2, values: [
303
- { key: 'count', value: author2_jan_count },
304
- { key: 'likes', value: author2_jan_likes },
305
- { key: 'likes_delta', value: author2_jan_likes_delta },
303
+ { key: "count", value: author2_jan_count },
304
+ { key: "likes", value: author2_jan_likes },
305
+ { key: "likes_delta", value: author2_jan_likes_delta },
306
306
  ] },
307
307
  ] },
308
308
  { key: feb, values: [
309
309
  { key: author1, values: [
310
- { key: 'count', value: author1_feb_count },
311
- { key: 'likes', value: author1_feb_likes },
312
- { key: 'likes_delta', value: author1_feb_likes_delta },
310
+ { key: "count", value: author1_feb_count },
311
+ { key: "likes", value: author1_feb_likes },
312
+ { key: "likes_delta", value: author1_feb_likes_delta },
313
313
  ] },
314
314
  { key: author2, values: [
315
- { key: 'count', value: author2_feb_count },
316
- { key: 'likes', value: author2_feb_likes },
317
- { key: 'likes_delta', value: author2_feb_likes_delta },
315
+ { key: "count", value: author2_feb_count },
316
+ { key: "likes", value: author2_feb_likes },
317
+ { key: "likes_delta", value: author2_feb_likes_delta },
318
318
  ] },
319
319
  ] },
320
320
  { key: mar, values: [
321
321
  { key: author1, values: [
322
- { key: 'count', value: author1_mar_count },
323
- { key: 'likes', value: author1_mar_likes },
324
- { key: 'likes_delta', value: author1_mar_likes_delta },
322
+ { key: "count", value: author1_mar_count },
323
+ { key: "likes", value: author1_mar_likes },
324
+ { key: "likes_delta", value: author1_mar_likes_delta },
325
325
  ] },
326
326
  { key: author2, values: [
327
- { key: 'count', value: author2_mar_count },
328
- { key: 'likes', value: author2_mar_likes },
329
- { key: 'likes_delta', value: author2_mar_likes_delta },
327
+ { key: "count", value: author2_mar_count },
328
+ { key: "likes", value: author2_mar_likes },
329
+ { key: "likes_delta", value: author2_mar_likes_delta },
330
330
  ] },
331
331
  ]},
332
332
  { key: apr, values: [
333
333
  { key: author1, values: [
334
- { key: 'count', value: author1_apr_count },
335
- { key: 'likes', value: author1_apr_likes },
336
- { key: 'likes_delta', value: author1_apr_likes_delta },
334
+ { key: "count", value: author1_apr_count },
335
+ { key: "likes", value: author1_apr_likes },
336
+ { key: "likes_delta", value: author1_apr_likes_delta },
337
337
  ] },
338
338
  { key: author2, values: [
339
- { key: 'count', value: author2_apr_count },
340
- { key: 'likes', value: author2_apr_likes },
341
- { key: 'likes_delta', value: author2_apr_likes_delta },
339
+ { key: "count", value: author2_apr_count },
340
+ { key: "likes", value: author2_apr_likes },
341
+ { key: "likes_delta", value: author2_apr_likes_delta },
342
342
  ] },
343
343
  ]},
344
344
  ]
@@ -346,8 +346,8 @@ describe ActiveReporter::Report do
346
346
  end
347
347
  end
348
348
 
349
- describe '#dimensions' do
350
- it 'is a curried hash' do
349
+ describe "#dimensions" do
350
+ it "is a curried hash" do
351
351
  expect(report_model.dimensions.keys).to include(:likes, :author, :created_at)
352
352
  expect(report.dimensions.keys).to include(:likes, :author, :created_at)
353
353
  expect(report.dimensions[:likes]).to be_a ActiveReporter::Dimension::Number
@@ -356,31 +356,31 @@ describe ActiveReporter::Report do
356
356
  end
357
357
  end
358
358
 
359
- describe '#calculators' do
359
+ describe "#calculators" do
360
360
  let(:parent_groupers) { %i(author) }
361
361
  let(:aggregators) { %i(count likes) }
362
362
  let(:parent_report) { report_model.new({groupers: parent_groupers, aggregators: aggregators}) }
363
363
  let(:calculators) { %i(likes_ratio) }
364
364
 
365
- it 'should return configured calculators' do
365
+ it "should return configured calculators" do
366
366
  expect(report.calculators).to include(:likes_ratio)
367
367
  end
368
368
  end
369
369
 
370
- describe '#trackers' do
370
+ describe "#trackers" do
371
371
  let(:parent_groupers) { %i(author) }
372
372
  let(:aggregators) { %i(count likes) }
373
373
  let(:parent_report) { report_model.new({groupers: parent_groupers, aggregators: aggregators}) }
374
374
  let(:trackers) { %i(likes_delta) }
375
375
 
376
- it 'should return configured trackers' do
376
+ it "should return configured trackers" do
377
377
  expect(report.trackers).to include(:likes_delta)
378
378
  end
379
379
  end
380
380
 
381
- describe '#params' do
382
- let(:author1) { 'Phil' }
383
- let(:author2) { 'Phyllis' }
381
+ describe "#params" do
382
+ let(:author1) { "Phil" }
383
+ let(:author2) { "Phyllis" }
384
384
  let(:date) { Date.new(year,1,1) }
385
385
  let(:author1_post1) { create(:post, author: author1, created_at: date) }
386
386
  let(:author1_post2) { create(:post, author: author1, created_at: date) }
@@ -391,50 +391,50 @@ describe ActiveReporter::Report do
391
391
  let(:author1_posts) { [author1_post1, author1_post2] }
392
392
  let(:author2_posts) { [author2_post1, author2_post2] }
393
393
 
394
- context 'where author dimension only allows empty string' do
395
- let(:report) { report_model.new(dimensions: { author: { only: '' }}) }
394
+ context "where author dimension only allows empty string" do
395
+ let(:report) { report_model.new(dimensions: { author: { only: "" }}) }
396
396
 
397
- it 'strips empty string but preserves nil by default' do
397
+ it "strips empty string but preserves nil by default" do
398
398
  expect(report.params).to be_blank
399
399
  expect(report.dimensions[:author].filter_values).to be_blank
400
400
  expect(report.records).to contain_exactly(*all_posts)
401
401
  end
402
402
  end
403
403
 
404
- context 'where author dimension only allows array of empty string' do
405
- let(:report) { report_model.new(dimensions: { author: { only: [''] }}) }
404
+ context "where author dimension only allows array of empty string" do
405
+ let(:report) { report_model.new(dimensions: { author: { only: [""] }}) }
406
406
 
407
- it 'strips empty string but preserves nil by default' do
407
+ it "strips empty string but preserves nil by default" do
408
408
  expect(report.params).to be_blank
409
409
  expect(report.dimensions[:author].filter_values).to be_blank
410
410
  expect(report.records).to contain_exactly(*all_posts)
411
411
  end
412
412
  end
413
413
 
414
- context 'where author dimension only allows empty string or Phil' do
415
- let(:report) { report_model.new(dimensions: { author: { only: ['', author1] }}) }
414
+ context "where author dimension only allows empty string or Phil" do
415
+ let(:report) { report_model.new(dimensions: { author: { only: ["", author1] }}) }
416
416
 
417
- it 'strips empty string but preserves nil by default' do
417
+ it "strips empty string but preserves nil by default" do
418
418
  expect(report.params).to be_present
419
419
  expect(report.dimensions[:author].filter_values).to contain_exactly(author1)
420
420
  expect(report.records).to contain_exactly(*author1_posts)
421
421
  end
422
422
  end
423
423
 
424
- context 'where author dimension strips blank values and only allows empty string' do
425
- let(:report) { report_model.new(strip_blanks: false, dimensions: { author: { only: '' }}) }
424
+ context "where author dimension strips blank values and only allows empty string" do
425
+ let(:report) { report_model.new(strip_blanks: false, dimensions: { author: { only: "" }}) }
426
426
 
427
- it 'strips empty string but preserves nil by default' do
427
+ it "strips empty string but preserves nil by default" do
428
428
  expect(report.params).to be_present
429
- expect(report.dimensions[:author].filter_values).to eq([''])
429
+ expect(report.dimensions[:author].filter_values).to eq([""])
430
430
  expect(report.records).to be_empty
431
431
  end
432
432
  end
433
433
 
434
- context 'where author dimension only allows nil' do
434
+ context "where author dimension only allows nil" do
435
435
  let(:report) { report_model.new(dimensions: { author: { only: nil }}) }
436
436
 
437
- it 'strips empty string but preserves nil by default' do
437
+ it "strips empty string but preserves nil by default" do
438
438
  expect(report.params).to be_present
439
439
  expect(report.dimensions[:author].filter_values).to eq [nil]
440
440
  expect(report.records).to be_empty
@@ -442,19 +442,19 @@ describe ActiveReporter::Report do
442
442
  end
443
443
  end
444
444
 
445
- describe '#parent_report' do
445
+ describe "#parent_report" do
446
446
  let(:groupers) { %i(author created_at) }
447
447
  let(:aggregators) { %i(count likes) }
448
448
  let(:dimensions) { { created_at: { bin_width: { months: 1 }}} }
449
449
  let(:parent_report) { report_model.new({ groupers: %i(author), aggregators: aggregators }) }
450
450
 
451
- it 'should return passed parent report' do
451
+ it "should return passed parent report" do
452
452
  expect(report.parent_report).to be_a report_model
453
453
  end
454
454
  end
455
455
 
456
- describe '#aggregators' do
457
- it 'is a curried hash' do
456
+ describe "#aggregators" do
457
+ it "is a curried hash" do
458
458
  expect(report_model.aggregators.keys).to eq [:count, :likes]
459
459
  expect(report.aggregators.keys).to eq [:count, :likes]
460
460
  expect(report.aggregators[:count]).to be_a ActiveReporter::Aggregator::Count
@@ -462,36 +462,36 @@ describe ActiveReporter::Report do
462
462
  end
463
463
  end
464
464
 
465
- describe '#groupers' do
466
- it 'defaults to the first' do
465
+ describe "#groupers" do
466
+ it "defaults to the first" do
467
467
  expect(report.groupers).to eq [report.dimensions[:likes]]
468
468
  end
469
469
 
470
- context 'with created_at group' do
471
- let(:groupers) { 'created_at' }
470
+ context "with created_at group" do
471
+ let(:groupers) { "created_at" }
472
472
 
473
- it 'can be set' do
473
+ it "can be set" do
474
474
  expect(report.groupers).to eq [report.dimensions[:created_at]]
475
475
  end
476
476
  end
477
477
 
478
- context 'with created_at and author groups' do
478
+ context "with created_at and author groups" do
479
479
  let(:groupers) { %w(created_at author) }
480
480
 
481
- it 'can be set' do
481
+ it "can be set" do
482
482
  expect(report.groupers).to eq [report.dimensions[:created_at], report.dimensions[:author]]
483
483
  end
484
484
  end
485
485
 
486
- context 'with invalid group' do
486
+ context "with invalid group" do
487
487
  let(:groupers) { %w(chickens) }
488
488
 
489
- it 'should raise an exception' do
489
+ it "should raise an exception" do
490
490
  expect { report }.to raise_error(ActiveReporter::InvalidParamsError)
491
491
  end
492
492
  end
493
493
 
494
- context 'on a report class with no dimensions declared' do
494
+ context "on a report class with no dimensions declared" do
495
495
  let(:report_model) do
496
496
  Class.new(ActiveReporter::Report) do
497
497
  report_on :Post
@@ -499,30 +499,30 @@ describe ActiveReporter::Report do
499
499
  end
500
500
  end
501
501
 
502
- specify 'there must be at least one defined' do
503
- expect { report }.to raise_error Regexp.new('does not declare any dimensions')
502
+ specify "there must be at least one defined" do
503
+ expect { report }.to raise_error Regexp.new("does not declare any dimensions")
504
504
  end
505
505
  end
506
506
  end
507
507
 
508
- describe '#aggregators' do
509
- context 'where the report aggregators are set' do
510
- let(:aggregators) { 'likes' }
508
+ describe "#aggregators" do
509
+ context "where the report aggregators are set" do
510
+ let(:aggregators) { "likes" }
511
511
 
512
- it 'returns the set aggregators' do
512
+ it "returns the set aggregators" do
513
513
  expect(report.aggregators.values).to contain_exactly report.aggregators[:likes]
514
514
  end
515
515
  end
516
516
 
517
- context 'where the report aggregators include an invalid value' do
518
- let(:aggregators) { 'chicken' }
517
+ context "where the report aggregators include an invalid value" do
518
+ let(:aggregators) { "chicken" }
519
519
 
520
- it 'should raise an exception' do
520
+ it "should raise an exception" do
521
521
  expect { report }.to raise_error(ActiveReporter::InvalidParamsError)
522
522
  end
523
523
  end
524
524
 
525
- context 'on a report class with no dimensions declared' do
525
+ context "on a report class with no dimensions declared" do
526
526
  let(:report_model) do
527
527
  Class.new(ActiveReporter::Report) do
528
528
  report_on :Post
@@ -530,19 +530,19 @@ describe ActiveReporter::Report do
530
530
  end
531
531
  end
532
532
 
533
- specify 'there must be at least one defined' do
534
- expect { report }.to raise_error Regexp.new('does not declare any aggregators or trackers')
533
+ specify "there must be at least one defined" do
534
+ expect { report }.to raise_error Regexp.new("does not declare any aggregators or trackers")
535
535
  end
536
536
  end
537
537
  end
538
538
 
539
- describe '#total_data' do
539
+ describe "#total_data" do
540
540
  let(:groupers) { %w(author created_at) }
541
541
  let(:aggregators) { %i(count likes) }
542
542
  let(:dimensions) { { likes: { bin_width: 1 }, created_at: { bin_width: { months: 1 }}} }
543
543
 
544
- let(:author1) { 'Timmy' }
545
- let(:author2) { 'Tammy' }
544
+ let(:author1) { "Timmy" }
545
+ let(:author2) { "Tammy" }
546
546
  let!(:author1_jan01_post) { create(:post, author: author1, created_at: Date.new(year,1,1), likes: 1) }
547
547
  let!(:author1_jan12_post) { create(:post, author: author1, created_at: Date.new(year,1,12), likes: 2) }
548
548
  let!(:author2_jan15_post) { create(:post, author: author2, created_at: Date.new(year,1,15), likes: 3) }
@@ -553,14 +553,14 @@ describe ActiveReporter::Report do
553
553
  let(:all_posts_count) { all_posts.count }
554
554
  let(:all_posts_likes) { all_posts.sum(&:likes) }
555
555
 
556
- it 'should return total_data' do
556
+ it "should return total_data" do
557
557
  expect(report.total_data).to eq({
558
- ['totals', 'count'] => all_posts_count,
559
- ['totals', 'likes'] => all_posts_likes,
558
+ ["totals", "count"] => all_posts_count,
559
+ ["totals", "likes"] => all_posts_likes,
560
560
  })
561
561
  end
562
562
 
563
- context 'with calculators' do
563
+ context "with calculators" do
564
564
  let(:parent_report_model) do
565
565
  Class.new(ActiveReporter::Report) do
566
566
  report_on :Post
@@ -585,11 +585,11 @@ describe ActiveReporter::Report do
585
585
  let(:author2_posts_likes) { author2_posts.sum(&:likes) }
586
586
  let(:author2_posts_likes_ratio) { all_posts_likes.zero? ? nil : (author2_posts_likes/all_posts_likes.to_f)*100 }
587
587
 
588
- it 'should calculate' do
588
+ it "should calculate" do
589
589
  expect(report.total_data).to eq({
590
- ['totals', 'count'] => author2_posts_count,
591
- ['totals', 'likes'] => author2_posts_likes,
592
- ['totals', 'likes_ratio'] => author2_posts_likes_ratio
590
+ ["totals", "count"] => author2_posts_count,
591
+ ["totals", "likes"] => author2_posts_likes,
592
+ ["totals", "likes_ratio"] => author2_posts_likes_ratio
593
593
  })
594
594
  end
595
595
  end