Sha256: ff9cfeb807ae0d394c03156e725d13eea96378715941ce2b736a7302572058ea
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 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 aggregation_field :field1 column 'dynamic-field1' => ->(context, row) { row['field1'] * 10 } 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) example = report_klass.new scope = example.aggregate scope = scope.all rows = scope['example-models'] 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid-report-0.1.6 | spec/mongoid/report/column_spec.rb |
mongoid-report-0.1.5 | spec/mongoid/report/column_spec.rb |