rating/spec/models/extension/rated_question_spec.rb

47 lines
1.5 KiB
Ruby
Raw Normal View History

2017-10-30 01:44:23 +00:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Rating::Extension, ':rated?' do
2018-03-01 20:50:28 +00:00
let!(:author) { create :author }
let!(:resource) { create :article }
2017-10-30 01:44:23 +00:00
2017-11-02 18:55:46 +00:00
context 'with no scopeable' do
2018-03-01 20:50:28 +00:00
before { author.rate resource, 1 }
2017-10-30 01:44:23 +00:00
2018-03-01 20:50:28 +00:00
context 'when has no rate for the given resource' do
specify { expect(author.rated?(create(:article))).to eq false }
2017-11-02 18:55:46 +00:00
end
context 'when has rate for the given resource' do
2018-03-01 20:50:28 +00:00
specify { expect(author.rated?(resource)).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
2018-03-01 20:50:28 +00:00
let!(:category) { create :category }
2017-11-02 18:55:46 +00:00
2018-03-01 20:50:28 +00:00
before { author.rate resource, 1, scope: category }
2017-11-02 18:55:46 +00:00
2018-03-01 20:50:28 +00:00
context 'when has no rate for the given resource' do
specify { expect(author.rated?(resource, scope: create(:category))).to eq false }
2017-11-02 18:55:46 +00:00
end
context 'when has rate for the given resource' do
2018-03-01 20:50:28 +00:00
specify { expect(author.rated?(resource, scope: category)).to eq true }
2017-11-02 18:55:46 +00:00
end
2017-10-30 01:44:23 +00:00
end
2018-03-01 20:50:28 +00:00
context 'with extra scopes' do
before { author.rate resource, 1, extra_scopes: { scope_1: 'scope_1' } }
context 'when has no rate for the given resource with given extra scopes' do
specify { expect(author.rated?(resource, extra_scopes: { scope_1: 'missing' })).to eq false }
end
context 'when has rate for the given resource with given extra scopes' do
specify { expect(author.rated?(resource, extra_scopes: { scope_1: 'scope_1' })).to eq true }
end
end if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
2017-10-30 01:44:23 +00:00
end