Sha256: 91b4c44694984ae745d4d449a03571fe7478d281fbabcf4e301c8dd49f5fea26

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Rating::Extension, ':rated?' do
  let!(:author)  { create :author }
  let!(:article) { create :article }

  context 'with no scopeable' do
    context 'when has no rate for the given resource' do
      before { allow(author).to receive(:rate_for).with(article, scope: nil).and_return nil }

      specify { expect(author.rated?(article)).to eq false }
    end

    context 'when has rate for the given resource' do
      before { allow(author).to receive(:rate_for).with(article, scope: nil).and_return double }

      specify { expect(author.rated?(article)).to eq true }
    end
  end

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

    context 'when has no rate for the given resource' do
      before { allow(author).to receive(:rate_for).with(article, scope: category).and_return nil }

      specify { expect(author.rated?(article, scope: category)).to eq false }
    end

    context 'when has rate for the given resource' do
      before { allow(author).to receive(:rate_for).with(article, scope: category).and_return double }

      specify { expect(author.rated?(article, scope: category)).to eq true }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rating-0.6.0 spec/models/extension/rated_question_spec.rb
rating-0.5.0 spec/models/extension/rated_question_spec.rb
rating-0.4.0 spec/models/extension/rated_question_spec.rb
rating-0.3.0 spec/models/extension/rated_question_spec.rb