闭社主体 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.

114 lines
2.7 KiB

8 years ago
8 years ago
  1. require 'rails_helper'
  2. RSpec.describe Account, type: :model do
  3. subject { Fabricate(:account, username: 'alice') }
  4. context do
  5. let(:bob) { Fabricate(:account, username: 'bob') }
  6. describe '#follow!' do
  7. it 'creates a follow' do
  8. follow = subject.follow!(bob)
  9. expect(follow).to be_instance_of Follow
  10. expect(follow.account).to eq subject
  11. expect(follow.target_account).to eq bob
  12. end
  13. end
  14. describe '#unfollow!' do
  15. before do
  16. subject.follow!(bob)
  17. end
  18. it 'destroys a follow' do
  19. unfollow = subject.unfollow!(bob)
  20. expect(unfollow).to be_instance_of Follow
  21. expect(unfollow.account).to eq subject
  22. expect(unfollow.target_account).to eq bob
  23. expect(unfollow.destroyed?).to be true
  24. end
  25. end
  26. describe '#following?' do
  27. it 'returns true when the target is followed' do
  28. subject.follow!(bob)
  29. expect(subject.following?(bob)).to be true
  30. end
  31. it 'returns false if the target is not followed' do
  32. expect(subject.following?(bob)).to be false
  33. end
  34. end
  35. end
  36. describe '#local?' do
  37. it 'returns true when the account is local' do
  38. expect(subject.local?).to be true
  39. end
  40. it 'returns false when the account is on a different domain' do
  41. subject.domain = 'foreign.tld'
  42. expect(subject.local?).to be false
  43. end
  44. end
  45. describe '#acct' do
  46. it 'returns username for local users' do
  47. expect(subject.acct).to eql 'alice'
  48. end
  49. it 'returns username@domain for foreign users' do
  50. subject.domain = 'foreign.tld'
  51. expect(subject.acct).to eql 'alice@foreign.tld'
  52. end
  53. end
  54. describe '#subscribed?' do
  55. it 'returns false when no secrets and tokens have been set' do
  56. expect(subject.subscribed?).to be false
  57. end
  58. it 'returns true when the secret and token have been set' do
  59. subject.secret = 'a'
  60. subject.verify_token = 'b'
  61. expect(subject.subscribed?).to be true
  62. end
  63. end
  64. describe '#keypair' do
  65. it 'returns an RSA key pair' do
  66. expect(subject.keypair).to be_instance_of OpenSSL::PKey::RSA
  67. end
  68. end
  69. describe '#subscription' do
  70. it 'returns an OStatus subscription' do
  71. expect(subject.subscription('')).to be_instance_of OStatus2::Subscription
  72. end
  73. end
  74. describe '#object_type' do
  75. it 'is always a person' do
  76. expect(subject.object_type).to be :person
  77. end
  78. end
  79. describe '#title' do
  80. it 'is the same as the username' do
  81. expect(subject.title).to eql subject.username
  82. end
  83. end
  84. describe '#content' do
  85. it 'is the same as the note' do
  86. expect(subject.content).to eql subject.note
  87. end
  88. end
  89. describe '#ping!' do
  90. pending
  91. end
  92. end