diff --git a/app/controllers/admin/base_items_controller.rb b/app/controllers/admin/base_items_controller.rb index b7489d706a..e423c08b49 100644 --- a/app/controllers/admin/base_items_controller.rb +++ b/app/controllers/admin/base_items_controller.rb @@ -42,9 +42,9 @@ def show def destroy @base_item = BaseItem.includes(:items).find(params[:id]) - if (@base_item.id = KitCreateService.find_or_create_kit_base_item!.id) + if @base_item.id == KitCreateService.find_or_create_kit_base_item!.id redirect_to admin_base_items_path, alert: "You cannot delete the Kits base item. This is reserved for all Kits." - elsif @base_item.items.any? && @base_item.destroy + elsif @base_item.items.empty? && @base_item.destroy redirect_to admin_base_items_path, notice: "Base Item deleted!" else redirect_to admin_base_items_path, alert: "Failed to delete Base Item. Are there still items attached?" diff --git a/db/seeds.rb b/db/seeds.rb index fd7f8545d7..c99dc7415a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -23,8 +23,8 @@ def random_record_for_org(org, klass) # Base Items # ---------------------------------------------------------------------------- -require 'seed_base_items' -seed_base_items +require 'seeds' +Seeds.seed_base_items # ---------------------------------------------------------------------------- # NDBN Members @@ -856,12 +856,12 @@ def seed_quantity(item_name, organization, storage_location, quantity) # Users invitation status # ---------------------------------------------------------------------------- # Mark users `invitation_status` as `accepted` -# +# # Addresses and resolves issue #4689, which can be found in: # https://github.com/rubyforgood/human-essentials/issues/4689 -User.where(invitation_token: nil).each do |user| +User.where(invitation_token: nil).each do |user| user.update!( invitation_sent_at: Time.current, invitation_accepted_at: Time.current ) -end \ No newline at end of file +end diff --git a/lib/seed_base_items.rb b/lib/seed_base_items.rb deleted file mode 100644 index 027aaa986f..0000000000 --- a/lib/seed_base_items.rb +++ /dev/null @@ -1,19 +0,0 @@ -def seed_base_items - # Initial starting qty for our test organizations - base_items = File.read(Rails.root.join("db", "base_items.json")) - items_by_category = JSON.parse(base_items) - - items_by_category.each do |category, entries| - entries.each do |entry| - BaseItem.find_or_create_by!( - name: entry["name"], - category: category, - partner_key: entry["key"], - updated_at: Time.zone.now, - created_at: Time.zone.now - ) - end - end - # Create global 'Kit' base item - KitCreateService.find_or_create_kit_base_item! -end diff --git a/lib/seeds.rb b/lib/seeds.rb new file mode 100644 index 0000000000..8bcc2333db --- /dev/null +++ b/lib/seeds.rb @@ -0,0 +1,21 @@ +module Seeds + def seed_base_items + # Initial starting qty for our test organizations + base_items = File.read(Rails.root.join("db", "base_items.json")) + items_by_category = JSON.parse(base_items) + + items_by_category.each do |category, entries| + entries.each do |entry| + BaseItem.find_or_create_by!( + name: entry["name"], + category: category, + partner_key: entry["key"], + updated_at: Time.zone.now, + created_at: Time.zone.now + ) + end + end + # Create global 'Kit' base item + KitCreateService.find_or_create_kit_base_item! + end +end diff --git a/spec/factories/organizations.rb b/spec/factories/organizations.rb index 9b6a0f7051..f5fa0aad71 100644 --- a/spec/factories/organizations.rb +++ b/spec/factories/organizations.rb @@ -34,7 +34,7 @@ # account_request_id :integer # ndbn_member_id :bigint # -require 'seed_base_items' +require 'seeds' FactoryBot.define do factory :organization do @@ -62,7 +62,7 @@ trait :with_items do after(:create) do |instance, evaluator| - seed_base_items if BaseItem.count.zero? # seeds 45 base items if none exist + Seeds.seed_base_items if BaseItem.count.zero? # seeds 45 base items if none exist Organization.seed_items(instance) # creates 1 item for each base item end end diff --git a/spec/services/reports/children_served_report_service_spec.rb b/spec/services/reports/children_served_report_service_spec.rb index 14e6446bd1..88b66dc536 100644 --- a/spec/services/reports/children_served_report_service_spec.rb +++ b/spec/services/reports/children_served_report_service_spec.rb @@ -42,7 +42,6 @@ create_list(:line_item, 5, :distribution, quantity: 200, item: disposable_item, itemizable: dist) create_list(:line_item, 5, :distribution, quantity: 300, item: non_disposable_item, itemizable: dist) end - # within_time total distributed i infant_distribution = create(:distribution, organization: organization, issued_at: within_time) toddler_distribution = create(:distribution, organization: organization, issued_at: within_time)