active_reporter 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -9
- data/lib/active_reporter/aggregator/array.rb +1 -1
- data/lib/active_reporter/aggregator/count.rb +2 -2
- data/lib/active_reporter/aggregator/count_if.rb +2 -2
- data/lib/active_reporter/aggregator.rb +9 -9
- data/lib/active_reporter/calculator.rb +2 -2
- data/lib/active_reporter/dimension/base.rb +3 -3
- data/lib/active_reporter/dimension/bin/set.rb +3 -3
- data/lib/active_reporter/dimension/bin/table.rb +1 -1
- data/lib/active_reporter/dimension/bin.rb +23 -15
- data/lib/active_reporter/dimension/category.rb +1 -1
- data/lib/active_reporter/dimension/enum.rb +1 -1
- data/lib/active_reporter/dimension/number.rb +3 -3
- data/lib/active_reporter/dimension/time.rb +4 -4
- data/lib/active_reporter/dimension.rb +8 -8
- data/lib/active_reporter/evaluator.rb +2 -2
- data/lib/active_reporter/inflector.rb +1 -1
- data/lib/active_reporter/report/aggregation.rb +12 -12
- data/lib/active_reporter/report/definition.rb +6 -6
- data/lib/active_reporter/report/validation.rb +9 -9
- data/lib/active_reporter/report.rb +3 -3
- data/lib/active_reporter/serializer/base.rb +6 -6
- data/lib/active_reporter/serializer/csv.rb +2 -2
- data/lib/active_reporter/serializer/form_field.rb +5 -5
- data/lib/active_reporter/serializer/highcharts.rb +6 -6
- data/lib/active_reporter/serializer.rb +7 -7
- data/lib/active_reporter/tracker/base.rb +1 -1
- data/lib/active_reporter/tracker.rb +3 -3
- data/lib/active_reporter/version.rb +1 -1
- data/lib/active_reporter.rb +7 -3
- data/spec/acceptance/data_spec.rb +49 -49
- data/spec/active_reporter/aggregator_spec.rb +37 -37
- data/spec/active_reporter/dimension/base_spec.rb +29 -29
- data/spec/active_reporter/dimension/bin/set_spec.rb +29 -29
- data/spec/active_reporter/dimension/bin/table_spec.rb +7 -7
- data/spec/active_reporter/dimension/bin_spec.rb +12 -12
- data/spec/active_reporter/dimension/category_spec.rb +22 -22
- data/spec/active_reporter/dimension/enum_spec.rb +12 -12
- data/spec/active_reporter/dimension/number_spec.rb +11 -11
- data/spec/active_reporter/dimension/time_spec.rb +20 -20
- data/spec/active_reporter/report_spec.rb +162 -162
- data/spec/active_reporter/serializer/hash_table_spec.rb +13 -13
- data/spec/active_reporter/serializer/highcharts_spec.rb +30 -30
- data/spec/active_reporter/serializer/table_spec.rb +22 -22
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/models/post_report.rb +1 -1
- data/spec/dummy/app/views/layouts/application.html.erb +2 -2
- data/spec/dummy/app/views/site/report.html.erb +5 -5
- data/spec/dummy/bin/bundle +2 -2
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +2 -2
- data/spec/dummy/config/application.rb +4 -4
- data/spec/dummy/config/boot.rb +3 -3
- data/spec/dummy/config/database.yml +3 -3
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/production.rb +4 -4
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/assets.rb +1 -1
- data/spec/dummy/config/initializers/inflections.rb +4 -4
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/locales/en.yml +2 -2
- data/spec/dummy/config/routes.rb +9 -9
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/log/test.log +68265 -0
- data/spec/spec_helper.rb +13 -13
- metadata +50 -30
@@ -2,7 +2,7 @@ module ActiveReporter
|
|
2
2
|
module Serializer
|
3
3
|
class Highcharts < Table
|
4
4
|
def colors
|
5
|
-
[
|
5
|
+
["#7cb5ec", "#434348", "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354", "#2b908f", "#f45b5b", "#91e8e1"]
|
6
6
|
end
|
7
7
|
|
8
8
|
def color_hash
|
@@ -118,7 +118,7 @@ module ActiveReporter
|
|
118
118
|
human_aggregator_label(report.all_aggregators),
|
119
119
|
human_aggregator_value_label(report.all_aggregators, xes[report.groupers.first][:value])
|
120
120
|
]
|
121
|
-
lines.map { |k, v| "<b>#{k}:</b> #{v}" }.join(
|
121
|
+
lines.map { |k, v| "<b>#{k}:</b> #{v}" }.join("<br/>")
|
122
122
|
end
|
123
123
|
|
124
124
|
def filters_for(xes)
|
@@ -153,7 +153,7 @@ module ActiveReporter
|
|
153
153
|
def highcharts_options
|
154
154
|
{
|
155
155
|
chart: {
|
156
|
-
type:
|
156
|
+
type: "column"
|
157
157
|
},
|
158
158
|
colors: colors,
|
159
159
|
title: {
|
@@ -176,9 +176,9 @@ module ActiveReporter
|
|
176
176
|
},
|
177
177
|
stackLabels: {
|
178
178
|
enabled: report.groupers.length >= 3,
|
179
|
-
format:
|
179
|
+
format: "{stack}",
|
180
180
|
rotation: -45,
|
181
|
-
textAlign:
|
181
|
+
textAlign: "left"
|
182
182
|
}
|
183
183
|
},
|
184
184
|
legend: {
|
@@ -190,7 +190,7 @@ module ActiveReporter
|
|
190
190
|
events: {}
|
191
191
|
},
|
192
192
|
column: {
|
193
|
-
stacking: (
|
193
|
+
stacking: ("normal" if report.groupers.length >= 2)
|
194
194
|
}
|
195
195
|
}
|
196
196
|
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require "active_reporter/serializer/base"
|
2
|
+
require "active_reporter/serializer/table"
|
3
|
+
require "active_reporter/serializer/csv"
|
4
|
+
require "active_reporter/serializer/form_field"
|
5
|
+
require "active_reporter/serializer/highcharts"
|
6
|
+
require "active_reporter/serializer/hash_table"
|
7
|
+
require "active_reporter/serializer/nested_hash"
|
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "active_reporter/tracker/base"
|
2
|
+
require "active_reporter/tracker/delta"
|
3
|
+
require "active_reporter/tracker/value"
|
data/lib/active_reporter.rb
CHANGED
@@ -17,10 +17,14 @@ module ActiveReporter
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def database_adapter
|
20
|
-
ActiveRecord::
|
20
|
+
@database_adapter ||= if ActiveRecord.gem_version < Gem::Version.new("6")
|
21
|
+
ActiveRecord::Base.connection_config[:adapter]
|
22
|
+
else
|
23
|
+
ActiveRecord::Base.connection_db_config.adapter
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
require
|
26
|
-
Dir.glob(File.join(__dir__,
|
29
|
+
require "deeply_enumerable"
|
30
|
+
Dir.glob(File.join(__dir__, "active_reporter", "*/")).each { |file| require file.chomp("/") }
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "more complicated case" do
|
4
4
|
let(:report_model) do
|
5
5
|
Class.new(ActiveReporter::Report) do
|
6
6
|
report_on :Post
|
@@ -61,12 +61,12 @@ describe 'more complicated case' do
|
|
61
61
|
expect(h1_json).to eq h2_json
|
62
62
|
end
|
63
63
|
|
64
|
-
let(:joyce) { create(:author, name:
|
65
|
-
let(:woolf) { create(:author, name:
|
64
|
+
let(:joyce) { create(:author, name: "James Joyce") }
|
65
|
+
let(:woolf) { create(:author, name: "Virginia Woolf") }
|
66
66
|
|
67
|
-
let(:oct_1) { Time.zone.parse(
|
68
|
-
let(:nov_1) { Time.zone.parse(
|
69
|
-
let(:dec_1) { Time.zone.parse(
|
67
|
+
let(:oct_1) { Time.zone.parse("2015-10-01") }
|
68
|
+
let(:nov_1) { Time.zone.parse("2015-11-01") }
|
69
|
+
let(:dec_1) { Time.zone.parse("2015-12-01") }
|
70
70
|
|
71
71
|
let(:oct) { { min: oct_1, max: nov_1 } }
|
72
72
|
let(:nov) { { min: nov_1, max: dec_1 } }
|
@@ -83,50 +83,50 @@ describe 'more complicated case' do
|
|
83
83
|
let!(:post_8) { create(:post, author: nil, published_at: oct_1, likes: 2) }
|
84
84
|
let!(:post_9) { create(:post, author: nil, published_at: nov_1, likes: 3) }
|
85
85
|
|
86
|
-
specify
|
86
|
+
specify "basic grouping, 1 grouper, no filters" do
|
87
87
|
expect_equal data_by(:author), [
|
88
88
|
{ key: nil, values: [
|
89
89
|
{ key: :count, value: 2 },
|
90
90
|
{ key: :total_likes, value: 5 },
|
91
|
-
{ key: :mean_likes, value:
|
91
|
+
{ key: :mean_likes, value: "2.5" },
|
92
92
|
{ key: :min_likes, value: 2 },
|
93
93
|
{ key: :max_likes, value: 3 }
|
94
94
|
] },
|
95
95
|
{ key: joyce.name, values: [
|
96
96
|
{ key: :count, value: 4 },
|
97
97
|
{ key: :total_likes, value: 7 },
|
98
|
-
{ key: :mean_likes, value:
|
98
|
+
{ key: :mean_likes, value: "1.75" },
|
99
99
|
{ key: :min_likes, value: 1 },
|
100
100
|
{ key: :max_likes, value: 3 }
|
101
101
|
] },
|
102
102
|
{ key: woolf.name, values: [
|
103
103
|
{ key: :count, value: 3 },
|
104
104
|
{ key: :total_likes, value: 8 },
|
105
|
-
{ key: :mean_likes, value:
|
105
|
+
{ key: :mean_likes, value: "2.6666666666666667" },
|
106
106
|
{ key: :min_likes, value: 2 },
|
107
107
|
{ key: :max_likes, value: 3 }
|
108
108
|
] }
|
109
109
|
]
|
110
110
|
|
111
|
-
expect_equal data_by(:published_at, bin_width:
|
111
|
+
expect_equal data_by(:published_at, bin_width: "1 month"), [
|
112
112
|
{ key: nil, values: [
|
113
113
|
{ key: :count, value: 2 },
|
114
114
|
{ key: :total_likes, value: 6 },
|
115
|
-
{ key: :mean_likes, value:
|
115
|
+
{ key: :mean_likes, value: "3.0" },
|
116
116
|
{ key: :min_likes, value: 3 },
|
117
117
|
{ key: :max_likes, value: 3 }
|
118
118
|
] },
|
119
119
|
{ key: oct, values: [
|
120
120
|
{ key: :count, value: 4 },
|
121
121
|
{ key: :total_likes, value: 7 },
|
122
|
-
{ key: :mean_likes, value:
|
122
|
+
{ key: :mean_likes, value: "1.75" },
|
123
123
|
{ key: :min_likes, value: 1 },
|
124
124
|
{ key: :max_likes, value: 2 }
|
125
125
|
] },
|
126
126
|
{ key: nov, values: [
|
127
127
|
{ key: :count, value: 3 },
|
128
128
|
{ key: :total_likes, value: 7 },
|
129
|
-
{ key: :mean_likes, value:
|
129
|
+
{ key: :mean_likes, value: "2.3333333333333333" },
|
130
130
|
{ key: :min_likes, value: 1 },
|
131
131
|
{ key: :max_likes, value: 3 }
|
132
132
|
] }
|
@@ -136,28 +136,28 @@ describe 'more complicated case' do
|
|
136
136
|
{ key: { min: 1, max: 2 }, values: [
|
137
137
|
{ key: :count, value: 2 },
|
138
138
|
{ key: :total_likes, value: 2 },
|
139
|
-
{ key: :mean_likes, value:
|
139
|
+
{ key: :mean_likes, value: "1.0" },
|
140
140
|
{ key: :min_likes, value: 1 },
|
141
141
|
{ key: :max_likes, value: 1 }
|
142
142
|
] },
|
143
143
|
{ key: { min: 2, max: 3 }, values: [
|
144
144
|
{ key: :count, value: 3 },
|
145
145
|
{ key: :total_likes, value: 6 },
|
146
|
-
{ key: :mean_likes, value:
|
146
|
+
{ key: :mean_likes, value: "2.0" },
|
147
147
|
{ key: :min_likes, value: 2 },
|
148
148
|
{ key: :max_likes, value: 2 }
|
149
149
|
] },
|
150
150
|
{ key: { min: 3, max: 4 }, values: [
|
151
151
|
{ key: :count, value: 4 },
|
152
152
|
{ key: :total_likes, value: 12 },
|
153
|
-
{ key: :mean_likes, value:
|
153
|
+
{ key: :mean_likes, value: "3.0" },
|
154
154
|
{ key: :min_likes, value: 3 },
|
155
155
|
{ key: :max_likes, value: 3 }
|
156
156
|
] }
|
157
157
|
]
|
158
158
|
end
|
159
159
|
|
160
|
-
specify
|
160
|
+
specify "basic grouping, >=2 groupers, no filters" do
|
161
161
|
expect_equal data_by([:published_at, :author], bin_width: { months: 1 }), [
|
162
162
|
{ key: nil, values: [
|
163
163
|
{ key: nil, values: [
|
@@ -170,14 +170,14 @@ describe 'more complicated case' do
|
|
170
170
|
{ key: oct, values: [
|
171
171
|
{ key: :count, value: 1 },
|
172
172
|
{ key: :total_likes, value: 2 },
|
173
|
-
{ key: :mean_likes, value:
|
173
|
+
{ key: :mean_likes, value: "2.0" },
|
174
174
|
{ key: :min_likes, value: 2 },
|
175
175
|
{ key: :max_likes, value: 2 }
|
176
176
|
] },
|
177
177
|
{ key: nov, values: [
|
178
178
|
{ key: :count, value: 1 },
|
179
179
|
{ key: :total_likes, value: 3 },
|
180
|
-
{ key: :mean_likes, value:
|
180
|
+
{ key: :mean_likes, value: "3.0" },
|
181
181
|
{ key: :min_likes, value: 3 },
|
182
182
|
{ key: :max_likes, value: 3 }
|
183
183
|
] }
|
@@ -186,21 +186,21 @@ describe 'more complicated case' do
|
|
186
186
|
{ key: nil, values: [
|
187
187
|
{ key: :count, value: 1 },
|
188
188
|
{ key: :total_likes, value: 3 },
|
189
|
-
{ key: :mean_likes, value:
|
189
|
+
{ key: :mean_likes, value: "3.0" },
|
190
190
|
{ key: :min_likes, value: 3 },
|
191
191
|
{ key: :max_likes, value: 3 }
|
192
192
|
] },
|
193
193
|
{ key: oct, values: [
|
194
194
|
{ key: :count, value: 2 },
|
195
195
|
{ key: :total_likes, value: 3 },
|
196
|
-
{ key: :mean_likes, value:
|
196
|
+
{ key: :mean_likes, value: "1.5" },
|
197
197
|
{ key: :min_likes, value: 1 },
|
198
198
|
{ key: :max_likes, value: 2 }
|
199
199
|
] },
|
200
200
|
{ key: nov, values: [
|
201
201
|
{ key: :count, value: 1 },
|
202
202
|
{ key: :total_likes, value: 1 },
|
203
|
-
{ key: :mean_likes, value:
|
203
|
+
{ key: :mean_likes, value: "1.0" },
|
204
204
|
{ key: :min_likes, value: 1 },
|
205
205
|
{ key: :max_likes, value: 1 }
|
206
206
|
] }
|
@@ -209,21 +209,21 @@ describe 'more complicated case' do
|
|
209
209
|
{ key: nil, values: [
|
210
210
|
{ key: :count, value: 1 },
|
211
211
|
{ key: :total_likes, value: 3 },
|
212
|
-
{ key: :mean_likes, value:
|
212
|
+
{ key: :mean_likes, value: "3.0" },
|
213
213
|
{ key: :min_likes, value: 3 },
|
214
214
|
{ key: :max_likes, value: 3 }
|
215
215
|
] },
|
216
216
|
{ key: oct, values: [
|
217
217
|
{ key: :count, value: 1 },
|
218
218
|
{ key: :total_likes, value: 2 },
|
219
|
-
{ key: :mean_likes, value:
|
219
|
+
{ key: :mean_likes, value: "2.0" },
|
220
220
|
{ key: :min_likes, value: 2 },
|
221
221
|
{ key: :max_likes, value: 2 }
|
222
222
|
] },
|
223
223
|
{ key: nov, values: [
|
224
224
|
{ key: :count, value: 1 },
|
225
225
|
{ key: :total_likes, value: 3 },
|
226
|
-
{ key: :mean_likes, value:
|
226
|
+
{ key: :mean_likes, value: "3.0" },
|
227
227
|
{ key: :min_likes, value: 3 },
|
228
228
|
{ key: :max_likes, value: 3 }
|
229
229
|
] }
|
@@ -231,50 +231,50 @@ describe 'more complicated case' do
|
|
231
231
|
]
|
232
232
|
end
|
233
233
|
|
234
|
-
specify
|
234
|
+
specify "sorting with nulls (1 grouper)" do
|
235
235
|
expect_equal data_by(:author, sort_desc: true), [
|
236
236
|
{ key: woolf.name, values: [
|
237
237
|
{ key: :count, value: 3 },
|
238
238
|
{ key: :total_likes, value: 8 },
|
239
|
-
{ key: :mean_likes, value:
|
239
|
+
{ key: :mean_likes, value: "2.6666666666666667" },
|
240
240
|
{ key: :min_likes, value: 2 },
|
241
241
|
{ key: :max_likes, value: 3 }
|
242
242
|
] },
|
243
243
|
{ key: joyce.name, values: [
|
244
244
|
{ key: :count, value: 4 },
|
245
245
|
{ key: :total_likes, value: 7 },
|
246
|
-
{ key: :mean_likes, value:
|
246
|
+
{ key: :mean_likes, value: "1.75" },
|
247
247
|
{ key: :min_likes, value: 1 },
|
248
248
|
{ key: :max_likes, value: 3 }
|
249
249
|
] },
|
250
250
|
{ key: nil, values: [
|
251
251
|
{key: :count, value: 2 },
|
252
252
|
{key: :total_likes, value: 5 },
|
253
|
-
{key: :mean_likes, value:
|
253
|
+
{key: :mean_likes, value: "2.5" },
|
254
254
|
{key: :min_likes, value: 2 },
|
255
255
|
{key: :max_likes, value: 3 }
|
256
256
|
] }
|
257
257
|
]
|
258
258
|
|
259
|
-
expect_equal data_by(:published_at, bin_width:
|
259
|
+
expect_equal data_by(:published_at, bin_width: "1 month", sort_desc: true), [
|
260
260
|
{ key: nov, values: [
|
261
261
|
{ key: :count, value: 3 },
|
262
262
|
{ key: :total_likes, value: 7 },
|
263
|
-
{ key: :mean_likes, value:
|
263
|
+
{ key: :mean_likes, value: "2.3333333333333333" },
|
264
264
|
{ key: :min_likes, value: 1 },
|
265
265
|
{ key: :max_likes, value: 3 }
|
266
266
|
] },
|
267
267
|
{ key: oct, values: [
|
268
268
|
{ key: :count, value: 4 },
|
269
269
|
{ key: :total_likes, value: 7 },
|
270
|
-
{ key: :mean_likes, value:
|
270
|
+
{ key: :mean_likes, value: "1.75" },
|
271
271
|
{ key: :min_likes, value: 1 },
|
272
272
|
{ key: :max_likes, value: 2 }
|
273
273
|
] },
|
274
274
|
{ key: nil, values: [
|
275
275
|
{ key: :count, value: 2 },
|
276
276
|
{ key: :total_likes, value: 6 },
|
277
|
-
{ key: :mean_likes, value:
|
277
|
+
{ key: :mean_likes, value: "3.0" },
|
278
278
|
{ key: :min_likes, value: 3 },
|
279
279
|
{ key: :max_likes, value: 3 }
|
280
280
|
] }
|
@@ -285,21 +285,21 @@ describe 'more complicated case' do
|
|
285
285
|
{ key: joyce.name, values: [
|
286
286
|
{ key: :count, value: 4 },
|
287
287
|
{ key: :total_likes, value: 7 },
|
288
|
-
{ key: :mean_likes, value:
|
288
|
+
{ key: :mean_likes, value: "1.75" },
|
289
289
|
{ key: :min_likes, value: 1 },
|
290
290
|
{ key: :max_likes, value: 3 }
|
291
291
|
] },
|
292
292
|
{ key: woolf.name, values: [
|
293
293
|
{ key: :count, value: 3 },
|
294
294
|
{ key: :total_likes, value: 8 },
|
295
|
-
{ key: :mean_likes, value:
|
295
|
+
{ key: :mean_likes, value: "2.6666666666666667" },
|
296
296
|
{ key: :min_likes, value: 2 },
|
297
297
|
{ key: :max_likes, value: 3 }
|
298
298
|
] },
|
299
299
|
{ key: nil, values: [
|
300
300
|
{ key: :count, value: 2 },
|
301
301
|
{ key: :total_likes, value: 5 },
|
302
|
-
{ key: :mean_likes, value:
|
302
|
+
{ key: :mean_likes, value: "2.5" },
|
303
303
|
{ key: :min_likes, value: 2 },
|
304
304
|
{ key: :max_likes, value: 3 }
|
305
305
|
] }
|
@@ -309,69 +309,69 @@ describe 'more complicated case' do
|
|
309
309
|
{ key: nil, values: [
|
310
310
|
{ key: :count, value: 2 },
|
311
311
|
{ key: :total_likes, value: 5 },
|
312
|
-
{ key: :mean_likes, value:
|
312
|
+
{ key: :mean_likes, value: "2.5" },
|
313
313
|
{ key: :min_likes, value: 2 },
|
314
314
|
{ key: :max_likes, value: 3 }
|
315
315
|
] },
|
316
316
|
{ key: woolf.name, values: [
|
317
317
|
{ key: :count, value: 3 },
|
318
318
|
{ key: :total_likes, value: 8 },
|
319
|
-
{ key: :mean_likes, value:
|
319
|
+
{ key: :mean_likes, value: "2.6666666666666667" },
|
320
320
|
{ key: :min_likes, value: 2 },
|
321
321
|
{ key: :max_likes, value: 3 }
|
322
322
|
] },
|
323
323
|
{ key: joyce.name, values: [
|
324
324
|
{ key: :count, value: 4 },
|
325
325
|
{ key: :total_likes, value: 7 },
|
326
|
-
{ key: :mean_likes, value:
|
326
|
+
{ key: :mean_likes, value: "1.75" },
|
327
327
|
{ key: :min_likes, value: 1 },
|
328
328
|
{ key: :max_likes, value: 3 }
|
329
329
|
] }
|
330
330
|
]
|
331
331
|
|
332
|
-
expect_equal data_by(:published_at, bin_width:
|
332
|
+
expect_equal data_by(:published_at, bin_width: "1 month", nulls_last: true), [
|
333
333
|
{ key: oct, values: [
|
334
334
|
{ key: :count, value: 4 },
|
335
335
|
{ key: :total_likes, value: 7 },
|
336
|
-
{ key: :mean_likes, value:
|
336
|
+
{ key: :mean_likes, value: "1.75" },
|
337
337
|
{ key: :min_likes, value: 1 },
|
338
338
|
{ key: :max_likes, value: 2 }
|
339
339
|
] },
|
340
340
|
{ key: nov, values: [
|
341
341
|
{ key: :count, value: 3 },
|
342
342
|
{ key: :total_likes, value: 7 },
|
343
|
-
{ key: :mean_likes, value:
|
343
|
+
{ key: :mean_likes, value: "2.3333333333333333" },
|
344
344
|
{ key: :min_likes, value: 1 },
|
345
345
|
{ key: :max_likes, value: 3 }
|
346
346
|
] },
|
347
347
|
{ key: nil, values: [
|
348
348
|
{ key: :count, value: 2 },
|
349
349
|
{ key: :total_likes, value: 6 },
|
350
|
-
{ key: :mean_likes, value:
|
350
|
+
{ key: :mean_likes, value: "3.0" },
|
351
351
|
{ key: :min_likes, value: 3 },
|
352
352
|
{ key: :max_likes, value: 3 }
|
353
353
|
] }
|
354
354
|
]
|
355
355
|
|
356
|
-
expect_equal data_by(:published_at, bin_width:
|
356
|
+
expect_equal data_by(:published_at, bin_width: "1 month", sort_desc: true, nulls_last: true), [
|
357
357
|
{ key: nil, values: [
|
358
358
|
{ key: :count, value: 2 },
|
359
359
|
{ key: :total_likes, value: 6 },
|
360
|
-
{ key: :mean_likes, value:
|
360
|
+
{ key: :mean_likes, value: "3.0" },
|
361
361
|
{ key: :min_likes, value: 3 },
|
362
362
|
{ key: :max_likes, value: 3 }
|
363
363
|
] },
|
364
364
|
{ key: nov, values: [
|
365
365
|
{ key: :count, value: 3 },
|
366
366
|
{ key: :total_likes, value: 7 },
|
367
|
-
{ key: :mean_likes, value:
|
367
|
+
{ key: :mean_likes, value: "2.3333333333333333" },
|
368
368
|
{ key: :min_likes, value: 1 },
|
369
369
|
{ key: :max_likes, value: 3 }
|
370
370
|
] },
|
371
371
|
{ key: oct, values: [
|
372
372
|
{ key: :count, value: 4 },
|
373
373
|
{ key: :total_likes, value: 7 },
|
374
|
-
{ key: :mean_likes, value:
|
374
|
+
{ key: :mean_likes, value: "1.75" },
|
375
375
|
{ key: :min_likes, value: 1 },
|
376
376
|
{ key: :max_likes, value: 2 }
|
377
377
|
] }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveReporter::Aggregator do
|
4
4
|
let(:report_model) do
|
@@ -17,22 +17,22 @@ describe ActiveReporter::Aggregator do
|
|
17
17
|
|
18
18
|
let(:report) { report_model.new(aggregators: aggregators, groupers: [:author, :status]) }
|
19
19
|
|
20
|
-
let!(:post_1) { create(:post, likes: 3, author:
|
21
|
-
let!(:post_2) { create(:post, likes: 2, author:
|
22
|
-
let!(:post_3) { create(:post, likes: 4, author:
|
23
|
-
let!(:post_4) { create(:post, likes: 1, author:
|
24
|
-
let!(:post_5) { create(:post, likes: 5, author:
|
25
|
-
let!(:post_6) { create(:post, likes: 10, author:
|
20
|
+
let!(:post_1) { create(:post, likes: 3, author: "Alice") }
|
21
|
+
let!(:post_2) { create(:post, likes: 2, author: "Alice") }
|
22
|
+
let!(:post_3) { create(:post, likes: 4, author: "Bob") }
|
23
|
+
let!(:post_4) { create(:post, likes: 1, author: "Bob") }
|
24
|
+
let!(:post_5) { create(:post, likes: 5, author: "Bob") }
|
25
|
+
let!(:post_6) { create(:post, likes: 10, author: "Chester") }
|
26
26
|
|
27
|
-
context
|
27
|
+
context "aggregating post_ids" do
|
28
28
|
let(:aggregators) { :post_ids }
|
29
29
|
|
30
|
-
it
|
30
|
+
it "should return post_ids values" do
|
31
31
|
if ActiveReporter.database_type == :postgres
|
32
32
|
expect(report.raw_data).to eq({
|
33
|
-
[
|
34
|
-
[
|
35
|
-
[
|
33
|
+
["Alice", "published", "post_ids"] => [post_1.id, post_2.id],
|
34
|
+
["Bob", "published", "post_ids"] => [post_3.id, post_4.id, post_5.id],
|
35
|
+
["Chester", "published", "post_ids"] => [post_6.id],
|
36
36
|
})
|
37
37
|
else
|
38
38
|
expect { report.raw_data }.to raise_error(ActiveReporter::InvalidParamsError)
|
@@ -40,62 +40,62 @@ describe ActiveReporter::Aggregator do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context
|
43
|
+
context "aggregating max_likes" do
|
44
44
|
let(:aggregators) { :max_likes }
|
45
45
|
|
46
|
-
it
|
46
|
+
it "should return max_likes values" do
|
47
47
|
expect(report.raw_data).to eq({
|
48
|
-
[
|
49
|
-
[
|
50
|
-
[
|
48
|
+
["Alice", "published", "max_likes"] => 3,
|
49
|
+
["Bob", "published", "max_likes"] => 5,
|
50
|
+
["Chester", "published", "max_likes"] => 10,
|
51
51
|
})
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
context
|
55
|
+
context "aggregating min_likes" do
|
56
56
|
let(:aggregators) { :min_likes }
|
57
57
|
|
58
|
-
it
|
58
|
+
it "should return min_likes values" do
|
59
59
|
expect(report.raw_data).to eq({
|
60
|
-
[
|
61
|
-
[
|
62
|
-
[
|
60
|
+
["Alice", "published", "min_likes"] => 2,
|
61
|
+
["Bob", "published", "min_likes"] => 1,
|
62
|
+
["Chester", "published", "min_likes"] => 10
|
63
63
|
})
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
context
|
67
|
+
context "aggregating mean_likes" do
|
68
68
|
let(:aggregators) { :mean_likes }
|
69
69
|
|
70
|
-
it
|
70
|
+
it "should return mean_likes values" do
|
71
71
|
expect(report.raw_data.collect{ |k,v| [k, v.round(2)] }.to_h).to eq({
|
72
|
-
[
|
73
|
-
[
|
74
|
-
[
|
72
|
+
["Alice", "published", "mean_likes"] => 2.50,
|
73
|
+
["Bob", "published", "mean_likes"] => 3.33,
|
74
|
+
["Chester", "published", "mean_likes"] => 10.00,
|
75
75
|
})
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
context
|
79
|
+
context "aggregating total_likes" do
|
80
80
|
let(:aggregators) { :total_likes }
|
81
81
|
|
82
|
-
it
|
82
|
+
it "should return total_likes values" do
|
83
83
|
expect(report.raw_data).to eq({
|
84
|
-
[
|
85
|
-
[
|
86
|
-
[
|
84
|
+
["Alice", "published", "total_likes"] => 5,
|
85
|
+
["Bob", "published", "total_likes"] => 10,
|
86
|
+
["Chester", "published", "total_likes"] => 10
|
87
87
|
})
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
context
|
91
|
+
context "aggregating count" do
|
92
92
|
let(:aggregators) { :count }
|
93
93
|
|
94
|
-
it
|
94
|
+
it "should return count values" do
|
95
95
|
expect(report.raw_data).to eq({
|
96
|
-
[
|
97
|
-
[
|
98
|
-
[
|
96
|
+
["Alice", "published", "count"] => 2,
|
97
|
+
["Bob", "published", "count"] => 3,
|
98
|
+
["Chester", "published", "count"] => 1
|
99
99
|
})
|
100
100
|
end
|
101
101
|
end
|