Sha256: 0bf8458c789d4356cf445ff1fe54934ef9f17fa2cab75ccd9f494787a6174ddf
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
require 'spec_helper' describe Mongoid::Report do let(:klass) { Model } let(:yesterday) { Date.parse("19-12-2004") } let(:today) { Date.parse("20-12-2004") } let(:two_days_ago) { Date.parse("18-12-2004") } let(:report_klass) do Class.new do include Mongoid::Report report 'example' do attach_to Model do group_by :day columns :'dynamic-field1' => ->(context, row, options) { row['field1'] * 10 } column :field1, :'dynamic-field1' end end end end it 'calculates dynamic field for each row in the report' do klass.create(day: today , field1: 1) klass.create(day: yesterday , field1: 1) klass.create(day: today , field1: 1) report = report_klass.new scope = report.aggregate scope = scope.all rows = scope['example']['models'].rows expect(rows.size).to eq(2) expect(rows[0]['field1']).to eq(1) expect(rows[0]['dynamic-field1']).to eq(10) expect(rows[1]['field1']).to eq(2) expect(rows[1]['dynamic-field1']).to eq(20) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mongoid-report-0.2.2 | spec/mongoid/report/column_spec.rb |
mongoid-report-0.2.1 | spec/mongoid/report/column_spec.rb |
mongoid-report-0.2.0 | spec/mongoid/report/column_spec.rb |