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

Resolves #4686 add another bank to seed #4826

Merged
merged 25 commits into from
Dec 14, 2024

Conversation

Benjamin-Couey
Copy link
Contributor

Resolves #4685

Description

This PR modifies the db/seeds.rb file to add another diaper bank with a partner and other associated records. CONTRIBUTING.md was also updated to include the login information for the new diaper bank and partner.

In total, the following records were added to the seed:

  • The new Organization Second City Essentials Bank
  • Four items unique to the new bank, each based on a random BaseItem, named "Second City Item 1"
  • New Users for the new bank, "second_city_admin@example.com" and "second_city_user@example.com"
  • 20 Donations and Distributions for the new bank
  • 25 Purchases for the new bank
  • DonationSites for the new bank, based on the city and state of the bank.
  • Two StorageLocations for the new bank.
  • Request Units, ProductDrives, ProductDriveParticipants, Manufacturers, and 'Vendor's for the new bank.
  • The new Partner "Second City Senior Center"
  • Several Requests made by the new partner to the new bank (this was handled by exiting Partner seeding code).

The seed uses both hand-written values and the Faker library to populate addresses, emails, etc. When creating entirely new records, I favored Faker for the sake of better looking demos but didn't update existing hand-written values.

For most of the records associated with an Organization, the seed only created records for the Pawnee Diaper Bank. I updated these sections to only create records for the new bank and not the existing SF Diaper Bank as they was not requested by the issue. I tried to modify the code so that it would be easy to define a list of banks for which these records should be created.

Type of change

  • New feature
  • Documentation update

How Has This Been Tested?

As far as I could tell, there were no automated tests associated with the seed and so relied on manual verification. I verified that rake db:reset runs without issues with the modified seed and manually verified that the database contained the new records associated with the new bank.

I created a unit test for a utility function added to Organization.

Benjamin-Couey and others added 19 commits November 22, 2024 09:19
…all orgs, removed redundant Product Drives section
…storage locations are selected to accommodate there being storage locations for multiple orgs
@cielf
Copy link
Collaborator

cielf commented Dec 3, 2024

Hey @Benjamin-Couey - I'm liking what I'm seeing from a functional pov. With the second city items, I have one question, though.

Are we guaranteed to have at least one each of donation, purchase, distribution, and request among those 4 items?

My concern is false positives when we are using them for manual testing -- that, with these extra items, we would rely on there being instances with them, and if there aren't, we might assume that everything is fine.

@cielf cielf requested a review from dorner December 3, 2024 17:58
@Benjamin-Couey
Copy link
Contributor Author

@cielf There is currently no guarantee that the second city items will be used for the donations, purchases, distributions, and requests.

I can work on explicitly adding examples of those records using the second city items.

@cielf
Copy link
Collaborator

cielf commented Dec 3, 2024

(Nods) Yes please.
I haven't checked, but could you also make sure at least one of them has an inventory level that is less than its recommended quantity?

… for donations, purchases, distributions, and requests
…he new bank's items, guarantee that at least one of the items unique to the new bank has an inventory less than the recommended quantity
@Benjamin-Couey
Copy link
Contributor Author

Alright, I pushed two commits to ensure that there are examples of donations, purchases, distributions, and requests using the unique items and that one of the unique items has a lower stock than its recommended quantity at all new storage locations.

@cielf
Copy link
Collaborator

cielf commented Dec 4, 2024

Thanks @Benjamin-Couey . Just to manage expectations, we're a bit snowed under on the reviewing side right now, and our main technical staff are not available for the next few days, so it might be a few days before this gets final-reviewed.

# At least one of the items is marked as inactive
Organization.all.each do |org|
Organization.all.find_each do |org|
Copy link
Collaborator

@coalest coalest Dec 5, 2024

Choose a reason for hiding this comment

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

nit: I think we weren't using find_each in this file because it's useful when you have many records in the db. And I don't believe we will have more than a few hundred records of any type during seeding.

But either way works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using find_each instead of each was actually a change made by the linter. If the use of each was intentional, perhaps we need to configure the linter to not automatically make this change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

find_each is pretty much always a better approach than each. There isn't really a case where the other way around is better.

db/seeds.rb Outdated
# Add a couple unique items based on random base items named after the sc_bank
# so it will be clear if they are showing up where they aren't supposed to be
4.times.each do |time|
sc_org.seed_random_item_with_name("Second City Item ##{time + 1}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Not sure the value of abstracting this logic into a new method. We could just create four new items here and then call sc_org.seed_items(second_city_only_items). And having all the logic in this file makes it easier to read imo.

But up to you.

Also another nit, I think the block parameter would normally be named index or i here. But doesn't really matter.

Copy link
Contributor Author

@Benjamin-Couey Benjamin-Couey Dec 6, 2024

Choose a reason for hiding this comment

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

Yes, time should absolutely be index as that convention is used elsewhere in the file. It's even used elsewhere in this PR.

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Checked it out by doing a bin/setup. It looks to me like it has everything we want . @dorner do you have any concerns?

CONTRIBUTING.md Outdated
Password: password!
```

Second City Essentials Bank
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be worth it to specify what the difference is between these accounts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It certainly would.

The biggest difference is that SF Diaper Bank is a brand new bank that hasn't been set up yet.

Now that you mention it, I'd suggest putting ordering them as Pawnee, then Second City, then SF, with a note on SF Diaper bank at the end with a note that it is a freshly accepted bank (i.e. not yet set up)

We might tune Second City to have more particular characteristics as we find things that are hard to test on Pawnee, but for now its main purpose is so we have multiple in-flight organizations while we test.

@@ -223,6 +223,13 @@ def seed_items(item_collection)
reload
end

def seed_random_item_with_name(name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't go on Organization if it's only used to create seed data. It should be a method in seeds.rb.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Am I correct in assuming I should then discard the associated unit test, since the other functions in seed.rb lack them?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct.

db/seeds.rb Outdated
org.items.order(created_at: :desc).last.update(active: false)
end

# Add a couple unique items based on random base items named after the sc_bank
# so it will be clear if they are showing up where they aren't supposed to be
4.times.each do |index|
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need each, you can just do 4.times do .

@cielf
Copy link
Collaborator

cielf commented Dec 13, 2024

Noting there are some conflicts to be resolved.

@Benjamin-Couey
Copy link
Contributor Author

Apologies for the delay, but commits have been made to address @dorner's requests and resolve the merge conflicts with main.

@dorner dorner merged commit 49c9308 into rubyforgood:main Dec 14, 2024
12 checks passed
@dorner
Copy link
Collaborator

dorner commented Dec 14, 2024

Looks good - thanks!

Copy link
Contributor

@Benjamin-Couey: Your PR Resolves #4686 add another bank to seed is part of today's Human Essentials production release: 2024.12.15.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add another fully set up bank to the seed.
4 participants