Sha256: 2c37c9c2e6f64f4301a75b2b72f543f8db6ba5553277db0a0f2288a57d5292a6
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true require 'rails_helper' RSpec.describe Rating::Rating, ':averager_data' do let!(:category) { create :category } 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 create :rating_rate, author: user_1, resource: article_1, scopeable: category, value: 1 create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 end context 'with no scopeable' do subject { described_class.averager_data article_1, nil } 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 context 'with scopeable' do subject { described_class.averager_data article_1, category } it 'returns the values average of given resource type' do expect(subject.as_json['rating_avg']).to eq 1.5 end it 'returns the average of number of records for the given resource type' do expect(subject.as_json['count_avg']).to eq 2 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rating-0.2.0 | spec/models/rating/averager_data_spec.rb |