2017-10-29 23:44:23 -02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe Rating::Extension, ':rate' do
|
2018-01-16 01:14:05 -02:00
|
|
|
let!(:author) { create :author }
|
2017-10-29 23:44:23 -02:00
|
|
|
let!(:article) { create :article }
|
|
|
|
|
2017-11-02 16:55:46 -02:00
|
|
|
context 'with no scopeable' do
|
|
|
|
it 'delegates to rate object' do
|
2018-01-26 19:03:07 -02:00
|
|
|
expect(Rating::Rate).to receive(:create).with(
|
2018-03-01 17:50:28 -03:00
|
|
|
author: author, extra_scopes: {}, metadata: {}, resource: article, scopeable: nil, value: 3
|
2018-01-26 19:03:07 -02:00
|
|
|
)
|
2017-10-29 23:44:23 -02:00
|
|
|
|
2018-01-16 01:14:05 -02:00
|
|
|
author.rate article, 3
|
2017-11-02 16:55:46 -02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with scopeable' do
|
|
|
|
let!(:category) { build :category }
|
|
|
|
|
|
|
|
it 'delegates to rate object' do
|
2018-01-26 19:03:07 -02:00
|
|
|
expect(Rating::Rate).to receive(:create).with(
|
2018-03-01 17:50:28 -03:00
|
|
|
author: author, extra_scopes: {}, metadata: {}, resource: article, scopeable: category, value: 3
|
2018-01-26 19:03:07 -02:00
|
|
|
)
|
2017-11-02 16:55:46 -02:00
|
|
|
|
2018-01-16 01:14:05 -02:00
|
|
|
author.rate article, 3, scope: category
|
2017-11-02 16:55:46 -02:00
|
|
|
end
|
2017-10-29 23:44:23 -02:00
|
|
|
end
|
2018-01-26 19:03:07 -02:00
|
|
|
|
|
|
|
context 'with no metadata' do
|
|
|
|
it 'delegates an empty hash to rate object' do
|
|
|
|
expect(Rating::Rate).to receive(:create).with(
|
2018-03-01 17:50:28 -03:00
|
|
|
author: author, extra_scopes: {}, resource: article, metadata: {}, scopeable: nil, value: 3
|
2018-01-26 19:03:07 -02:00
|
|
|
)
|
|
|
|
|
|
|
|
author.rate article, 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with metadata' do
|
|
|
|
it 'delegates to rate object' do
|
|
|
|
expect(Rating::Rate).to receive(:create).with(
|
2018-03-01 17:50:28 -03:00
|
|
|
author: author, extra_scopes: {}, metadata: { comment: 'comment' }, resource: article, scopeable: nil, value: 3
|
2018-01-26 19:03:07 -02:00
|
|
|
)
|
|
|
|
|
|
|
|
author.rate article, 3, metadata: { comment: 'comment' }
|
|
|
|
end
|
|
|
|
end
|
2018-03-01 17:50:28 -03:00
|
|
|
|
|
|
|
context 'with extra_scopes' do
|
|
|
|
it 'delegates to rate object' do
|
|
|
|
expect(Rating::Rate).to receive(:create).with(
|
2022-04-21 15:57:48 -07:00
|
|
|
author: author,
|
|
|
|
extra_scopes: { scope_1: 'scope_1' },
|
|
|
|
metadata: { comment: 'comment' },
|
|
|
|
resource: article,
|
|
|
|
scopeable: nil,
|
|
|
|
value: 3
|
2018-03-01 17:50:28 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
author.rate article, 3, extra_scopes: { scope_1: 'scope_1' }, metadata: { comment: 'comment' }
|
|
|
|
end
|
|
|
|
end
|
2017-10-29 23:44:23 -02:00
|
|
|
end
|