From 60bb51eef826c20097cf25c196e602b7c02b1df9 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 17 Dec 2024 04:20:01 -0500 Subject: [PATCH] Convert `filters` spec controller->system (#33326) --- spec/controllers/filters_controller_spec.rb | 34 ------------------- spec/requests/filters_spec.rb | 16 +++++++++ spec/system/filters_spec.rb | 36 ++++++++++++++++++++- 3 files changed, 51 insertions(+), 35 deletions(-) delete mode 100644 spec/controllers/filters_controller_spec.rb create mode 100644 spec/requests/filters_spec.rb diff --git a/spec/controllers/filters_controller_spec.rb b/spec/controllers/filters_controller_spec.rb deleted file mode 100644 index de043e8ae3..0000000000 --- a/spec/controllers/filters_controller_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe FiltersController do - render_views - - describe 'GET #index' do - context 'with signed out user' do - before do - get :index - end - - it 'redirects' do - expect(response).to be_redirect - end - end - - context 'with a signed in user' do - before do - sign_in(Fabricate(:user)) - get :index - end - - it 'returns http success' do - expect(response).to have_http_status(200) - end - - it 'returns private cache control headers' do - expect(response.headers['Cache-Control']).to include('private, no-store') - end - end - end -end diff --git a/spec/requests/filters_spec.rb b/spec/requests/filters_spec.rb new file mode 100644 index 0000000000..a7b2eddc1b --- /dev/null +++ b/spec/requests/filters_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Filters' do + describe 'GET /filters' do + context 'with signed out user' do + it 'redirects to sign in page' do + get filters_path + + expect(response) + .to redirect_to(new_user_session_path) + end + end + end +end diff --git a/spec/system/filters_spec.rb b/spec/system/filters_spec.rb index 64de384c00..e681c6940e 100644 --- a/spec/system/filters_spec.rb +++ b/spec/system/filters_spec.rb @@ -8,6 +8,18 @@ RSpec.describe 'Filters' do before { sign_in(user) } + describe 'Viewing existing filters' do + before { Fabricate :custom_filter, account: user.account, phrase: 'Photography' } + + it 'shows a list of user filters' do + visit filters_path + + expect(page) + .to have_content('Photography') + .and have_private_cache_control + end + end + describe 'Creating a filter' do it 'Populates a new filter from form' do navigate_to_filters @@ -16,12 +28,22 @@ RSpec.describe 'Filters' do fill_in_filter_form expect(page).to have_content(filter_title) end + + it 'Does not save with invalid values' do + navigate_to_filters + click_on I18n.t('filters.new.title') + + expect { click_on I18n.t('filters.new.save') } + .to_not change(CustomFilter, :count) + expect(page) + .to have_content("can't be blank") + end end describe 'Editing an existing filter' do let(:new_title) { 'Change title value' } - before { Fabricate :custom_filter, account: user.account, title: filter_title } + let!(:custom_filter) { Fabricate :custom_filter, account: user.account, title: filter_title } it 'Updates the saved filter' do navigate_to_filters @@ -33,6 +55,18 @@ RSpec.describe 'Filters' do expect(page).to have_content(new_title) end + + it 'Does not save with invalid values' do + navigate_to_filters + click_on filter_title + + fill_in filter_title_field, with: '' + + expect { click_on submit_button } + .to_not(change { custom_filter.reload.updated_at }) + expect(page) + .to have_content("can't be blank") + end end describe 'Destroying an existing filter' do