Sha256: b52e0a038c7e29436f3d4b187b8ef12a8e762b136abccf99d6dd6fa7ef6dc3f8

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

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

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

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

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

      specify { expect(user.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(user).to receive(:rate_for).with(article, scope: category) { nil } }

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rating-0.2.0 spec/models/extension/rated_question_spec.rb