follow_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. end