accounts_controller_spec.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. require 'rails_helper'
  2. RSpec.describe AccountsController, type: :controller do
  3. render_views
  4. let(:alice) { Fabricate(:account, username: 'alice', user: Fabricate(:user)) }
  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 'activitystreams2' do
  42. let(:format) { 'json' }
  43. let(:content_type) { 'application/activity+json' }
  44. include_examples 'responses'
  45. end
  46. context 'html' do
  47. let(:format) { nil }
  48. let(:content_type) { 'text/html' }
  49. shared_examples 'responsed statuses' do
  50. it 'assigns @pinned_statuses' do
  51. pinned_statuses = assigns(:pinned_statuses).to_a
  52. expect(pinned_statuses.size).to eq expected_pinned_statuses.size
  53. pinned_statuses.each.zip(expected_pinned_statuses.each) do |pinned_status, expected_pinned_status|
  54. expect(pinned_status).to eq expected_pinned_status
  55. end
  56. end
  57. it 'assigns @statuses' do
  58. statuses = assigns(:statuses).to_a
  59. expect(statuses.size).to eq expected_statuses.size
  60. statuses.each.zip(expected_statuses.each) do |status, expected_status|
  61. expect(status).to eq expected_status
  62. end
  63. end
  64. end
  65. include_examples 'responses'
  66. context 'with anonymous visitor' do
  67. context 'without since_id nor max_id' do
  68. let(:expected_statuses) { [status7, status6, status5, status4, status3, status2, status1] }
  69. let(:expected_pinned_statuses) { [status7, status5, status6] }
  70. include_examples 'responsed statuses'
  71. end
  72. context 'with since_id nor max_id' do
  73. let(:max_id) { status4.id }
  74. let(:since_id) { status1.id }
  75. let(:expected_statuses) { [status3, status2] }
  76. let(:expected_pinned_statuses) { [] }
  77. include_examples 'responsed statuses'
  78. end
  79. end
  80. context 'with blocked visitor' do
  81. let(:current_user) { eve }
  82. context 'without since_id nor max_id' do
  83. let(:expected_statuses) { [] }
  84. let(:expected_pinned_statuses) { [] }
  85. include_examples 'responsed statuses'
  86. end
  87. end
  88. end
  89. end
  90. end