Sha256: b1d282c59404b4fdd6c83b9bb29b7d699934af6a6585a9224aa4f4edba915b40

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

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

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

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

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

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

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

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

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rating-0.8.0 spec/models/rating/values_data_spec.rb
rating-0.7.0 spec/models/rating/values_data_spec.rb
rating-0.6.0 spec/models/rating/values_data_spec.rb
rating-0.5.0 spec/models/rating/values_data_spec.rb
rating-0.4.0 spec/models/rating/values_data_spec.rb
rating-0.3.0 spec/models/rating/values_data_spec.rb