Sha256: 1340ff37a83837d66143b806ed40f01a58cef1fd521a002757b4664e910c35cb

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe Mongoid::Report do

  describe '.aggregation_field' do
    it 'defines field for aggregation using class method' do
      example = Report1.new
      expect(example).to be_respond_to(:field1)
    end

    it 'defines as reader only' do
      example = Report1.new
      expect{ example.field1 = 'value' }.to raise_error
    end

    it 'defines field with 0 by default' do
      example = Report1.new
      expect(example.field1).to eq(0)
    end

    it 'defines aggegration settings' do
      expect(Report1).to be_respond_to(:settings)
    end

    it 'defines aggregation field for specific model to make queries' do
      fields = Report1.fields(Model)
      expect(fields).to eq([:field1])
    end
  end

  describe '.attach_to' do
    it 'defines method in report class to attach report to the model' do
      expect(Report2).to be_respond_to(:attach_to)
    end

    it 'defines field in terms of attached model' do
      fields = Report2.fields(Model)
      expect(fields).to eq([:field1])
    end
  end

  describe '.group_by' do
    it 'defines group by method as class method' do
      expect(Report3).to be_respond_to(:group_by)
    end

    it 'stores group by settings under report class' do
      group_by_settings = Report3.settings[Model][:group_by]
      expect(group_by_settings).to eq([:day])
    end

    it 'defines groups in terms of attached model' do
      groups = Report4.groups(Model)
      expect(groups).to eq([:day])
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-report-0.0.5 spec/mongoid/report_spec.rb