rating/spec/models/extension/rated_question_spec.rb

47 lines
1.4 KiB
Ruby
Raw Normal View History

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