From 822e918a56055223be009974d581a8295d60b709 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 16 Sep 2024 03:52:22 -0400 Subject: [PATCH] Add coverage for `Bookmark` validation and reblog/status check callback (#31907) --- spec/models/bookmark_spec.rb | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/models/bookmark_spec.rb diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb new file mode 100644 index 00000000000..e0d91000e77 --- /dev/null +++ b/spec/models/bookmark_spec.rb @@ -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