tags_controller_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe TagsController do
  4. render_views
  5. describe 'GET #show' do
  6. let(:format) { 'html' }
  7. let(:tag) { Fabricate(:tag, name: 'test') }
  8. let(:tag_name) { tag&.name }
  9. before do
  10. get :show, params: { id: tag_name, format: format }
  11. end
  12. context 'when tag exists' do
  13. context 'when requested as HTML' do
  14. it 'returns http success' do
  15. expect(response).to have_http_status(200)
  16. end
  17. it 'returns Vary header' do
  18. expect(response.headers['Vary']).to eq 'Accept, Accept-Language, Cookie'
  19. end
  20. it 'returns public Cache-Control header' do
  21. expect(response.headers['Cache-Control']).to include 'public'
  22. end
  23. end
  24. context 'when requested as JSON' do
  25. let(:format) { 'json' }
  26. it 'returns http success' do
  27. expect(response).to have_http_status(200)
  28. end
  29. it 'returns Vary header' do
  30. expect(response.headers['Vary']).to eq 'Accept, Accept-Language, Cookie'
  31. end
  32. it 'returns public Cache-Control header' do
  33. expect(response.headers['Cache-Control']).to include 'public'
  34. end
  35. end
  36. end
  37. context 'when tag does not exist' do
  38. let(:tag_name) { 'hoge' }
  39. it 'returns http not found' do
  40. expect(response).to have_http_status(404)
  41. end
  42. end
  43. end
  44. end