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

117 lines
2.9 KiB

8 years ago
8 years ago
  1. require 'rails_helper'
  2. RSpec.describe Status, type: :model do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. let(:bob) { Fabricate(:account, username: 'bob') }
  5. let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!')}
  6. subject { Fabricate(:status, account: alice) }
  7. describe '#local?' do
  8. it 'returns true when no remote URI is set' do
  9. expect(subject.local?).to be true
  10. end
  11. it 'returns false if a remote URI is set' do
  12. subject.uri = 'a'
  13. expect(subject.local?).to be false
  14. end
  15. end
  16. describe '#reblog?' do
  17. it 'returns true when the status reblogs another status' do
  18. subject.reblog = other
  19. expect(subject.reblog?).to be true
  20. end
  21. it 'returns false if the status is self-contained' do
  22. expect(subject.reblog?).to be false
  23. end
  24. end
  25. describe '#reply?' do
  26. it 'returns true if the status references another' do
  27. subject.thread = other
  28. expect(subject.reply?).to be true
  29. end
  30. it 'returns false if the status is self-contained' do
  31. expect(subject.reply?).to be false
  32. end
  33. end
  34. describe '#mentions' do
  35. before do
  36. bob # make sure the account exists
  37. end
  38. it 'is empty if the status is self-contained and does not mention anyone' do
  39. expect(subject.mentions).to be_empty
  40. end
  41. it 'returns mentioned accounts' do
  42. subject.text = 'Hello @bob!'
  43. expect(subject.mentions).to include bob
  44. end
  45. it 'returns account of the replied-to status' do
  46. subject.thread = other
  47. expect(subject.mentions).to include bob
  48. end
  49. it 'returns the account of the shared status' do
  50. subject.reblog = other
  51. expect(subject.mentions).to include bob
  52. end
  53. end
  54. describe '#verb' do
  55. it 'is always post' do
  56. expect(subject.verb).to be :post
  57. end
  58. end
  59. describe '#object_type' do
  60. it 'is note when the status is self-contained' do
  61. expect(subject.object_type).to be :note
  62. end
  63. it 'is comment when the status replies to another' do
  64. subject.thread = other
  65. expect(subject.object_type).to be :comment
  66. end
  67. end
  68. describe '#title' do
  69. it 'is a shorter version of the content' do
  70. expect(subject.title).to be_a String
  71. end
  72. end
  73. describe '#content' do
  74. it 'returns the text of the status if it is not a reblog' do
  75. expect(subject.content).to eql subject.text
  76. end
  77. it 'returns the text of the reblogged status' do
  78. subject.reblog = other
  79. expect(subject.content).to eql other.text
  80. end
  81. end
  82. describe '#target' do
  83. it 'returns nil if the status is self-contained' do
  84. expect(subject.target).to be_nil
  85. end
  86. it 'returns nil if the status is a reply' do
  87. subject.thread = other
  88. expect(subject.target).to be_nil
  89. end
  90. it 'returns the reblogged status' do
  91. subject.reblog = other
  92. expect(subject.target).to eq other
  93. end
  94. end
  95. end