Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change item seeding removal strategy #4264

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/mailers/account_request_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe AccountRequestMailer, type: :mailer, seed_items: false do
RSpec.describe AccountRequestMailer, type: :mailer, skip_seed: true do
describe '#confirmation' do
let(:mail) { AccountRequestMailer.confirmation(account_request_id: account_request_id) }
let(:account_request_id) { account_request.id }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/custom_devise_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe CustomDeviseMailer, type: :mailer, seed_items: false do
RSpec.describe CustomDeviseMailer, type: :mailer, skip_seed: true do
describe "#invitation_instructions" do
let(:user) { create(:partner_user) }
let(:mail) { described_class.invitation_instructions(user, SecureRandom.uuid) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/distribution_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe DistributionMailer, type: :mailer, seed_items: false do
RSpec.describe DistributionMailer, type: :mailer, skip_seed: true do
let(:organization) { create(:organization, skip_items: true, name: "TEST ORG") }
let(:user) { create(:user, organization: organization) }
let(:partner) { create(:partner, name: 'PARTNER', organization_id: organization.id) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/organization_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe OrganizationMailer, type: :mailer, seed_items: false do
RSpec.describe OrganizationMailer, type: :mailer, skip_seed: true do
describe "#partner_approval_request" do
subject { described_class.partner_approval_request(organization: organization, partner: partner) }
let(:organization) { create(:organization, skip_items: true) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/partner_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe PartnerMailer, type: :mailer, seed_items: false do
RSpec.describe PartnerMailer, type: :mailer, skip_seed: true do
describe "#recertification_request" do
subject { PartnerMailer.recertification_request(partner: partner) }
let(:partner) { create(:partner) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/reminder_deadline_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe ReminderDeadlineMailer, type: :job, seed_items: false do
RSpec.describe ReminderDeadlineMailer, type: :job do
let(:organization) { create(:organization, skip_items: true) }

describe 'notify deadline' do
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/request_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe RequestMailer, type: :mailer, seed_items: false do
RSpec.describe RequestMailer, type: :mailer, skip_seed: true do
describe "#request_cancel_partner_notification" do
subject { described_class.request_cancel_partner_notification(request_id: request.id) }
let(:request) { create(:request) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/requests_confirmation_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe RequestsConfirmationMailer, type: :mailer, seed_items: false do
RSpec.describe RequestsConfirmationMailer, type: :mailer, skip_seed: true do
let(:organization) { create(:organization, :with_items) }
let(:request) { create(:request, organization: organization) }
let(:mail) { RequestsConfirmationMailer.confirmation_email(request) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe User, type: :mailer, seed_items: false do
RSpec.describe User, type: :mailer, skip_seed: true do
describe "#role_added" do
let(:user) { create(:user, email: "[email protected]") }
let(:partner) { create(:partner, name: "Partner 1") }
Expand Down
27 changes: 22 additions & 5 deletions spec/rails_helper.rb
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only real file with changes worth looking at, all the rest is adding tags to spec files.

Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ def seed_base_data_for_tests
]
)
end

seed_base_data_for_tests if !ENV["SKIP_SEED"]
end

config.before(:each, type: :system) do
Expand All @@ -214,10 +212,29 @@ def seed_base_data_for_tests
Capybara.server = :puma, { Silent: true }
end

config.before(:each) do
# Defined shared @ global variables used throughout the test suite.
define_global_variables if RSpec.current_example.metadata[:seed_items] != false
config.before(:all) do
seed_current = self.class.metadata[:skip_seed].nil? || self.class.metadata[:skip_seed] == false
seeded_last = Thread.current[:seeded_last]

if seeded_last && !seed_current
DatabaseCleaner.clean_with(:truncation)
elasticspoon marked this conversation as resolved.
Show resolved Hide resolved
end

if seeded_last && seed_current
define_global_variables
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reorganize this a bit like so:

if seeded_last && !seed_current
  DatabaseCleaner.clean_with(:truncation) # remove previously seeded data
end
if seed_current
  seed_base_data_for_tests if !seeded_last # need to re-seed data
  define_global_variables
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was doing it the other way do be explicit about all the cases, also why I added the comment about the !seeded && !seeded case. You think this is better?

end

if !seeded_last && seed_current
seed_base_data_for_tests
define_global_variables
end

# if !seeded_last && !seed_current do nothing

Thread.current[:seeded_last] = seed_current
end

config.before(:each) do
if ENV['EVENTS_READ'] == 'true'
allow(Event).to receive(:read_events?).and_return(true)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/product_drives_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe "ProductDrives", type: :request, skip_seed: true do
RSpec.describe "ProductDrives", type: :request do
let(:organization) { create(:organization) }
let(:user) { create(:user, organization: organization) }
let(:default_params) { { organization_name: organization.to_param } }
Expand Down
2 changes: 1 addition & 1 deletion spec/services/organization_update_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe OrganizationUpdateService, skip_seed: true do
RSpec.describe OrganizationUpdateService do
let(:organization) { create(:organization) }

describe "#update" do
Expand Down
1 change: 0 additions & 1 deletion spec/services/partner_profile_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
expect(result.error.to_s).to include("Validation failed: Total client share must be 0 or 100")

profile.reload
puts profile.served_areas.size
expect(profile.served_areas.size).to eq(0)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/user_invite_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe UserInviteService, type: :service, skip_seed: true do
RSpec.describe UserInviteService, type: :service do
let(:organization) { FactoryBot.create(:organization) }
before(:each) do
allow(UserMailer).to receive(:role_added).and_return(double(:mail, deliver_later: nil))
Expand Down