spec/mongoid/report/summary_spec.rb in mongoid-report-0.1.3 vs spec/mongoid/report/summary_spec.rb in mongoid-report-0.1.5
- old
+ new
@@ -18,8 +18,32 @@
expect(rows.count).to eq(2)
expect(rows.summary[:field1]).to eq(3)
expect(rows.summary['field1']).to eq(3)
end
+
+ it 'should support dynamic columns as well' do
+ Report = Class.new do
+ include Mongoid::Report
+
+ report 'example' do
+ attach_to Model do
+ aggregation_field :field1
+ column 'new-field1' => ->(context, row) { row['field1'] * 10 }
+ end
+ end
+ end
+
+ klass.create!(field1: 1)
+ klass.create!(field1: 1)
+ klass.create!(field1: 1)
+
+ example = Report.new
+ rows = example.aggregate_for('example-models')
+ rows = rows.all
+
+ expect(rows[0]['field1']).to eq(3)
+ expect(rows[0]['new-field1']).to eq(30)
+ end
end
end