闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe Follow, type: :model do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. let(:bob) { Fabricate(:account, username: 'bob') }
  5. describe 'validations' do
  6. subject { Follow.new(account: alice, target_account: bob) }
  7. it 'has a valid fabricator' do
  8. follow = Fabricate.build(:follow)
  9. expect(follow).to be_valid
  10. end
  11. it 'is invalid without an account' do
  12. follow = Fabricate.build(:follow, account: nil)
  13. follow.valid?
  14. expect(follow).to model_have_error_on_field(:account)
  15. end
  16. it 'is invalid without a target_account' do
  17. follow = Fabricate.build(:follow, target_account: nil)
  18. follow.valid?
  19. expect(follow).to model_have_error_on_field(:target_account)
  20. end
  21. end
  22. describe 'recent' do
  23. it 'sorts so that more recent follows comes earlier' do
  24. follow0 = Follow.create!(account: alice, target_account: bob)
  25. follow1 = Follow.create!(account: bob, target_account: alice)
  26. a = Follow.recent.to_a
  27. expect(a.size).to eq 2
  28. expect(a[0]).to eq follow1
  29. expect(a[1]).to eq follow0
  30. end
  31. end
  32. describe 'revoke_request!' do
  33. let(:follow) { Fabricate(:follow, account: account, target_account: target_account) }
  34. let(:account) { Fabricate(:account) }
  35. let(:target_account) { Fabricate(:account) }
  36. it 'revokes the follow relation' do
  37. follow.revoke_request!
  38. expect(account.following?(target_account)).to be false
  39. end
  40. it 'creates a follow request' do
  41. follow.revoke_request!
  42. expect(account.requested?(target_account)).to be true
  43. end
  44. end
  45. end