flatten_record 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flatten_record/definition.rb +16 -11
- data/lib/flatten_record/meta/id_column.rb +1 -2
- data/lib/flatten_record/meta/normalized_attr.rb +52 -35
- data/lib/flatten_record/version.rb +1 -1
- data/lib/generators/flatten_record/migration/migration_generator.rb +76 -62
- data/spec/dummy/log/test.log +14730 -0
- data/spec/lib/flatten_record/flattener/denormalize_spec.rb +61 -0
- data/spec/support/flattener.rb +2 -0
- metadata +1 -1
@@ -134,6 +134,67 @@ describe FlattenRecord::Flattener do
|
|
134
134
|
|
135
135
|
end
|
136
136
|
end #/context
|
137
|
+
|
138
|
+
context 'when :except option is defined' do
|
139
|
+
let(:klass) do
|
140
|
+
Order.class_eval { def grand_total;50;end }
|
141
|
+
|
142
|
+
Denormalized.class_eval do
|
143
|
+
denormalize :order, {
|
144
|
+
compute: [:total_in_usd],
|
145
|
+
methods: [:grand_total],
|
146
|
+
include: {
|
147
|
+
customer: {
|
148
|
+
include: {
|
149
|
+
children: {
|
150
|
+
except: [:name],
|
151
|
+
include: {
|
152
|
+
cats: {
|
153
|
+
except: [:name],
|
154
|
+
include: {
|
155
|
+
owner: { class_name: 'Child', except: [:name] }
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
},
|
163
|
+
}
|
164
|
+
def compute_total_in_usd(item);1000;end
|
165
|
+
end
|
166
|
+
|
167
|
+
Denormalized
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should construct columns' do
|
171
|
+
meta = klass.flattener_meta
|
172
|
+
expect(meta).to_not be_nil
|
173
|
+
|
174
|
+
expect(meta.all_columns).to_not be_empty
|
175
|
+
column_names = meta.all_columns.map(&:name)
|
176
|
+
|
177
|
+
expect(column_names.count).to eq(15)
|
178
|
+
|
179
|
+
expect(column_names).to be_include("order_id")
|
180
|
+
expect(column_names).to be_include("total")
|
181
|
+
expect(column_names).to be_include("grand_total")
|
182
|
+
expect(column_names).to be_include("total_in_usd")
|
183
|
+
expect(column_names).to be_include("customer_id")
|
184
|
+
expect(column_names).to be_include("customer_name")
|
185
|
+
expect(column_names).to be_include("customer_child_id")
|
186
|
+
expect(column_names).to be_include("customer_child_parent_id")
|
187
|
+
expect(column_names).to be_include("customer_child_description")
|
188
|
+
expect(column_names).to be_include("customer_child_cat_id")
|
189
|
+
expect(column_names).to be_include("customer_child_cat_description")
|
190
|
+
expect(column_names).to be_include("customer_child_cat_owner_type")
|
191
|
+
expect(column_names).to be_include("customer_child_cat_owner_child_id")
|
192
|
+
expect(column_names).to be_include("customer_child_cat_owner_child_parent_id")
|
193
|
+
expect(column_names).to be_include("customer_child_cat_owner_child_description")
|
194
|
+
end
|
195
|
+
end #/context
|
196
|
+
|
197
|
+
|
137
198
|
|
138
199
|
|
139
200
|
end
|
data/spec/support/flattener.rb
CHANGED
@@ -14,10 +14,12 @@ class FlattenRecord::Flattener::Test
|
|
14
14
|
end
|
15
15
|
create_table :children do |t|
|
16
16
|
t.string :name
|
17
|
+
t.string :description
|
17
18
|
t.integer :parent_id
|
18
19
|
end
|
19
20
|
create_table :cats do |t|
|
20
21
|
t.string :name
|
22
|
+
t.string :description
|
21
23
|
t.string :owner_type
|
22
24
|
t.integer :owner_id
|
23
25
|
end
|