From 219458d7d4c9bb9ee0ed3c89c72438ee4edc2e1c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 3 Sep 2024 09:18:53 -0400 Subject: [PATCH] Convert `tags` controller spec to system and request specs (#31708) --- spec/controllers/tags_controller_spec.rb | 45 ------------------ spec/requests/tags_spec.rb | 59 ++++++++++++++++++++++++ spec/system/tags_spec.rb | 16 +++++++ 3 files changed, 75 insertions(+), 45 deletions(-) delete mode 100644 spec/controllers/tags_controller_spec.rb create mode 100644 spec/requests/tags_spec.rb create mode 100644 spec/system/tags_spec.rb diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb deleted file mode 100644 index 2bb0c8de3b..0000000000 --- a/spec/controllers/tags_controller_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe TagsController do - render_views - - describe 'GET #show' do - let(:format) { 'html' } - let(:tag) { Fabricate(:tag, name: 'test') } - let(:tag_name) { tag&.name } - - before do - get :show, params: { id: tag_name, format: format } - end - - context 'when tag exists' do - context 'when requested as HTML' do - it 'returns http success' do - expect(response).to have_http_status(200) - end - - it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie' - end - - context 'when requested as JSON' do - let(:format) { 'json' } - - it 'returns http success' do - expect(response).to have_http_status(200) - end - - it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie' - end - end - - context 'when tag does not exist' do - let(:tag_name) { 'hoge' } - - it 'returns http not found' do - expect(response).to have_http_status(404) - end - end - end -end diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb new file mode 100644 index 0000000000..c037bbef5a --- /dev/null +++ b/spec/requests/tags_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Tags' do + describe 'GET /tags/:id' do + context 'when tag exists' do + let(:tag) { Fabricate :tag } + + context 'with HTML format' do + # TODO: Convert the cacheable response shared example into a matcher, + # remove this example, rely on system spec (which should use matcher) + before { get tag_path(tag) } + + it 'returns http success' do + expect(response) + .to have_http_status(200) + end + + it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie' + end + + context 'with JSON format' do + before { get tag_path(tag, format: :json) } + + it 'returns http success' do + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to start_with('application/activity+json') + end + + it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie' + end + + context 'with RSS format' do + before { get tag_path(tag, format: :rss) } + + it 'returns http success' do + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to start_with('application/rss+xml') + end + + it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie' + end + end + + context 'when tag does not exist' do + before { get tag_path('missing') } + + it 'returns http not found' do + expect(response) + .to have_http_status(404) + end + end + end +end diff --git a/spec/system/tags_spec.rb b/spec/system/tags_spec.rb new file mode 100644 index 0000000000..e9ad970a54 --- /dev/null +++ b/spec/system/tags_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Tags' do + describe 'Viewing a tag' do + let(:tag) { Fabricate(:tag, name: 'test') } + + it 'visits the tag page and renders the web app' do + visit tag_path(tag) + + expect(page) + .to have_css('noscript', text: /Mastodon/) + end + end +end