rating/spec/models/extension/rated_spec.rb

49 lines
1.4 KiB
Ruby
Raw Normal View History

2017-10-30 01:44:23 +00:00
# frozen_string_literal: true
require 'rails_helper'
2018-01-16 03:25:36 +00:00
require 'support/shared_context/with_database_records'
2017-10-30 01:44:23 +00:00
RSpec.describe Rating::Extension, ':rated' do
2018-01-16 03:25:36 +00:00
include_context 'with_database_records'
2017-11-02 18:55:46 +00:00
context 'with no scope' do
it 'returns rates made by this author' do
expect(author_1.rated).to match_array [rate_1, rate_2, rate_3]
2017-11-02 18:55:46 +00:00
end
end
context 'with no scope' do
it 'returns scoped rates made by this author' do
expect(author_1.rated(scope: category)).to eq [rate_5]
2017-11-02 18:55:46 +00:00
end
2017-10-30 01:44:23 +00:00
end
context 'when destroy author' do
2018-01-26 21:58:12 +00:00
it 'destroys rates of that author' do
expect(Rating::Rate.where(author: author_1).count).to eq 4
2017-10-30 01:44:23 +00:00
author_1.destroy!
2017-10-30 01:44:23 +00:00
expect(Rating::Rate.where(author: author_1).count).to eq 0
2017-10-30 01:44:23 +00:00
end
end
context 'when destroy resource rated by author' do
2018-01-26 21:58:12 +00:00
it 'destroys rates of that resource' do
2017-11-02 18:55:46 +00:00
expect(Rating::Rate.where(resource: article_1).count).to eq 4
2017-10-30 01:44:23 +00:00
2017-11-02 18:55:46 +00:00
article_1.destroy!
2017-10-30 01:44:23 +00:00
2017-11-02 18:55:46 +00:00
expect(Rating::Rate.where(resource: article_1).count).to eq 0
2017-10-30 01:44:23 +00:00
end
end
2018-03-01 20:50:28 +00:00
context 'with extra scopes' do
let!(:extra_scopes_rate) { author_1.rate article_1, 1, extra_scopes: { scope_1: 'scope_1' } }
it 'returns records considering the extra scopes' do
expect(author_1.rated(extra_scopes: { scope_1: 'scope_1' })).to eq [extra_scopes_rate]
end
end if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
2017-10-30 01:44:23 +00:00
end