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.

143 lines
4.7 KiB

7 years ago
7 years ago
  1. require 'rails_helper'
  2. RSpec.describe AccountsController, type: :controller do
  3. render_views
  4. let(:alice) { Fabricate(:account, username: 'alice') }
  5. let(:eve) { Fabricate(:user) }
  6. describe 'GET #show' do
  7. let!(:status1) { Status.create!(account: alice, text: 'Hello world') }
  8. let!(:status2) { Status.create!(account: alice, text: 'Boop', thread: status1) }
  9. let!(:status3) { Status.create!(account: alice, text: 'Picture!') }
  10. let!(:status4) { Status.create!(account: alice, text: 'Mentioning @alice') }
  11. let!(:status5) { Status.create!(account: alice, text: 'Kitsune') }
  12. let!(:status6) { Status.create!(account: alice, text: 'Neko') }
  13. let!(:status7) { Status.create!(account: alice, text: 'Tanuki') }
  14. let!(:status_pin1) { StatusPin.create!(account: alice, status: status5, created_at: 5.days.ago) }
  15. let!(:status_pin2) { StatusPin.create!(account: alice, status: status6, created_at: 2.years.ago) }
  16. let!(:status_pin3) { StatusPin.create!(account: alice, status: status7, created_at: 10.minutes.ago) }
  17. before do
  18. alice.block!(eve.account)
  19. status3.media_attachments.create!(account: alice, file: fixture_file_upload('files/attachment.jpg', 'image/jpeg'))
  20. end
  21. shared_examples 'responses' do
  22. before do
  23. sign_in(current_user) if defined? current_user
  24. get :show, params: {
  25. username: alice.username,
  26. max_id: (max_id if defined? max_id),
  27. since_id: (since_id if defined? since_id),
  28. current_user: (current_user if defined? current_user),
  29. }, format: format
  30. end
  31. it 'assigns @account' do
  32. expect(assigns(:account)).to eq alice
  33. end
  34. it 'returns http success' do
  35. expect(response).to have_http_status(200)
  36. end
  37. it 'returns correct format' do
  38. expect(response.content_type).to eq content_type
  39. end
  40. end
  41. context 'atom' do
  42. let(:format) { 'atom' }
  43. let(:content_type) { 'application/atom+xml' }
  44. shared_examples 'responsed streams' do
  45. it 'assigns @entries' do
  46. entries = assigns(:entries).to_a
  47. expect(entries.size).to eq expected_statuses.size
  48. entries.each.zip(expected_statuses.each) do |entry, expected_status|
  49. expect(entry.status).to eq expected_status
  50. end
  51. end
  52. end
  53. include_examples 'responses'
  54. context 'without max_id nor since_id' do
  55. let(:expected_statuses) { [status7, status6, status5, status4, status3, status2, status1] }
  56. include_examples 'responsed streams'
  57. end
  58. context 'with max_id and since_id' do
  59. let(:max_id) { status4.stream_entry.id }
  60. let(:since_id) { status1.stream_entry.id }
  61. let(:expected_statuses) { [status3, status2] }
  62. include_examples 'responsed streams'
  63. end
  64. end
  65. context 'activitystreams2' do
  66. let(:format) { 'json' }
  67. let(:content_type) { 'application/activity+json' }
  68. include_examples 'responses'
  69. end
  70. context 'html' do
  71. let(:format) { nil }
  72. let(:content_type) { 'text/html' }
  73. shared_examples 'responsed statuses' do
  74. it 'assigns @pinned_statuses' do
  75. pinned_statuses = assigns(:pinned_statuses).to_a
  76. expect(pinned_statuses.size).to eq expected_pinned_statuses.size
  77. pinned_statuses.each.zip(expected_pinned_statuses.each) do |pinned_status, expected_pinned_status|
  78. expect(pinned_status).to eq expected_pinned_status
  79. end
  80. end
  81. it 'assigns @statuses' do
  82. statuses = assigns(:statuses).to_a
  83. expect(statuses.size).to eq expected_statuses.size
  84. statuses.each.zip(expected_statuses.each) do |status, expected_status|
  85. expect(status).to eq expected_status
  86. end
  87. end
  88. end
  89. include_examples 'responses'
  90. context 'with anonymous visitor' do
  91. context 'without since_id nor max_id' do
  92. let(:expected_statuses) { [status7, status6, status5, status4, status3, status2, status1] }
  93. let(:expected_pinned_statuses) { [status7, status5, status6] }
  94. include_examples 'responsed statuses'
  95. end
  96. context 'with since_id nor max_id' do
  97. let(:max_id) { status4.id }
  98. let(:since_id) { status1.id }
  99. let(:expected_statuses) { [status3, status2] }
  100. let(:expected_pinned_statuses) { [] }
  101. include_examples 'responsed statuses'
  102. end
  103. end
  104. context 'with blocked visitor' do
  105. let(:current_user) { eve }
  106. context 'without since_id nor max_id' do
  107. let(:expected_statuses) { [] }
  108. let(:expected_pinned_statuses) { [] }
  109. include_examples 'responsed statuses'
  110. end
  111. end
  112. end
  113. end
  114. end