rating/spec/models/extension/rated_question_spec.rb

47 lines
1.4 KiB
Ruby
Raw Normal View History

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