Sha256: 6f85dbb287217e16fef00cb5c7086d344ae81c3f0c3654221d9816c2d94e387a

Contents?: true

Size: 1.5 KB

Versions: 10

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe ActiveReporter::Serializer::HashTable do
  let(:report_model) do
    Class.new(ActiveReporter::Report) do
      report_on :Post
      number_dimension :likes
      time_dimension :created_at
      category_dimension :title
      count_aggregator :post_count
      sum_aggregator :likes_count, attribute: :likes
    end
  end

  let(:report) do
    report_model.new(
      aggregators: [:post_count, :likes_count],
      groupers: %i[title created_at],
      dimensions: { created_at: { bin_width: '1 day' } }
    )
  end

  let(:hash_table) do
    ActiveReporter::Serializer::HashTable.new(report)
  end

  before do
    create(:post, created_at: '2016-01-01', likes: 2, title: 'A')
    create(:post, created_at: '2016-01-01', likes: 2, title: 'A')
    create(:post, created_at: '2016-01-01', likes: 1, title: 'B')
    create(:post, created_at: '2016-01-02', likes: 1, title: 'A')
  end

  describe '#report' do
    it 'builds report' do
      expect(hash_table.table).to eq [
        { title: 'Title', created_at: 'Created at', post_count: 'Post count', likes_count: 'Likes count' },
        { title: 'A', created_at: '2016-01-01 00:00:00 UTC', post_count: '2', likes_count: '4' },
        { title: 'A', created_at: '2016-01-02 00:00:00 UTC', post_count: '1', likes_count: '1' },
        { title: 'B', created_at: '2016-01-01 00:00:00 UTC', post_count: '1', likes_count: '1' },
        { title: 'B', created_at: '2016-01-02 00:00:00 UTC', post_count: '0', likes_count: '0' }
      ]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_reporter-0.6.3 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.6.2 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.6.1 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.6.0 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.5.13 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.5.12 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.5.11 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.5.10 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.5.9 spec/active_reporter/serializer/hash_table_spec.rb
active_reporter-0.5.8 spec/active_reporter/serializer/hash_table_spec.rb