mirror of
https://github.com/funamitech/mastodon
synced 2024-11-23 14:46:52 +09:00
Add coverage for Bookmark
validation and reblog/status check callback (#31907)
This commit is contained in:
parent
c24de04f9c
commit
822e918a56
43
spec/models/bookmark_spec.rb
Normal file
43
spec/models/bookmark_spec.rb
Normal file
@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Bookmark do
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
it { is_expected.to belong_to(:status).required }
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :bookmark }
|
||||
|
||||
it { is_expected.to validate_uniqueness_of(:status_id).scoped_to(:account_id) }
|
||||
end
|
||||
|
||||
describe 'Callbacks' do
|
||||
describe 'reblog statuses' do
|
||||
context 'when status is not a reblog' do
|
||||
let(:status) { Fabricate :status }
|
||||
|
||||
it 'keeps status set to assigned value' do
|
||||
bookmark = Fabricate.build :bookmark, status: status
|
||||
|
||||
expect { bookmark.valid? }
|
||||
.to_not change(bookmark, :status)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is a reblog' do
|
||||
let(:original) { Fabricate :status }
|
||||
let(:status) { Fabricate :status, reblog: original }
|
||||
|
||||
it 'keeps status set to assigned value' do
|
||||
bookmark = Fabricate.build :bookmark, status: status
|
||||
|
||||
expect { bookmark.valid? }
|
||||
.to change(bookmark, :status).to(original)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user