Add coverage for `AccountPin` model (#33231)
This commit is contained in:
		
							parent
							
								
									58c5068bda
								
							
						
					
					
						commit
						7d52b24569
					
				| 
						 | 
					@ -23,6 +23,6 @@ class AccountPin < ApplicationRecord
 | 
				
			||||||
  private
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def validate_follow_relationship
 | 
					  def validate_follow_relationship
 | 
				
			||||||
    errors.add(:base, I18n.t('accounts.pin_errors.following')) unless account.following?(target_account)
 | 
					    errors.add(:base, I18n.t('accounts.pin_errors.following')) unless account&.following?(target_account)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,33 @@
 | 
				
			||||||
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require 'rails_helper'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RSpec.describe AccountPin do
 | 
				
			||||||
 | 
					  describe 'Associations' do
 | 
				
			||||||
 | 
					    it { is_expected.to belong_to(:account).required }
 | 
				
			||||||
 | 
					    it { is_expected.to belong_to(:target_account).required }
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe 'Validations' do
 | 
				
			||||||
 | 
					    describe 'the follow relationship' do
 | 
				
			||||||
 | 
					      subject { Fabricate.build :account_pin, account: account }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      let(:account) { Fabricate :account }
 | 
				
			||||||
 | 
					      let(:target_account) { Fabricate :account }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      context 'when account is following target account' do
 | 
				
			||||||
 | 
					        before { account.follow!(target_account) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        it { is_expected.to allow_value(target_account).for(:target_account).against(:base) }
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      context 'when account is not following target account' do
 | 
				
			||||||
 | 
					        it { is_expected.to_not allow_value(target_account).for(:target_account).against(:base).with_message(not_following_message) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def not_following_message
 | 
				
			||||||
 | 
					          I18n.t('accounts.pin_errors.following')
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
		Loading…
	
		Reference in New Issue