mongoid-report 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +30 -18
- data/README.md +6 -36
- data/lib/mongoid/report/attach_proxy.rb +26 -5
- data/lib/mongoid/report/batches.rb +41 -0
- data/lib/mongoid/report/collection.rb +4 -3
- data/lib/mongoid/report/collections.rb +16 -0
- data/lib/mongoid/report/input.rb +17 -0
- data/lib/mongoid/report/merger.rb +29 -0
- data/lib/mongoid/report/output.rb +32 -0
- data/lib/mongoid/report/queries_builder.rb +14 -16
- data/lib/mongoid/report/report_proxy.rb +16 -4
- data/lib/mongoid/report/scope.rb +123 -17
- data/lib/mongoid/report/scope_collection.rb +16 -10
- data/lib/mongoid/report/version.rb +1 -1
- data/lib/mongoid/report.rb +180 -61
- data/spec/mongoid/report/aggregation_spec.rb +72 -57
- data/spec/mongoid/report/attach_to_spec.rb +16 -0
- data/spec/mongoid/report/collection_spec.rb +12 -7
- data/spec/mongoid/report/column_spec.rb +1 -1
- data/spec/mongoid/report/dynamic_attach_to_spec.rb +86 -0
- data/spec/mongoid/report/integration_spec.rb +129 -0
- data/spec/mongoid/report/module_configuration_spec.rb +35 -0
- data/spec/mongoid/report/out_spec.rb +122 -0
- data/spec/mongoid/report/queries_builder_spec.rb +54 -16
- data/spec/mongoid/report/set_spec.rb +3 -3
- data/spec/mongoid/report/summary_spec.rb +87 -16
- data/spec/mongoid/report/threads_spec.rb +132 -4
- data/spec/mongoid/report_spec.rb +58 -34
- data/spec/spec_helper.rb +2 -0
- metadata +17 -2
data/spec/mongoid/report_spec.rb
CHANGED
@@ -5,8 +5,9 @@ describe Mongoid::Report do
|
|
5
5
|
describe '.column' do
|
6
6
|
let(:report_klass) do
|
7
7
|
Class.new do
|
8
|
+
def self.name ; 'report-klass' ; end
|
8
9
|
include Mongoid::Report
|
9
|
-
column :field1,
|
10
|
+
column :field1, collection: Model
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -15,15 +16,16 @@ describe Mongoid::Report do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'defines aggregation field for specific model to make queries' do
|
18
|
-
fields = report_klass.fields
|
19
|
-
expect(fields).to eq(
|
19
|
+
fields = report_klass.settings['report-klass'][:reports]['models'][:fields]
|
20
|
+
expect(fields).to eq(['field1'])
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
describe '.attach_to' do
|
24
25
|
let(:report_klass) do
|
25
26
|
Class.new do
|
26
27
|
include Mongoid::Report
|
28
|
+
def self.name ; 'report-klass' ; end
|
27
29
|
attach_to Model do
|
28
30
|
column :field1
|
29
31
|
end
|
@@ -35,8 +37,8 @@ describe Mongoid::Report do
|
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'defines field in terms of attached model' do
|
38
|
-
fields = report_klass.fields
|
39
|
-
expect(fields).to eq(
|
40
|
+
fields = report_klass.settings['report-klass'][:reports]['models'][:fields]
|
41
|
+
expect(fields).to eq(['field1'])
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
@@ -44,8 +46,9 @@ describe Mongoid::Report do
|
|
44
46
|
let(:report_klass1) do
|
45
47
|
Class.new do
|
46
48
|
include Mongoid::Report
|
47
|
-
|
48
|
-
|
49
|
+
def self.name ; 'report-klass' ; end
|
50
|
+
group_by :day, collection: Model
|
51
|
+
column :field1, collection: Model
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -54,13 +57,14 @@ describe Mongoid::Report do
|
|
54
57
|
end
|
55
58
|
|
56
59
|
it 'stores group by settings under report class' do
|
57
|
-
|
58
|
-
expect(
|
60
|
+
settings = report_klass1.settings['report-klass'][:reports]['models'][:group_by]
|
61
|
+
expect(settings).to eq(['day'])
|
59
62
|
end
|
60
63
|
|
61
64
|
let(:report_klass2) do
|
62
65
|
Class.new do
|
63
66
|
include Mongoid::Report
|
67
|
+
def self.name ; 'report-klass' ; end
|
64
68
|
attach_to Model do
|
65
69
|
group_by :day
|
66
70
|
column :field1
|
@@ -69,8 +73,8 @@ describe Mongoid::Report do
|
|
69
73
|
end
|
70
74
|
|
71
75
|
it 'defines groups in terms of attached model' do
|
72
|
-
|
73
|
-
expect(
|
76
|
+
settings = report_klass2.settings['report-klass'][:reports]['models'][:group_by]
|
77
|
+
expect(settings).to eq(['day'])
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
@@ -78,6 +82,7 @@ describe Mongoid::Report do
|
|
78
82
|
let(:report_klass) do
|
79
83
|
Class.new do
|
80
84
|
include Mongoid::Report
|
85
|
+
def self.name ; 'report-klass' ; end
|
81
86
|
attach_to Model, as: 'example1' do
|
82
87
|
column :field1
|
83
88
|
end
|
@@ -85,7 +90,7 @@ describe Mongoid::Report do
|
|
85
90
|
end
|
86
91
|
|
87
92
|
it 'creates settings with "as" name' do
|
88
|
-
expect(report_klass.settings).to have_key('example1')
|
93
|
+
expect(report_klass.settings['report-klass'][:reports]).to have_key('example1')
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
@@ -106,45 +111,33 @@ describe Mongoid::Report do
|
|
106
111
|
end
|
107
112
|
|
108
113
|
it 'creates settings with report-<attached-model-name' do
|
109
|
-
|
110
|
-
expect(
|
114
|
+
reports = report_klass.settings['example'][:reports].keys
|
115
|
+
expect(reports).to include('model1')
|
116
|
+
expect(reports).to include('models')
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
describe '.column `as` option' do
|
115
|
-
let(:report_klass) do
|
116
|
-
Class.new do
|
117
|
-
include Mongoid::Report
|
118
|
-
column :field1, for: Model, as: 'field-name'
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'creates settings with report-<attached-model-name' do
|
123
|
-
expect(report_klass.fields(Model).keys).to eq(['field1'])
|
124
|
-
expect(report_klass.fields(Model).values).to eq(['field-name'])
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
120
|
describe 'two report classes' do
|
130
121
|
it 'should have different settings' do
|
131
|
-
|
122
|
+
report_klass1 = Class.new do
|
132
123
|
include Mongoid::Report
|
124
|
+
def self.name ; 'report-klass1' ; end
|
133
125
|
|
134
126
|
attach_to Model do
|
135
127
|
column :field1
|
136
128
|
end
|
137
129
|
end
|
138
130
|
|
139
|
-
|
131
|
+
report_klass2 = Class.new do
|
140
132
|
include Mongoid::Report
|
133
|
+
def self.name ; 'report-klass2' ; end
|
141
134
|
|
142
135
|
attach_to Model do
|
143
136
|
column :field2
|
144
137
|
end
|
145
138
|
end
|
146
139
|
|
147
|
-
expect(
|
140
|
+
expect(report_klass1.settings).not_to eq(report_klass2.settings)
|
148
141
|
end
|
149
142
|
|
150
143
|
class ReportKlass
|
@@ -164,7 +157,38 @@ describe Mongoid::Report do
|
|
164
157
|
end
|
165
158
|
|
166
159
|
it 'should have different settings for inherited classes' do
|
167
|
-
|
160
|
+
settings1 = ReportKlass1.settings['ReportKlass1'][:reports]['models']
|
161
|
+
settings2 = ReportKlass2.settings['ReportKlass2'][:reports]['models']
|
162
|
+
expect(settings1).not_to eq(settings2)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'empty matchs' do
|
167
|
+
it 'should work fine with passed empty match value' do
|
168
|
+
report_klass = Class.new do
|
169
|
+
include Mongoid::Report
|
170
|
+
|
171
|
+
report 'example' do
|
172
|
+
attach_to 'models' do
|
173
|
+
match field1: {}
|
174
|
+
match field2: 1
|
175
|
+
match field3: { '$in' => [1,2,3] }
|
176
|
+
column :field1, :field2, :field3
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
Model.create(field1: 1, field2: 2, field3: 1)
|
182
|
+
Model.create(field1: 1, field2: 1, field3: 2)
|
183
|
+
Model.create(field1: 1, field2: 1, field3: 4)
|
184
|
+
|
185
|
+
report = report_klass.new
|
186
|
+
scope = report.aggregate_for('example', 'models').all
|
187
|
+
|
188
|
+
expect(scope.rows.size).to eq(1)
|
189
|
+
expect(scope.rows[0]['field1']).to eq(1)
|
190
|
+
expect(scope.rows[0]['field2']).to eq(1)
|
191
|
+
expect(scope.rows[0]['field3']).to eq(2)
|
168
192
|
end
|
169
193
|
end
|
170
194
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Korsak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -73,8 +73,13 @@ files:
|
|
73
73
|
- Rakefile
|
74
74
|
- lib/mongoid/report.rb
|
75
75
|
- lib/mongoid/report/attach_proxy.rb
|
76
|
+
- lib/mongoid/report/batches.rb
|
76
77
|
- lib/mongoid/report/collection.rb
|
78
|
+
- lib/mongoid/report/collections.rb
|
77
79
|
- lib/mongoid/report/config.rb
|
80
|
+
- lib/mongoid/report/input.rb
|
81
|
+
- lib/mongoid/report/merger.rb
|
82
|
+
- lib/mongoid/report/output.rb
|
78
83
|
- lib/mongoid/report/queries_builder.rb
|
79
84
|
- lib/mongoid/report/report_proxy.rb
|
80
85
|
- lib/mongoid/report/scope.rb
|
@@ -82,9 +87,14 @@ files:
|
|
82
87
|
- lib/mongoid/report/version.rb
|
83
88
|
- mongoid-report.gemspec
|
84
89
|
- spec/mongoid/report/aggregation_spec.rb
|
90
|
+
- spec/mongoid/report/attach_to_spec.rb
|
85
91
|
- spec/mongoid/report/collection_spec.rb
|
86
92
|
- spec/mongoid/report/column_spec.rb
|
87
93
|
- spec/mongoid/report/config_spec.rb
|
94
|
+
- spec/mongoid/report/dynamic_attach_to_spec.rb
|
95
|
+
- spec/mongoid/report/integration_spec.rb
|
96
|
+
- spec/mongoid/report/module_configuration_spec.rb
|
97
|
+
- spec/mongoid/report/out_spec.rb
|
88
98
|
- spec/mongoid/report/queries_builder_spec.rb
|
89
99
|
- spec/mongoid/report/set_spec.rb
|
90
100
|
- spec/mongoid/report/summary_spec.rb
|
@@ -118,9 +128,14 @@ specification_version: 4
|
|
118
128
|
summary: Easily build mongoid reports using aggregation framework
|
119
129
|
test_files:
|
120
130
|
- spec/mongoid/report/aggregation_spec.rb
|
131
|
+
- spec/mongoid/report/attach_to_spec.rb
|
121
132
|
- spec/mongoid/report/collection_spec.rb
|
122
133
|
- spec/mongoid/report/column_spec.rb
|
123
134
|
- spec/mongoid/report/config_spec.rb
|
135
|
+
- spec/mongoid/report/dynamic_attach_to_spec.rb
|
136
|
+
- spec/mongoid/report/integration_spec.rb
|
137
|
+
- spec/mongoid/report/module_configuration_spec.rb
|
138
|
+
- spec/mongoid/report/out_spec.rb
|
124
139
|
- spec/mongoid/report/queries_builder_spec.rb
|
125
140
|
- spec/mongoid/report/set_spec.rb
|
126
141
|
- spec/mongoid/report/summary_spec.rb
|