2017-10-30 01:44:23 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-16 03:25:36 +00:00
|
|
|
require 'support/shared_context/with_database_records'
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2017-11-02 18:55:46 +00:00
|
|
|
RSpec.describe Rating::Extension, '.rating' do
|
2018-01-16 03:25:36 +00:00
|
|
|
include_context 'with_database_records'
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2017-11-02 18:55:46 +00:00
|
|
|
context 'with no scope' do
|
|
|
|
it 'returns rating record' do
|
|
|
|
expect(article_1.rating).to eq Rating::Rating.find_by(resource: article_1, scopeable: nil)
|
|
|
|
end
|
|
|
|
end
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2017-11-02 18:55:46 +00:00
|
|
|
context 'with scope' do
|
|
|
|
it 'returns scoped rating record' do
|
|
|
|
expect(article_1.rating(scope: category)).to eq Rating::Rating.find_by(resource: article_1, scopeable: category)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when destroy author' do
|
2017-10-30 01:44:23 +00:00
|
|
|
it 'does not destroy resource rating' do
|
2017-11-02 18:55:46 +00:00
|
|
|
expect(Rating::Rating.where(resource: article_1).count).to eq 2
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2018-01-16 03:14:05 +00:00
|
|
|
author_1.destroy!
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2017-11-02 18:55:46 +00:00
|
|
|
expect(Rating::Rating.where(resource: article_1).count).to eq 2
|
2017-10-30 01:44:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when destroy resource' do
|
|
|
|
it 'destroys resource rating too' do
|
2017-11-02 18:55:46 +00:00
|
|
|
expect(Rating::Rating.where(resource: article_1).count).to eq 2
|
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::Rating.where(resource: article_1).count).to eq 0
|
2017-10-30 01:44:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|