mirror of https://github.com/tootsuite/mastodon
Reduce factory creation in `AP::ProcessStatusUpdateService` spec (#31051)
parent
64c7ffdc65
commit
47ea83d246
|
@ -40,14 +40,13 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
it 'updates text' do
|
it 'updates text and content warning' do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
expect(status.reload.text).to eq 'Hello universe'
|
expect(status.reload)
|
||||||
end
|
.to have_attributes(
|
||||||
|
text: eq('Hello universe'),
|
||||||
it 'updates content warning' do
|
spoiler_text: eq('Show more')
|
||||||
subject.call(status, json, json)
|
)
|
||||||
expect(status.reload.spoiler_text).to eq 'Show more'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the changes are only in sanitized-out HTML' do
|
context 'when the changes are only in sanitized-out HTML' do
|
||||||
|
@ -67,12 +66,9 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits and does not mark status edited' do
|
||||||
expect(status.reload.edits).to be_empty
|
expect(status.reload.edits).to be_empty
|
||||||
end
|
expect(status).to_not be_edited
|
||||||
|
|
||||||
it 'does not mark status as edited' do
|
|
||||||
expect(status.edited?).to be false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -90,15 +86,9 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits, mark status edited, or update text' do
|
||||||
expect(status.reload.edits).to be_empty
|
expect(status.reload.edits).to be_empty
|
||||||
end
|
expect(status.reload).to_not be_edited
|
||||||
|
|
||||||
it 'does not mark status as edited' do
|
|
||||||
expect(status.reload.edited?).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not update the text' do
|
|
||||||
expect(status.reload.text).to eq 'Hello world'
|
expect(status.reload.text).to eq 'Hello world'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -137,19 +127,10 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits, mark status edited, update text but does update tallies' do
|
||||||
expect(status.reload.edits).to be_empty
|
expect(status.reload.edits).to be_empty
|
||||||
end
|
expect(status.reload).to_not be_edited
|
||||||
|
|
||||||
it 'does not mark status as edited' do
|
|
||||||
expect(status.reload.edited?).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not update the text' do
|
|
||||||
expect(status.reload.text).to eq 'Hello world'
|
expect(status.reload.text).to eq 'Hello world'
|
||||||
end
|
|
||||||
|
|
||||||
it 'updates tallies' do
|
|
||||||
expect(status.poll.reload.cached_tallies).to eq [4, 3]
|
expect(status.poll.reload.cached_tallies).to eq [4, 3]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -189,19 +170,10 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits, mark status edited, update text, or update tallies' do
|
||||||
expect(status.reload.edits).to be_empty
|
expect(status.reload.edits).to be_empty
|
||||||
end
|
expect(status.reload).to_not be_edited
|
||||||
|
|
||||||
it 'does not mark status as edited' do
|
|
||||||
expect(status.reload.edited?).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not update the text' do
|
|
||||||
expect(status.reload.text).to eq 'Hello world'
|
expect(status.reload.text).to eq 'Hello world'
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not update tallies' do
|
|
||||||
expect(status.poll.reload.cached_tallies).to eq [0, 0]
|
expect(status.poll.reload.cached_tallies).to eq [0, 0]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -213,13 +185,10 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
status.snapshot!(rate_limit: false)
|
status.snapshot!(rate_limit: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits or update relevant attributes' do
|
||||||
expect { subject.call(status, json, json) }.to_not(change { status.reload.edits.pluck(&:id) })
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not update the text, spoiler_text or edited_at' do
|
|
||||||
expect { subject.call(status, json, json) }
|
expect { subject.call(status, json, json) }
|
||||||
.to_not(change { status.reload.attributes.slice('text', 'spoiler_text', 'edited_at').values })
|
.to not_change { status.reload.edits.pluck(&:id) }
|
||||||
|
.and(not_change { status.reload.attributes.slice('text', 'spoiler_text', 'edited_at').values })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -237,12 +206,9 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits or mark status edited' do
|
||||||
expect(status.reload.edits).to be_empty
|
expect(status.reload.edits).to be_empty
|
||||||
end
|
expect(status).to_not be_edited
|
||||||
|
|
||||||
it 'does not mark status as edited' do
|
|
||||||
expect(status.edited?).to be false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -261,12 +227,9 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create any edits' do
|
it 'does not create any edits or mark status edited' do
|
||||||
expect(status.reload.edits).to be_empty
|
expect(status.reload.edits).to be_empty
|
||||||
end
|
expect(status).to_not be_edited
|
||||||
|
|
||||||
it 'does not mark status as edited' do
|
|
||||||
expect(status.edited?).to be false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -412,11 +375,8 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes poll' do
|
it 'removes poll and records media change in edit' do
|
||||||
expect(status.reload.poll).to be_nil
|
expect(status.reload.poll).to be_nil
|
||||||
end
|
|
||||||
|
|
||||||
it 'records media change in edit' do
|
|
||||||
expect(status.edits.reload.last.poll_options).to be_nil
|
expect(status.edits.reload.last.poll_options).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -442,26 +402,21 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a poll' do
|
it 'creates a poll and records media change in edit' do
|
||||||
poll = status.reload.poll
|
poll = status.reload.poll
|
||||||
|
|
||||||
expect(poll).to_not be_nil
|
expect(poll).to_not be_nil
|
||||||
expect(poll.options).to eq %w(Foo Bar Baz)
|
expect(poll.options).to eq %w(Foo Bar Baz)
|
||||||
end
|
|
||||||
|
|
||||||
it 'records media change in edit' do
|
|
||||||
expect(status.edits.reload.last.poll_options).to eq %w(Foo Bar Baz)
|
expect(status.edits.reload.last.poll_options).to eq %w(Foo Bar Baz)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates edit history' do
|
it 'creates edit history and sets edit timestamp' do
|
||||||
subject.call(status, json, json)
|
subject.call(status, json, json)
|
||||||
expect(status.edits.reload.map(&:text)).to eq ['Hello world', 'Hello universe']
|
expect(status.edits.reload.map(&:text))
|
||||||
end
|
.to eq ['Hello world', 'Hello universe']
|
||||||
|
expect(status.reload.edited_at.to_s)
|
||||||
it 'sets edited timestamp' do
|
.to eq '2021-09-08 22:39:25 UTC'
|
||||||
subject.call(status, json, json)
|
|
||||||
expect(status.reload.edited_at.to_s).to eq '2021-09-08 22:39:25 UTC'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue