forked from cybrespace/mastodon
Add and Remove tests for FollowRequest (#5622)
* Add a test for FollowRequest#authorize! * Remove tests There is no need to test ActiveModel::Validations::ClassMethods#validates. * Make an alias of destroy! as reject! Instead of defining the method, make an alias of destroy! as reject! because of reducing test.
This commit is contained in:
parent
d200e041fe
commit
54b42901df
|
@ -27,7 +27,5 @@ class FollowRequest < ApplicationRecord
|
||||||
destroy!
|
destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject!
|
alias reject! destroy!
|
||||||
destroy!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,16 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe FollowRequest, type: :model do
|
RSpec.describe FollowRequest, type: :model do
|
||||||
describe '#authorize!'
|
describe '#authorize!' do
|
||||||
describe '#reject!'
|
let(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
|
||||||
|
let(:account) { Fabricate(:account) }
|
||||||
|
let(:target_account) { Fabricate(:account) }
|
||||||
|
|
||||||
describe 'validations' do
|
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
|
||||||
it 'has a valid fabricator' do
|
expect(account).to receive(:follow!).with(target_account)
|
||||||
follow_request = Fabricate.build(:follow_request)
|
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
|
||||||
expect(follow_request).to be_valid
|
expect(follow_request).to receive(:destroy!)
|
||||||
end
|
follow_request.authorize!
|
||||||
|
|
||||||
it 'is invalid without an account' do
|
|
||||||
follow_request = Fabricate.build(:follow_request, account: nil)
|
|
||||||
follow_request.valid?
|
|
||||||
expect(follow_request).to model_have_error_on_field(:account)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is invalid without a target account' do
|
|
||||||
follow_request = Fabricate.build(:follow_request, target_account: nil)
|
|
||||||
follow_request.valid?
|
|
||||||
expect(follow_request).to model_have_error_on_field(:target_account)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue