2017-10-30 01:44:23 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Rating::Extension, ':rated?' do
|
2018-01-16 03:14:05 +00:00
|
|
|
let!(:author) { create :author }
|
2017-10-30 01:44:23 +00:00
|
|
|
let!(:article) { create :article }
|
|
|
|
|
2017-11-02 18:55:46 +00:00
|
|
|
context 'with no scopeable' do
|
|
|
|
context 'when has no rate for the given resource' do
|
2018-01-16 03:14:05 +00:00
|
|
|
before { allow(author).to receive(:rate_for).with(article, scope: nil) { nil } }
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2018-01-16 03:14:05 +00:00
|
|
|
specify { expect(author.rated?(article)).to eq false }
|
2017-11-02 18:55:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when has rate for the given resource' do
|
2018-01-16 03:14:05 +00:00
|
|
|
before { allow(author).to receive(:rate_for).with(article, scope: nil) { double } }
|
2017-11-02 18:55:46 +00:00
|
|
|
|
2018-01-16 03:14:05 +00:00
|
|
|
specify { expect(author.rated?(article)).to eq true }
|
2017-11-02 18:55:46 +00:00
|
|
|
end
|
2017-10-30 01:44:23 +00:00
|
|
|
end
|
|
|
|
|
2017-11-02 18:55:46 +00:00
|
|
|
context 'with scopeable' do
|
|
|
|
let!(:category) { build :category }
|
|
|
|
|
|
|
|
context 'when has no rate for the given resource' do
|
2018-01-16 03:14:05 +00:00
|
|
|
before { allow(author).to receive(:rate_for).with(article, scope: category) { nil } }
|
2017-11-02 18:55:46 +00:00
|
|
|
|
2018-01-16 03:14:05 +00:00
|
|
|
specify { expect(author.rated?(article, scope: category)).to eq false }
|
2017-11-02 18:55:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when has rate for the given resource' do
|
2018-01-16 03:14:05 +00:00
|
|
|
before { allow(author).to receive(:rate_for).with(article, scope: category) { double } }
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2018-01-16 03:14:05 +00:00
|
|
|
specify { expect(author.rated?(article, scope: category)).to eq true }
|
2017-11-02 18:55:46 +00:00
|
|
|
end
|
2017-10-30 01:44:23 +00:00
|
|
|
end
|
|
|
|
end
|