Skip to content

Commit

Permalink
Make spec/models/mail_handler_spec.rb faster
Browse files Browse the repository at this point in the history
Using `shared_let` for caching project creation lead to almost twice faster spec run time (33 secs to 17 secs).
  • Loading branch information
cbliard committed Dec 21, 2023
1 parent fd3ece7 commit 1e870a0
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions spec/models/mail_handler_spec.rb
Expand Up @@ -29,18 +29,15 @@
require 'spec_helper'

RSpec.describe MailHandler do
let(:anno_user) { User.anonymous }
let(:project) { create(:valid_project, identifier: 'onlinestore', name: 'OnlineStore', public: false) }
let(:public_project) { create(:valid_project, identifier: 'onlinestore', name: 'OnlineStore', public: true) }
let(:priority_low) { create(:priority_low, is_default: true) }
# we need these run first so the anonymous and system users are created and
# there is a default work package priority to save any work packages
shared_let(:anno_user) { User.anonymous }
shared_let(:system_user) { User.system }
shared_let(:priority_low) { create(:priority_low, name: 'Low', is_default: true) }

before do
# we need both of these run first so the anonymous user is created and
# there is a default work package priority to save any work packages
priority_low
anno_user
User.system
shared_let(:project) { create(:valid_project, identifier: 'onlinestore', name: 'OnlineStore', public: false) }

before do
allow(UserMailer)
.to receive(:incoming_email_error)
.and_return instance_double(ActionMailer::MessageDelivery, deliver_later: nil)
Expand Down Expand Up @@ -874,8 +871,9 @@
end

subject do
project.update(public: true)
submit_email('ticket_from_emission_address.eml',
issue: { project: public_project.identifier },
issue: { project: project.identifier },
unknown_user: 'create')
end

Expand Down Expand Up @@ -918,7 +916,6 @@
context 'for wp with status case insensitive' do
let(:type) { project.types.first }
let!(:status) { create(:status, name: 'Resolved', workflow_for_type: type) }
let!(:priority_low) { create(:priority_low, name: 'Low', is_default: true) }
let!(:version) { create(:version, name: 'alpha', project:) }

# This email contains: 'Project: onlinestore' and 'Status: resolved'
Expand Down

0 comments on commit 1e870a0

Please sign in to comment.