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.

112 lines
3.6 KiB

7 years ago
7 years ago
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. describe 'GET #show' do
  6. let!(:status1) { Status.create!(account: alice, text: 'Hello world') }
  7. let!(:status2) { Status.create!(account: alice, text: 'Boop', thread: status1) }
  8. let!(:status3) { Status.create!(account: alice, text: 'Picture!') }
  9. let!(:status4) { Status.create!(account: alice, text: 'Mentioning @alice') }
  10. let!(:status5) { Status.create!(account: alice, text: 'Kitsune') }
  11. let!(:status6) { Status.create!(account: alice, text: 'Neko') }
  12. let!(:status7) { Status.create!(account: alice, text: 'Tanuki') }
  13. let!(:status_pin1) { StatusPin.create!(account: alice, status: status5, created_at: 5.days.ago) }
  14. let!(:status_pin2) { StatusPin.create!(account: alice, status: status6, created_at: 2.years.ago) }
  15. let!(:status_pin3) { StatusPin.create!(account: alice, status: status7, created_at: 10.minutes.ago) }
  16. before do
  17. status3.media_attachments.create!(account: alice, file: fixture_file_upload('files/attachment.jpg', 'image/jpeg'))
  18. end
  19. context 'atom' do
  20. before do
  21. get :show, params: { username: alice.username, max_id: status4.stream_entry.id, since_id: status1.stream_entry.id }, format: 'atom'
  22. end
  23. it 'assigns @account' do
  24. expect(assigns(:account)).to eq alice
  25. end
  26. it 'assigns @entries' do
  27. entries = assigns(:entries).to_a
  28. expect(entries.size).to eq 2
  29. expect(entries[0].status).to eq status3
  30. expect(entries[1].status).to eq status2
  31. end
  32. it 'returns http success with Atom' do
  33. expect(response).to have_http_status(:success)
  34. end
  35. end
  36. context 'activitystreams2' do
  37. before do
  38. get :show, params: { username: alice.username }, format: 'json'
  39. end
  40. it 'assigns @account' do
  41. expect(assigns(:account)).to eq alice
  42. end
  43. it 'returns http success with Activity Streams 2.0' do
  44. expect(response).to have_http_status(:success)
  45. end
  46. it 'returns application/activity+json' do
  47. expect(response.content_type).to eq 'application/activity+json'
  48. end
  49. end
  50. context 'html without since_id nor max_id' do
  51. before do
  52. get :show, params: { username: alice.username }
  53. end
  54. it 'assigns @account' do
  55. expect(assigns(:account)).to eq alice
  56. end
  57. it 'assigns @pinned_statuses' do
  58. pinned_statuses = assigns(:pinned_statuses).to_a
  59. expect(pinned_statuses.size).to eq 3
  60. expect(pinned_statuses[0]).to eq status7
  61. expect(pinned_statuses[1]).to eq status5
  62. expect(pinned_statuses[2]).to eq status6
  63. end
  64. it 'returns http success' do
  65. expect(response).to have_http_status(:success)
  66. end
  67. end
  68. context 'html with since_id and max_id' do
  69. before do
  70. get :show, params: { username: alice.username, max_id: status4.id, since_id: status1.id }
  71. end
  72. it 'assigns @account' do
  73. expect(assigns(:account)).to eq alice
  74. end
  75. it 'assigns @statuses' do
  76. statuses = assigns(:statuses).to_a
  77. expect(statuses.size).to eq 2
  78. expect(statuses[0]).to eq status3
  79. expect(statuses[1]).to eq status2
  80. end
  81. it 'assigns an empty array to @pinned_statuses' do
  82. pinned_statuses = assigns(:pinned_statuses).to_a
  83. expect(pinned_statuses.size).to eq 0
  84. end
  85. it 'returns http success' do
  86. expect(response).to have_http_status(:success)
  87. end
  88. end
  89. end
  90. end