Sha256: 49f391f65118bbd40f82bba53fd2a7f844ea097b164e5f4fe218d8ffa62e3810

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Rating::Rate, ':rate_for' do
  let!(:author)  { create :author }
  let!(:article) { create :article }

  context 'with no scopeable' do
    context 'when rate does not exist' do
      specify { expect(described_class.rate_for(author: author, resource: article)).to eq nil }
    end

    context 'when rate does not exist' do
      before { described_class.create author: author, metadata: {}, resource: article, value: 3 }

      it 'returns the record' do
        expect(described_class.rate_for(author: author, resource: article)).to eq described_class.last
      end
    end
  end

  context 'with scopeable' do
    let!(:category) { create :category }

    context 'when rate does not exist' do
      specify { expect(described_class.rate_for(author: author, resource: article, scopeable: category)).to eq nil }
    end

    context 'when rate does not exist' do
      before { described_class.create author: author, metadata: {}, resource: article, scopeable: category, value: 3 }

      it 'returns the record' do
        query = described_class.rate_for(author: author, resource: article, scopeable: category)

        expect(query).to eq described_class.last
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rating-0.6.0 spec/models/rate/rate_for_spec.rb
rating-0.5.0 spec/models/rate/rate_for_spec.rb
rating-0.4.0 spec/models/rate/rate_for_spec.rb
rating-0.3.0 spec/models/rate/rate_for_spec.rb