Sha256: 879230b24288d8918155c9313df9e472dc8ae5a81c3fbe2da73db0bccfac6458

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

describe ActiveHashRelation do
  include Helpers

  context 'aggregations' do
    context 'sum' do
      before do
        FactoryGirl.create_list(:micropost, 10)
      end

      it "one aggregation" do
        hash = { aggregate: {likes: {sum: true} } }

        aggregations = HelperClass.new.aggregations(Micropost.all, hash)
        expected_aggregations = HashWithIndifferentAccess.new({
          likes: {
            sum: Micropost.pluck(:likes).sum
          }
        })
        expect(aggregations).to eq expected_aggregations
      end
      it "multiple aggregations" do
        hash = {
          aggregate: {
            likes: {sum: true}, reposts: {sum: true}, created_at: {sum: true}
          }
        }

        aggregations = HelperClass.new.aggregations(Micropost.all, hash)
        expected_aggregations = HashWithIndifferentAccess.new({
          likes: {
            sum: Micropost.pluck(:likes).sum
          },
          reposts: {
            sum: Micropost.pluck(:reposts).sum
          },
          created_at: {}
        })
        expect(aggregations).to eq expected_aggregations
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_hash_relation-1.4.1 spec/tests/aggregations/sum_spec.rb
active_hash_relation-1.4.0 spec/tests/aggregations/sum_spec.rb
active_hash_relation-1.2.0 spec/tests/aggregations/sum_spec.rb