Sha256: a373362289dc4a0411e3c74f663de7da71b4bde36ed69db86f9c035fd051d045

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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

RSpec.describe Rating::Rating, ':update_rating' do
  context 'with no scopeable' do
    include_context 'with_database_records'

    it 'updates the rating data of the given resource' do
      record = described_class.find_by(resource: article_1)

      expect(record.average).to  eq 50.5
      expect(record.estimate).to eq 42.5
      expect(record.sum).to      eq 101
      expect(record.total).to    eq 2
    end
  end

  context 'with scopeable' do
    include_context 'with_database_records'

    it 'updates the rating data of the given resource respecting the scope' do
      record = described_class.find_by(resource: article_1, scopeable: category)

      expect(record.average).to  eq 1.5
      expect(record.estimate).to eq 1.5
      expect(record.sum).to      eq 3
      expect(record.total).to    eq 2
    end
  end

  context 'when rate table has no record' do
    let!(:resource) { create :article }
    let!(:scope)    { nil }

    it 'calculates with counts values as zero' do
      described_class.update_rating resource, scope

      record = described_class.last

      expect(record.average).to  eq 0
      expect(record.estimate).to eq 0
      expect(record.sum).to      eq 0
      expect(record.total).to    eq 0
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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