From ddfbf6139ec37fbe6ac9ed535c13b29d5730d7dc Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Thu, 18 Jun 2020 13:51:25 +0200 Subject: [PATCH] Maintenance: Unified `:authenticated` and `:authenticated_as` helpers to just `:authenticated_as` in `system` and `request` specs. --- .../admin/knowledge_base/public_menu_spec.rb | 3 +- .../answer_attachments_cloning_spec.rb | 4 +- .../knowledge_base/attachments_spec.rb | 101 +++++++++++++----- .../loading_initial_data_spec.rb | 16 ++- .../knowledge_base/translation_update_spec.rb | 29 +++-- spec/support/authenticated_as.rb | 68 ++++++++++++ spec/support/capybara/authenticated.rb | 27 +---- spec/support/request.rb | 10 +- .../admin/knowledge_base/public_menu_spec.rb | 2 +- spec/system/basic/authentication_spec.rb | 2 +- spec/system/basic/redirects_spec.rb | 2 +- spec/system/dashboard_spec.rb | 2 +- spec/system/js/q_unit_spec.rb | 2 +- .../knowledge_base/locale/answer/edit_spec.rb | 2 +- .../knowledge_base_public/answer_spec.rb | 2 +- .../editor_search_spec.rb | 2 +- .../knowledge_base_public/editor_spec.rb | 2 +- .../guest_search_spec.rb | 2 +- .../knowledge_base_public/guest_spec.rb | 2 +- .../knowledge_base_public/menu_items_spec.rb | 2 +- spec/system/login/message_spec.rb | 2 +- spec/system/profile/devices_spec.rb | 2 +- spec/system/setup/system_spec.rb | 2 +- spec/system/ticket/create_spec.rb | 4 +- .../inserting_knowledge_base_answer_spec.rb | 2 +- .../linking_knowledge_base_answer_spec.rb | 2 +- spec/system/ticket/zoom_spec.rb | 6 +- 27 files changed, 209 insertions(+), 93 deletions(-) create mode 100644 spec/support/authenticated_as.rb diff --git a/spec/requests/admin/knowledge_base/public_menu_spec.rb b/spec/requests/admin/knowledge_base/public_menu_spec.rb index 4c89634d2..48ca1a7dd 100644 --- a/spec/requests/admin/knowledge_base/public_menu_spec.rb +++ b/spec/requests/admin/knowledge_base/public_menu_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Admin Knowledge Base Public Menu', type: :request, authenticated_as: :admin_user do +RSpec.describe 'Admin Knowledge Base Public Menu', type: :request, authenticated_as: :current_user do let(:url) { "/api/v1/knowledge_bases/manage/#{knowledge_base.id}/update_menu_items" } let(:params) do { @@ -12,6 +12,7 @@ RSpec.describe 'Admin Knowledge Base Public Menu', type: :request, authenticated } end + let(:current_user) { create(:admin) } let(:menu_item) { create(:knowledge_base_menu_item) } let(:kb_locale) { menu_item.kb_locale } let(:knowledge_base) { kb_locale.knowledge_base } diff --git a/spec/requests/knowledge_base/answer_attachments_cloning_spec.rb b/spec/requests/knowledge_base/answer_attachments_cloning_spec.rb index b384f2d1f..2042b491d 100644 --- a/spec/requests/knowledge_base/answer_attachments_cloning_spec.rb +++ b/spec/requests/knowledge_base/answer_attachments_cloning_spec.rb @@ -1,12 +1,14 @@ require 'rails_helper' -RSpec.describe 'KnowledgeBase answer attachments cloning', type: :request, authenticated_as: :agent_user do +RSpec.describe 'KnowledgeBase answer attachments cloning', type: :request, authenticated_as: :current_user do include_context 'basic Knowledge Base' do before do published_answer end end + let(:current_user) { create(:agent) } + it 'copies to given UploadCache' do form_id = Random.rand(999..9999) endpoint = "/api/v1/knowledge_bases/#{knowledge_base.id}/answers/#{published_answer.id}/attachments/clone_to_form" diff --git a/spec/requests/knowledge_base/attachments_spec.rb b/spec/requests/knowledge_base/attachments_spec.rb index dff5cc402..cfcad080a 100644 --- a/spec/requests/knowledge_base/attachments_spec.rb +++ b/spec/requests/knowledge_base/attachments_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'KnowledgeBase attachments', type: :request do +RSpec.describe 'KnowledgeBase attachments', type: :request, authenticated_as: :current_user do include_context 'basic Knowledge Base' let(:attachment) do @@ -16,7 +16,8 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do ) end - let(:endpoint) { "/api/v1/attachments/#{attachment.id}" } + let(:endpoint) { "/api/v1/attachments/#{attachment.id}" } + let(:current_user) { create(user_identifier) if defined?(user_identifier) } describe 'visible when attached to' do shared_examples 'a visible resource' do @@ -36,15 +37,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'draft answer' do let(:object) { draft_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a non-existent resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a visible resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-existent resource' end @@ -56,15 +63,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'internal answer' do let(:object) { internal_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a visible resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a visible resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-existent resource' end @@ -76,15 +89,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'published answer' do let(:object) { published_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a visible resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a visible resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a visible resource' end @@ -96,15 +115,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'archived answer' do let(:object) { archived_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a non-existent resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a visible resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-existent resource' end @@ -126,15 +151,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'draft answer' do let(:object) { draft_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a non-deletable resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a deletable resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-deletable resource' end @@ -146,15 +177,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'internal answer' do let(:object) { internal_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a non-deletable resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a deletable resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-deletable resource' end @@ -166,15 +203,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'published answer' do let(:object) { published_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a non-deletable resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a deletable resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-deletable resource' end @@ -186,15 +229,21 @@ RSpec.describe 'KnowledgeBase attachments', type: :request do describe 'archived answer' do let(:object) { archived_answer } - describe 'as agent', authenticated_as: :agent_user do + describe 'as agent' do + let(:user_identifier) { :agent } + it_behaves_like 'a non-deletable resource' end - context 'as admin', authenticated_as: :admin_user do + context 'as admin' do + let(:user_identifier) { :admin } + it_behaves_like 'a deletable resource' end - context 'as customer', authenticated_as: :customer_user do + context 'as customer' do + let(:user_identifier) { :customer } + it_behaves_like 'a non-deletable resource' end diff --git a/spec/requests/knowledge_base/loading_initial_data_spec.rb b/spec/requests/knowledge_base/loading_initial_data_spec.rb index e6354d740..d71940931 100644 --- a/spec/requests/knowledge_base/loading_initial_data_spec.rb +++ b/spec/requests/knowledge_base/loading_initial_data_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'KnowledgeBase loading initial data', type: :request, searchindex: true do +RSpec.describe 'KnowledgeBase loading initial data', type: :request, searchindex: true, authenticated_as: :current_user do include_context 'basic Knowledge Base' do before do draft_answer @@ -13,12 +13,16 @@ RSpec.describe 'KnowledgeBase loading initial data', type: :request, searchindex post '/api/v1/knowledge_bases/init' end + let(:current_user) { create(user_identifier) if defined?(user_identifier) } + shared_examples 'returning valid JSON' do it { expect(response).to have_http_status(:ok) } it { expect(json_response).to be_a_kind_of(Hash) } end - describe 'for admin', authenticated_as: :admin_user do + describe 'for admin' do + let(:user_identifier) { :admin } + it_behaves_like 'returning valid JSON' it 'returns assets for all KB objects' do @@ -26,7 +30,9 @@ RSpec.describe 'KnowledgeBase loading initial data', type: :request, searchindex end end - describe 'for agent', authenticated_as: :agent_user do + describe 'for agent' do + let(:user_identifier) { :agent } + it_behaves_like 'returning valid JSON' it 'returns assets for all KB objects except drafts' do @@ -36,7 +42,9 @@ RSpec.describe 'KnowledgeBase loading initial data', type: :request, searchindex end end - describe 'for customer', authenticated_as: :customer_user do + describe 'for customer' do + let(:user_identifier) { :customer } + it_behaves_like 'returning valid JSON' it 'only returns assets for KB itself' do diff --git a/spec/requests/knowledge_base/translation_update_spec.rb b/spec/requests/knowledge_base/translation_update_spec.rb index 9ba1e3c4c..c3ac94284 100644 --- a/spec/requests/knowledge_base/translation_update_spec.rb +++ b/spec/requests/knowledge_base/translation_update_spec.rb @@ -1,9 +1,10 @@ require 'rails_helper' -RSpec.describe 'KnowledgeBase translation update', type: :request, authentication: true do +RSpec.describe 'KnowledgeBase translation update', type: :request, authenticated_as: :current_user do include_context 'basic Knowledge Base' - let(:new_title) { 'new title for update test' } + let(:new_title) { 'new title for update test' } + let(:current_user) { create(user_identifier) if defined?(user_identifier) } let(:params_for_updating) do { @@ -22,19 +23,25 @@ RSpec.describe 'KnowledgeBase translation update', type: :request, authenticatio end describe 'changes KB translation title' do - describe 'as editor', authenticated_as: :admin_user do + describe 'as editor' do + let(:user_identifier) { :admin_user } + it 'updates title' do expect { request }.to change { knowledge_base.reload.translations.first.title }.to(new_title) end end - describe 'as reader', authenticated_as: :agent_user do + describe 'as reader' do + let(:user_identifier) { :agent_user } + it 'does not change title' do expect { request }.not_to change { knowledge_base.reload.translations.first.title } end end - describe 'as non-KB user', authenticated_as: :customer do + describe 'as non-KB user' do + let(:user_identifier) { :customer } + it 'does not change title' do expect { request }.not_to change { knowledge_base.reload.translations.first.title } end @@ -50,16 +57,22 @@ RSpec.describe 'KnowledgeBase translation update', type: :request, authenticatio describe 'can make request to KB translation' do before { request } - describe 'as editor', authenticated_as: :admin_user do + describe 'as editor' do + let(:user_identifier) { :admin_user } + it { expect(response).to have_http_status(:ok) } it { expect(json_response).to be_a_kind_of(Hash) } end - describe 'as reader', authenticated_as: :agent_user do + describe 'as reader' do + let(:user_identifier) { :agent_user } + it { expect(response).to have_http_status(:unauthorized) } end - describe 'as non-KB user', authenticated_as: :customer do + describe 'as non-KB user' do + let(:user_identifier) { :customer } + it { expect(response).to have_http_status(:unauthorized) } end diff --git a/spec/support/authenticated_as.rb b/spec/support/authenticated_as.rb new file mode 100644 index 000000000..85a910829 --- /dev/null +++ b/spec/support/authenticated_as.rb @@ -0,0 +1,68 @@ +module ZammadAuthenticatedAsHelper + # parse authenticated_as params for request and system test helpers + # + # @param input [Any] any to parse, see bellow for options + # @param return_type [Symbol] :credentials or :user + def authenticated_as_get_user(input, return_type:) + case input + when Proc + parse_meta instance_exec(&input), return_type: return_type + when Symbol + parse_meta instance_eval { send(input) }, return_type: return_type + else + parse_meta input, return_type: return_type + end + end + + private + + def parse_meta(input, return_type:) + case return_type + when :credentials + parse_meta_credentials(input) + when :user + parse_meta_user_object(input) + end + end + + def parse_meta_user_object(input) + case input + when User + input + end + end + + def parse_meta_credentials(input) + case input + when Hash + input.slice(:username, :password) + when User + parse_meta_user(input) + when true + { + username: 'master@example.com', + password: 'test', + } + end + end + + def parse_meta_user(input) + password = input.password_plain + + if password.blank? + password = 'automagically set by your friendly capybara helper' + input.update!(password: password) + end + + { + username: input.email, + password: password, + } + end +end + +RSpec.configure do |config| + %i[request system].each do |type| + config.include ZammadAuthenticatedAsHelper, type: type + end +end diff --git a/spec/support/capybara/authenticated.rb b/spec/support/capybara/authenticated.rb index d2abb078f..9498c90c9 100644 --- a/spec/support/capybara/authenticated.rb +++ b/spec/support/capybara/authenticated.rb @@ -13,30 +13,9 @@ RSpec.configure do |config| # there is no way to authenticated in a not set up system next if !example.metadata.fetch(:set_up, true) - # check if authentication should be performed - authenticated = example.metadata.fetch(:authenticated, true) - next if authenticated.blank? + authenticated = example.metadata.fetch(:authenticated_as, true) + credentials = authenticated_as_get_user(authenticated, return_type: :credentials) - if authenticated.is_a?(Proc) - user = instance_exec(&authenticated) - password = user.password_plain - - if password.blank? - password = 'automagically set by your friendly capybara helper' - user.update!(password: password) - end - - credentials = { - username: user.email, - password: password, - } - else - credentials = { - username: 'master@example.com', - password: 'test', - } - end - - login(credentials) + login(credentials) if credentials end end diff --git a/spec/support/request.rb b/spec/support/request.rb index 4c7d224ec..032f017dc 100644 --- a/spec/support/request.rb +++ b/spec/support/request.rb @@ -147,13 +147,9 @@ RSpec.configure do |config| # # let(:user) { create(:customer_user) } # - config.before(:each, :authenticated_as) do |example| - @current_user = if example.metadata[:authenticated_as].is_a? Proc - instance_exec(&example.metadata[:authenticated_as]) - else - create(*Array(example.metadata[:authenticated_as])) - end + config.before(:each, :authenticated_as, type: :request) do |example| + user = authenticated_as_get_user example.metadata[:authenticated_as], return_type: :user - authenticated_as @current_user unless @current_user.nil? + authenticated_as user if user end end diff --git a/spec/system/admin/knowledge_base/public_menu_spec.rb b/spec/system/admin/knowledge_base/public_menu_spec.rb index 61d9e13bb..d5162aa00 100644 --- a/spec/system/admin/knowledge_base/public_menu_spec.rb +++ b/spec/system/admin/knowledge_base/public_menu_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' # https://github.com/zammad/zammad/issues/266 -RSpec.describe 'Admin Panel > Knowledge Base > Public Menu', type: :system, authenticated: true do +RSpec.describe 'Admin Panel > Knowledge Base > Public Menu', type: :system, authenticated_as: true do include_context 'basic Knowledge Base' include_context 'Knowledge Base menu items' diff --git a/spec/system/basic/authentication_spec.rb b/spec/system/basic/authentication_spec.rb index b6ab66cb7..ff33b00a8 100644 --- a/spec/system/basic/authentication_spec.rb +++ b/spec/system/basic/authentication_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe 'Authentication', type: :system do - it 'Login', authenticated: false do + it 'Login', authenticated_as: false do login( username: 'master@example.com', password: 'test', diff --git a/spec/system/basic/redirects_spec.rb b/spec/system/basic/redirects_spec.rb index a12a62c58..4f3b13e52 100644 --- a/spec/system/basic/redirects_spec.rb +++ b/spec/system/basic/redirects_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Unauthenticated redirect', type: :system, authenticated: false do +RSpec.describe 'Unauthenticated redirect', type: :system, authenticated_as: false do it 'Sessions' do visit 'system/sessions' diff --git a/spec/system/dashboard_spec.rb b/spec/system/dashboard_spec.rb index d6e359a57..c4a3ae697 100644 --- a/spec/system/dashboard_spec.rb +++ b/spec/system/dashboard_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Dashboard', type: :system, authenticated: true do +RSpec.describe 'Dashboard', type: :system, authenticated_as: true do it 'shows default widgets' do visit 'dashboard' diff --git a/spec/system/js/q_unit_spec.rb b/spec/system/js/q_unit_spec.rb index 1ad1d3251..25ea10d28 100644 --- a/spec/system/js/q_unit_spec.rb +++ b/spec/system/js/q_unit_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'QUnit', type: :system, authenticated: false, set_up: true, websocket: false do +RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, websocket: false do def q_unit_tests(test_name) diff --git a/spec/system/knowledge_base/locale/answer/edit_spec.rb b/spec/system/knowledge_base/locale/answer/edit_spec.rb index 2e25160f5..dc27a6e5c 100644 --- a/spec/system/knowledge_base/locale/answer/edit_spec.rb +++ b/spec/system/knowledge_base/locale/answer/edit_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Knowledge Base Locale Answer Edit', type: :system, authenticated: true do +RSpec.describe 'Knowledge Base Locale Answer Edit', type: :system, authenticated_as: true do include_context 'basic Knowledge Base' before do diff --git a/spec/system/knowledge_base_public/answer_spec.rb b/spec/system/knowledge_base_public/answer_spec.rb index a84ee4cf9..0d8f78366 100644 --- a/spec/system/knowledge_base_public/answer_spec.rb +++ b/spec/system/knowledge_base_public/answer_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base answer', type: :system, authenticated: false do +RSpec.describe 'Public Knowledge Base answer', type: :system, authenticated_as: false do include_context 'basic Knowledge Base' context 'video content' do diff --git a/spec/system/knowledge_base_public/editor_search_spec.rb b/spec/system/knowledge_base_public/editor_search_spec.rb index 3c4f09d89..9fe36edcc 100644 --- a/spec/system/knowledge_base_public/editor_search_spec.rb +++ b/spec/system/knowledge_base_public/editor_search_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base for guest search', type: :system, authenticated: true, searchindex: true do +RSpec.describe 'Public Knowledge Base for guest search', type: :system, authenticated_as: true, searchindex: true do include_context 'basic Knowledge Base' before do diff --git a/spec/system/knowledge_base_public/editor_spec.rb b/spec/system/knowledge_base_public/editor_spec.rb index f28388216..45a5cef7c 100644 --- a/spec/system/knowledge_base_public/editor_spec.rb +++ b/spec/system/knowledge_base_public/editor_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base for editor', type: :system, authenticated: true do +RSpec.describe 'Public Knowledge Base for editor', type: :system, authenticated_as: true do include_context 'basic Knowledge Base' before do diff --git a/spec/system/knowledge_base_public/guest_search_spec.rb b/spec/system/knowledge_base_public/guest_search_spec.rb index 09e3c7a9c..8c22190a6 100644 --- a/spec/system/knowledge_base_public/guest_search_spec.rb +++ b/spec/system/knowledge_base_public/guest_search_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base for guest search', type: :system, authenticated: false, searchindex: true do +RSpec.describe 'Public Knowledge Base for guest search', type: :system, authenticated_as: false, searchindex: true do include_context 'basic Knowledge Base' before do diff --git a/spec/system/knowledge_base_public/guest_spec.rb b/spec/system/knowledge_base_public/guest_spec.rb index c3368528d..11ba9845b 100644 --- a/spec/system/knowledge_base_public/guest_spec.rb +++ b/spec/system/knowledge_base_public/guest_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base for guest', type: :system, authenticated: false do +RSpec.describe 'Public Knowledge Base for guest', type: :system, authenticated_as: false do include_context 'basic Knowledge Base' before do diff --git a/spec/system/knowledge_base_public/menu_items_spec.rb b/spec/system/knowledge_base_public/menu_items_spec.rb index e291e2190..6e9f17981 100644 --- a/spec/system/knowledge_base_public/menu_items_spec.rb +++ b/spec/system/knowledge_base_public/menu_items_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base menu items', type: :system, authenticated: false do +RSpec.describe 'Public Knowledge Base menu items', type: :system, authenticated_as: false do include_context 'basic Knowledge Base' include_context 'Knowledge Base menu items' diff --git a/spec/system/login/message_spec.rb b/spec/system/login/message_spec.rb index 3ad4ab647..209c95899 100644 --- a/spec/system/login/message_spec.rb +++ b/spec/system/login/message_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Login Message', type: :system, authenticated: false do +RSpec.describe 'Login Message', type: :system, authenticated_as: false do context 'with maintenance_login_message' do let(:message) { "badum tssss #{rand(99_999)}" } let(:alt_message) { 'lorem ipsum' } diff --git a/spec/system/profile/devices_spec.rb b/spec/system/profile/devices_spec.rb index bac516fd2..839120b64 100644 --- a/spec/system/profile/devices_spec.rb +++ b/spec/system/profile/devices_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Profile > Devices', type: :system, authenticated: true do +RSpec.describe 'Profile > Devices', type: :system, authenticated_as: true do subject!(:device) { create(:user_device, user_id: User.find_by(login: 'master@example.com').id) } it 'allows to remove device' do diff --git a/spec/system/setup/system_spec.rb b/spec/system/setup/system_spec.rb index e0dba89a9..782dc8764 100644 --- a/spec/system/setup/system_spec.rb +++ b/spec/system/setup/system_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'System setup process', type: :system, set_up: false do raise "Unable to get fqdn based on #{app_host}" end - it 'Setting up a new system', authenticated: false do + it 'Setting up a new system', authenticated_as: false do if !ENV['MAILBOX_INIT'] skip("NOTICE: Need MAILBOX_INIT as ENV variable like export MAILBOX_INIT='unittest01@znuny.com:somepass'") diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index 6a1b4bfda..915052d37 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -10,7 +10,7 @@ RSpec.describe 'Ticket Create', type: :system do let!(:template) { create(:template, :dummy_data, group: unpermitted_group, owner: agent) } # Regression test for issue #2424 - Unavailable ticket template attributes get applied - it 'unavailable attributes do not get applied', authenticated: -> { agent } do + it 'unavailable attributes do not get applied', authenticated_as: :agent do visit 'ticket/create' use_template(template) @@ -55,7 +55,7 @@ RSpec.describe 'Ticket Create', type: :system do end end - context 'private key configured', authenticated: -> { agent } do + context 'private key configured', authenticated_as: :agent do let!(:template) { create(:template, :dummy_data, group: group, owner: agent, customer: customer) } let(:system_email_address) { 'smime1@example.com' } diff --git a/spec/system/ticket/inserting_knowledge_base_answer_spec.rb b/spec/system/ticket/inserting_knowledge_base_answer_spec.rb index 58989a5eb..38975b3fb 100644 --- a/spec/system/ticket/inserting_knowledge_base_answer_spec.rb +++ b/spec/system/ticket/inserting_knowledge_base_answer_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'inserting Knowledge Base answer', type: :system, authenticated: true, searchindex: true do +RSpec.describe 'inserting Knowledge Base answer', type: :system, authenticated_as: true, searchindex: true do include_context 'basic Knowledge Base' let(:field) { find(:richtext) } diff --git a/spec/system/ticket/linking_knowledge_base_answer_spec.rb b/spec/system/ticket/linking_knowledge_base_answer_spec.rb index 8cc81976d..ec940e623 100644 --- a/spec/system/ticket/linking_knowledge_base_answer_spec.rb +++ b/spec/system/ticket/linking_knowledge_base_answer_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'linking Knowledge Base answer', type: :system, authenticated: true, searchindex: true do +RSpec.describe 'linking Knowledge Base answer', type: :system, authenticated_as: true, searchindex: true do include_context 'basic Knowledge Base' before do diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 19fb9a390..37aae6f57 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -185,7 +185,7 @@ RSpec.describe 'Ticket zoom', type: :system do create(:ticket_article, ticket: ticket) end - it 'ensures that text input opens on multiple replies', authenticated: -> { current_user } do + it 'ensures that text input opens on multiple replies', authenticated_as: :current_user do visit "ticket/zoom/#{ticket.id}" 2.times do |article_offset| @@ -207,7 +207,7 @@ RSpec.describe 'Ticket zoom', type: :system do end end - describe 'delete article', authenticated: -> { user } do + describe 'delete article', authenticated_as: :user do let(:admin_user) { create :admin, groups: [Group.first] } let(:agent_user) { create :agent, groups: [Group.first] } let(:customer_user) { create :customer } @@ -395,7 +395,7 @@ RSpec.describe 'Ticket zoom', type: :system do end end - context 'S/MIME active', authenticated: -> { agent } do + context 'S/MIME active', authenticated_as: :agent do let(:system_email_address) { 'smime1@example.com' } let(:email_address) { create(:email_address, email: system_email_address) }