Sha256: 1fa78e9fb79b0b32db71fac059e530e117db6d907de0ced7737f92f2e85e9a97

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Rating::Rating, ':averager_data' do
  subject { described_class.averager_data article_1 }

  let!(:user_1) { create :user }
  let!(:user_2) { create :user }

  let!(:article_1) { create :article }
  let!(:article_2) { create :article }
  let!(:article_3) { create :article }

  before do
    create :rating_rate, author: user_1, resource: article_1, value: 100
    create :rating_rate, author: user_1, resource: article_2, value: 11
    create :rating_rate, author: user_1, resource: article_3, value: 10
    create :rating_rate, author: user_2, resource: article_1, value: 1
  end

  it 'returns the values average of given resource type' do
    expect(subject.as_json['rating_avg']).to eq 30.5
  end

  it 'returns the average of number of records for the given resource type' do
    expect(subject.as_json['count_avg']).to eq 1.3333333333333333
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rating-0.1.0 spec/models/rating/averager_data_spec.rb