Sha256: 503189fb3a4ecad386cb3e6f834ca0feee0426e4027cdc7e23e0059ed04945b1

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

describe ActiveHashRelation do
  include Helpers

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

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

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

        aggregations = HelperClass.new.aggregations(Micropost.all, hash)
        expected_aggregations = HashWithIndifferentAccess.new({
          likes: {
            min: Micropost.pluck(:likes).min
          },
          reposts: {
            min: Micropost.pluck(:reposts).min
          },
          created_at: {
            min: Micropost.pluck(:created_at).min.to_time
          }
        })
        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/min_spec.rb
active_hash_relation-1.4.0 spec/tests/aggregations/min_spec.rb
active_hash_relation-1.2.0 spec/tests/aggregations/min_spec.rb