Merge commit 'df2611a10f
' into kbtopic-remove-quote
This commit is contained in:
commit
e4c72836a3
36 changed files with 1660 additions and 87 deletions
87
spec/serializers/rest/quote_serializer_spec.rb
Normal file
87
spec/serializers/rest/quote_serializer_spec.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::QuoteSerializer do
|
||||
subject do
|
||||
serialized_record_json(
|
||||
quote,
|
||||
described_class,
|
||||
options: {
|
||||
scope: current_user,
|
||||
scope_name: :current_user,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:current_user) { Fabricate(:user) }
|
||||
let(:quote) { Fabricate(:quote) }
|
||||
|
||||
context 'with a pending quote' do
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status: nil,
|
||||
state: 'pending'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an accepted quote' do
|
||||
let(:quote) { Fabricate(:quote, state: :accepted) }
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status: be_a(Hash),
|
||||
state: 'accepted'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an accepted quote of a deleted post' do
|
||||
let(:quote) { Fabricate(:quote, state: :accepted) }
|
||||
|
||||
before do
|
||||
quote.quoted_status.destroy!
|
||||
quote.reload
|
||||
end
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status: nil,
|
||||
state: 'deleted'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an accepted quote of a blocked user' do
|
||||
let(:quote) { Fabricate(:quote, state: :accepted) }
|
||||
|
||||
before do
|
||||
quote.quoted_account.block!(current_user.account)
|
||||
end
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status: nil,
|
||||
state: 'unauthorized'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a recursive accepted quote' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:quote) { Fabricate(:quote, status: status, quoted_status: status, state: :accepted) }
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status: be_a(Hash),
|
||||
state: 'accepted'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
93
spec/serializers/rest/shallow_quote_serializer_spec.rb
Normal file
93
spec/serializers/rest/shallow_quote_serializer_spec.rb
Normal file
|
@ -0,0 +1,93 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::ShallowQuoteSerializer do
|
||||
subject do
|
||||
serialized_record_json(
|
||||
quote,
|
||||
described_class,
|
||||
options: {
|
||||
scope: current_user,
|
||||
scope_name: :current_user,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:current_user) { Fabricate(:user) }
|
||||
let(:quote) { Fabricate(:quote) }
|
||||
|
||||
context 'with a pending quote' do
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status_id: nil,
|
||||
state: 'pending'
|
||||
)
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to_not have_key(:quoted_status)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an accepted quote' do
|
||||
let(:quote) { Fabricate(:quote, state: :accepted) }
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status_id: be_a(String),
|
||||
state: 'accepted'
|
||||
)
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to_not have_key(:quoted_status)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an accepted quote of a deleted post' do
|
||||
let(:quote) { Fabricate(:quote, state: :accepted) }
|
||||
|
||||
before do
|
||||
quote.quoted_status.destroy!
|
||||
quote.reload
|
||||
end
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status_id: nil,
|
||||
state: 'deleted'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an accepted quote of a blocked user' do
|
||||
let(:quote) { Fabricate(:quote, state: :accepted) }
|
||||
|
||||
before do
|
||||
quote.quoted_account.block!(current_user.account)
|
||||
end
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status_id: nil,
|
||||
state: 'unauthorized'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a recursive accepted quote' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:quote) { Fabricate(:quote, status: status, quoted_status: status, state: :accepted) }
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
quoted_status_id: be_a(String),
|
||||
state: 'accepted'
|
||||
)
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to_not have_key(:quoted_status)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue