Sha256: 96bc23a235a3c8d30bff12f6becc01b67ea038c46624a9d24a0bbcb9c3986427

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 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_f.to_s).to eq '50.5'
    end

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

    it 'returns the count of votes for a resource' do
      expect(result.as_json['rating_count'].to_f.to_s).to eq '2.0'
    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_f.to_s).to eq '1.5'
    end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rating-0.11.0 spec/models/rating/values_data_spec.rb
rating-0.10.0 spec/models/rating/values_data_spec.rb
rating-0.9.0 spec/models/rating/values_data_spec.rb