From 273402e20c86aff026ae7e0db4cd2421b44edc06 Mon Sep 17 00:00:00 2001 From: ulferts Date: Tue, 3 Dec 2019 15:44:24 +0100 Subject: [PATCH] stabilize flickering request spec --- .../form/work_package_form_resource_spec.rb | 12 +++++++++--- spec/services/relations/update_service_spec.rb | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb index 226e37bb09..7bd0aa203f 100644 --- a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb @@ -29,7 +29,7 @@ require 'spec_helper' require 'rack/test' -describe 'API v3 Work package form resource', type: :request do +describe 'API v3 Work package form resource', type: :request, with_mail: false do include Rack::Test::Methods include Capybara::RSpecMatchers include API::V3::Utilities::PathHelper @@ -37,7 +37,13 @@ describe 'API v3 Work package form resource', type: :request do shared_let(:all_allowed_permissions) { %i[view_work_packages edit_work_packages assign_versions] } shared_let(:assign_permissions) { %i[view_work_packages assign_versions] } shared_let(:project) { FactoryBot.create(:project, public: false) } - shared_let(:work_package) { FactoryBot.create(:work_package, project: project) } + shared_let(:work_package) do + # Prevent executing as potentially unsaved AnyonymousUser which would + # lead to the creation failing as the journal cannot be written with user_id = nil. + User.execute_as authorized_user do + FactoryBot.create(:work_package, project: project) + end + end shared_let(:authorized_user) do FactoryBot.create(:user, member_in_project: project, member_with_permissions: all_allowed_permissions) end @@ -59,7 +65,7 @@ describe 'API v3 Work package form resource', type: :request do shared_context 'post request' do before(:each) do - allow(User).to receive(:current).and_return current_user + login_as(current_user) post post_path, (params ? params.to_json : nil), 'CONTENT_TYPE' => 'application/json' end end diff --git a/spec/services/relations/update_service_spec.rb b/spec/services/relations/update_service_spec.rb index 544288fa17..23a1a1e832 100644 --- a/spec/services/relations/update_service_spec.rb +++ b/spec/services/relations/update_service_spec.rb @@ -40,12 +40,12 @@ describe Relations::UpdateService do let(:delay) { 3 } let(:work_package1) do - FactoryBot.build_stubbed(:work_package, + FactoryBot.build_stubbed(:stubbed_work_package, due_date: work_package1_due_date, start_date: work_package1_start_date) end let(:work_package2) do - FactoryBot.build_stubbed(:work_package, + FactoryBot.build_stubbed(:stubbed_work_package, due_date: work_package2_due_date, start_date: work_package2_start_date) end