Sha256: aa3a078c6e7d79b06a02fdd250c367548e45ffc554694f1091f0ff0631c933c0

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

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

  before { user.rate article, 3 }

  it 'returns rates made by the caller' do
    expect(user.rated).to eq [Rating::Rate.find_by(resource: article)]
  end

  context 'when destroy author' do
    before do
      expect(Rating::Rate.where(author: user).count).to eq 1

      user.destroy!
    end

    it 'destroys rates of this author' do
      expect(Rating::Rate.where(author: user).count).to eq 0
    end
  end

  context 'when destroy resource rated by author' do
    before do
      expect(Rating::Rate.where(resource: article).count).to eq 1

      article.destroy!
    end

    it 'destroys rates for that resource' do
      expect(Rating::Rate.where(resource: article).count).to eq 0
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rating-0.1.0 spec/models/extension/rated_spec.rb