Sha256: 9c73d23f157fd68e9a80eddc817a4eefe77b103f4f7a75daf21859754bd05fb3

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'support/shared_context/with_database_records'

RSpec.describe Rating::Rating, ':data' do
  include_context 'with_database_records'

  context 'with no scopeable' do
    subject(:result) { described_class.data article_1, nil }

    it 'returns the average of value for a resource' do
      expect(result[:average]).to eq 50.5
    end

    it 'returns the sum of values for a resource' do
      expect(result[:sum]).to eq 101
    end

    it 'returns the count of votes for a resource' do
      expect(result[:total]).to eq 2
    end

    it 'returns the estimate for a resource' do
      expect(result[:estimate]).to eq 42.50000000000001
    end
  end

  context 'with scopeable' do
    subject(:result) { described_class.data article_1, category }

    it 'returns the average of value for a resource' do
      expect(result[:average]).to eq 1.5
    end

    it 'returns the sum of values for a resource' do
      expect(result[:sum]).to eq 3
    end

    it 'returns the count of votes for a resource' do
      expect(result[:total]).to eq 2
    end

    it 'returns the estimate for a resource' do
      expect(result[:estimate]).to eq 1.5
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rating-0.3.0 spec/models/rating/data_spec.rb