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.

64 lines
2.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. require 'rails_helper'
  2. RSpec.describe TagsController, type: :controller do
  3. render_views
  4. describe 'GET #show' do
  5. let!(:tag) { Fabricate(:tag, name: 'test') }
  6. let!(:local) { Fabricate(:status, tags: [ tag ], text: 'local #test') }
  7. let!(:remote) { Fabricate(:status, tags: [ tag ], text: 'remote #test', account: Fabricate(:account, domain: 'remote')) }
  8. let!(:late) { Fabricate(:status, tags: [ tag ], text: 'late #test') }
  9. context 'when tag exists' do
  10. it 'returns http success' do
  11. get :show, params: { id: 'test', max_id: late.id }
  12. expect(response).to have_http_status(:success)
  13. end
  14. it 'renders public layout' do
  15. get :show, params: { id: 'test', max_id: late.id }
  16. expect(response).to render_template layout: 'public'
  17. end
  18. it 'renders only local statuses if local parameter is specified' do
  19. get :show, params: { id: 'test', local: true, max_id: late.id }
  20. expect(assigns(:tag)).to eq tag
  21. statuses = assigns(:statuses).to_a
  22. expect(statuses.size).to eq 1
  23. expect(statuses[0]).to eq local
  24. end
  25. it 'renders local and remote statuses if local parameter is not specified' do
  26. get :show, params: { id: 'test', max_id: late.id }
  27. expect(assigns(:tag)).to eq tag
  28. statuses = assigns(:statuses).to_a
  29. expect(statuses.size).to eq 2
  30. expect(statuses[0]).to eq remote
  31. expect(statuses[1]).to eq local
  32. end
  33. it 'filters statuses by the current account' do
  34. user = Fabricate(:user)
  35. user.account.block!(remote.account)
  36. sign_in(user)
  37. get :show, params: { id: 'test', max_id: late.id }
  38. expect(assigns(:tag)).to eq tag
  39. statuses = assigns(:statuses).to_a
  40. expect(statuses.size).to eq 1
  41. expect(statuses[0]).to eq local
  42. end
  43. end
  44. context 'when tag does not exist' do
  45. it 'returns http missing for non-existent tag' do
  46. get :show, params: { id: 'none' }
  47. expect(response).to have_http_status(:missing)
  48. end
  49. end
  50. end
  51. end