Sha256: b6c8c1fde1776d8d03103a50745271297e146ef189efde1f71e5ae8af3e20504

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 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_s).to eq '42.5000000000000000012000000505'
    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

8 entries across 8 versions & 1 rubygems

Version Path
rating-0.11.0 spec/models/rating/data_spec.rb
rating-0.10.0 spec/models/rating/data_spec.rb
rating-0.9.0 spec/models/rating/data_spec.rb
rating-0.8.0 spec/models/rating/data_spec.rb
rating-0.7.0 spec/models/rating/data_spec.rb
rating-0.6.0 spec/models/rating/data_spec.rb
rating-0.5.0 spec/models/rating/data_spec.rb
rating-0.4.0 spec/models/rating/data_spec.rb