From af45e037db55512d7030d248f401b9604ec09747 Mon Sep 17 00:00:00 2001 From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com> Date: Sun, 25 Aug 2024 19:31:20 -0700 Subject: [PATCH 01/15] Filters out deactive partners on new distribution This commit adds in a conditional check to the _form partial that checks where the partial is coming from. If it is being rendered from the 'new' view, it will then generate a partner list that filters out the deactivated partners. If it is being rendered from anywhere else, it will generate the complete partner list unfiltered. [Ticket: 4515] --- app/views/distributions/_form.html.erb | 10 +++++++++- app/views/distributions/new.html.erb | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/views/distributions/_form.html.erb b/app/views/distributions/_form.html.erb index b72329f950..423e724eeb 100644 --- a/app/views/distributions/_form.html.erb +++ b/app/views/distributions/_form.html.erb @@ -1,3 +1,11 @@ +<% + partner_list = if defined?(source) && source == 'new' + current_organization.partners.where.not(status: 'deactivated').alphabetized + else + current_organization.partners.alphabetized + end +%> + <%= simple_form_for distribution, data: { controller: "form-input", confirmation_target: "form" }, html: { class: "storage-location-required" }, @@ -9,7 +17,7 @@ <% end %> <%= f.association :partner, - collection: current_organization.partners.alphabetized, + collection: partner_list, label: "Partner", error: "Which partner is this distribution going to?" %> diff --git a/app/views/distributions/new.html.erb b/app/views/distributions/new.html.erb index f741e4823b..676c36101c 100644 --- a/app/views/distributions/new.html.erb +++ b/app/views/distributions/new.html.erb @@ -36,7 +36,7 @@
- <%= render 'form', distribution: @distribution, date_place_holder: Time.zone.now.end_of_day %> + <%= render 'form', distribution: @distribution, date_place_holder: Time.zone.now.end_of_day, source: 'new' %>
From b9d305025aedfe1887edfe6b2950be0e95c6ca41 Mon Sep 17 00:00:00 2001 From: isaiah3031 Date: Mon, 26 Aug 2024 06:17:50 -0400 Subject: [PATCH 02/15] Adds required to Payment Total. --- app/views/purchases/_purchase_form.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/purchases/_purchase_form.html.erb b/app/views/purchases/_purchase_form.html.erb index f2e0d35bb4..f0765e4dd2 100644 --- a/app/views/purchases/_purchase_form.html.erb +++ b/app/views/purchases/_purchase_form.html.erb @@ -27,7 +27,8 @@
<%= f.input :amount_spent, label: "Purchase Total", - wrapper: :input_group %> + wrapper: :input_group, + required: true %>
From f04cdcd269f855a437c57945456c6b0e14d3d13b Mon Sep 17 00:00:00 2001 From: isaiah3031 Date: Thu, 29 Aug 2024 13:39:02 -0400 Subject: [PATCH 03/15] Adds wsl install note to CONTRIBUTING.md --- CONTRIBUTING.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1c7e260a3..49235123b3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,6 +17,15 @@ You won't be yelled at for giving your best effort. The worst that can happen is # Getting Started ## Local Environment 🛠️ + +Do you develop on Windows? +#### Windows Subsystem for Linux (WSL2) - Windows Only +Follow [documentation](https://docs.microsoft.com/en-us/windows/wsl/install-win10) from Microsoft for enabling and installing WSL2 on your machine. + +Make sure to install **Ubuntu** as your Linux distribution. (This should be default.) + +**Note:** If you run into any issues with a command not running, restart your machine. + 1. Install Ruby - Install the version specified in [`.ruby-version`](.ruby-version). - Visit the [Install Ruby on Rails](https://gorails.com/setup/osx/12-monterey) guide by GoRails for Ubuntu, Windows, and macOSX setup. ⚠️ Follow only the Installing Ruby step, as our project setup differs ⚠️ It is highly recommended you use a ruby version manager such as [rbenv](https://github.com/rbenv/rbenv), [asdf](https://asdf-vm.com/), or [rvm](https://rvm.io/). From 6f199ec2b51b0358ca4e75d161de079037a51f45 Mon Sep 17 00:00:00 2001 From: isaiah3031 Date: Thu, 29 Aug 2024 14:06:42 -0400 Subject: [PATCH 04/15] Remove request. Rewording. --- CONTRIBUTING.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49235123b3..f8a23fd295 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,21 +18,20 @@ You won't be yelled at for giving your best effort. The worst that can happen is # Getting Started ## Local Environment 🛠️ -Do you develop on Windows? -#### Windows Subsystem for Linux (WSL2) - Windows Only -Follow [documentation](https://docs.microsoft.com/en-us/windows/wsl/install-win10) from Microsoft for enabling and installing WSL2 on your machine. +#### Install WSL2 first if Using Windows +Follow [documentation](https://docs.microsoft.com/en-us/windows/wsl/install-win10) from Microsoft for enabling and installing Windows Subsystem For Linux 2 on your machine. Make sure to install **Ubuntu** as your Linux distribution. (This should be default.) **Note:** If you run into any issues with a command not running, restart your machine. + 1. Install Ruby - Install the version specified in [`.ruby-version`](.ruby-version). - Visit the [Install Ruby on Rails](https://gorails.com/setup/osx/12-monterey) guide by GoRails for Ubuntu, Windows, and macOSX setup. ⚠️ Follow only the Installing Ruby step, as our project setup differs ⚠️ It is highly recommended you use a ruby version manager such as [rbenv](https://github.com/rbenv/rbenv), [asdf](https://asdf-vm.com/), or [rvm](https://rvm.io/). - Verify that your Ruby installation works by running `ruby -v`. 2. Install Postgres - Follow one of these guides: [MacOSX](https://www.digitalocean.com/community/tutorials/how-to-use-postgresql-with-your-ruby-on-rails-application-on-macos), [Ubuntu](https://www.digitalocean.com/community/tutorials/how-to-use-postgresql-with-your-ruby-on-rails-application-on-ubuntu-18-04). - - Do you develop on Windows? We'd love to hear (and for you to submit a PR explaining) how you do it. 🙏🏻 - Create a `database.yml` file on `config/` directory with your database configurations. You can also copy the existing files called [`database.yml.example`](config/database.yml.example) and [`.env.example`](.env.example) and change the credentials. 3. Clone the project and switch to its directory 4. Run `bin/setup` From 9bb01addc15a8d1b73e74227b0f3e3572262777e Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Thu, 29 Aug 2024 21:59:54 -0400 Subject: [PATCH 05/15] Add data migration to fix errant distribution+event --- .../20240830015517_fix_invalid_distribution_event.rb | 12 ++++++++++++ db/schema.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240830015517_fix_invalid_distribution_event.rb diff --git a/db/migrate/20240830015517_fix_invalid_distribution_event.rb b/db/migrate/20240830015517_fix_invalid_distribution_event.rb new file mode 100644 index 0000000000..cace57fead --- /dev/null +++ b/db/migrate/20240830015517_fix_invalid_distribution_event.rb @@ -0,0 +1,12 @@ +class FixInvalidDistributionEvent < ActiveRecord::Migration[7.1] + def change + return unless Rails.env.production? + + # We are not sure why yet, but this org was able to create a distribution + # that put them at a negative inventory. Later playback of the events with + # validation turned on then raised it as an error. For now we are deleting + # the distribution and event directly. + Event.where(id: 34416, eventable_type: 'Distribution', eventable_id: 75002).first.destroy + Distribution.find(75002).destroy + end +end diff --git a/db/schema.rb b/db/schema.rb index bcc773347a..91483f028f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_18_010905) do +ActiveRecord::Schema[7.1].define(version: 2024_08_30_015517) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 4a3253f8b3e753dcc9d4dff513f2038910098860 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 04:20:54 +0000 Subject: [PATCH 06/15] build(deps): bump omniauth-google-oauth2 from 1.1.2 to 1.1.3 Bumps [omniauth-google-oauth2](https://github.com/zquestz/omniauth-google-oauth2) from 1.1.2 to 1.1.3. - [Release notes](https://github.com/zquestz/omniauth-google-oauth2/releases) - [Changelog](https://github.com/zquestz/omniauth-google-oauth2/blob/master/CHANGELOG.md) - [Commits](https://github.com/zquestz/omniauth-google-oauth2/compare/v1.1.2...v1.1.3) --- updated-dependencies: - dependency-name: omniauth-google-oauth2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 54039a468f..fe9ae9d6c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -243,7 +243,7 @@ GEM faraday-httpclient (1.0.1) faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (1.0.1) + faraday-net_http (1.0.2) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) @@ -383,8 +383,9 @@ GEM monetize (~> 1.9) money (~> 6.13) railties (>= 3.0) - multi_xml (0.6.0) - multipart-post (2.4.0) + multi_xml (0.7.1) + bigdecimal (~> 3.1) + multipart-post (2.4.1) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) mutex_m (0.2.0) @@ -422,7 +423,7 @@ GEM hashie (>= 3.4.6) rack (>= 2.2.3) rack-protection - omniauth-google-oauth2 (1.1.2) + omniauth-google-oauth2 (1.1.3) jwt (>= 2.0) oauth2 (~> 2.0) omniauth (~> 2.0) From 5bed0a6598871b1ec33d7f0494b93093269ef828 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 04:22:02 +0000 Subject: [PATCH 07/15] build(deps-dev): bump rspec-rails from 6.1.3 to 6.1.4 Bumps [rspec-rails](https://github.com/rspec/rspec-rails) from 6.1.3 to 6.1.4. - [Changelog](https://github.com/rspec/rspec-rails/blob/main/Changelog.md) - [Commits](https://github.com/rspec/rspec-rails/compare/v6.1.3...v6.1.4) --- updated-dependencies: - dependency-name: rspec-rails dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 8bc1e4f459..3e3e5f4ef9 100644 --- a/Gemfile +++ b/Gemfile @@ -150,7 +150,7 @@ group :development, :test do # Debugger which supports rdbg and Shopify Ruby LSP VSCode extension gem "debug", ">= 1.0.0" # RSpec behavioral testing framework for Rails. - gem "rspec-rails", "~> 6.1.3" + gem "rspec-rails", "~> 6.1.4" # Static analysis / linter. gem "rubocop" # Rails add-on for static analysis. diff --git a/Gemfile.lock b/Gemfile.lock index fe9ae9d6c3..ee194df0c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,7 +141,7 @@ GEM activesupport tzinfo coderay (1.1.3) - concurrent-ruby (1.3.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) coverband (6.1.2) redis (>= 3.0) @@ -315,7 +315,7 @@ GEM activesupport (>= 6.0.0) railties (>= 6.0.0) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) jbuilder (2.12.0) @@ -373,7 +373,7 @@ GEM method_source (1.1.0) mini_magick (4.13.2) mini_mime (1.1.5) - minitest (5.24.1) + minitest (5.25.1) monetize (1.12.0) money (~> 6.12) money (6.16.0) @@ -563,13 +563,13 @@ GEM rspec-mocks (~> 3.13.0) rspec-core (3.13.0) rspec-support (~> 3.13.0) - rspec-expectations (3.13.1) + rspec-expectations (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-rails (6.1.3) + rspec-rails (6.1.4) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) @@ -669,7 +669,7 @@ GEM strscan (3.1.0) terser (1.2.3) execjs (>= 0.3.0, < 3) - thor (1.3.1) + thor (1.3.2) tilt (2.2.0) timeout (0.4.1) ttfunk (1.7.0) @@ -700,7 +700,7 @@ GEM xpath (3.2.0) nokogiri (~> 1.8) yard (0.9.34) - zeitwerk (2.6.16) + zeitwerk (2.6.17) PLATFORMS arm64-darwin-20 @@ -783,7 +783,7 @@ DEPENDENCIES recaptcha redis (~> 5.2) rolify (~> 6.0) - rspec-rails (~> 6.1.3) + rspec-rails (~> 6.1.4) rubocop rubocop-performance rubocop-rails (~> 2.25.1) From ad0654fb50ea0e88aa1e3f6146268dd5a8a11dc6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 04:24:16 +0000 Subject: [PATCH 08/15] build(deps-dev): bump standard from 1.39.2 to 1.40.0 Bumps [standard](https://github.com/standardrb/standard) from 1.39.2 to 1.40.0. - [Release notes](https://github.com/standardrb/standard/releases) - [Changelog](https://github.com/standardrb/standard/blob/main/CHANGELOG.md) - [Commits](https://github.com/standardrb/standard/compare/v1.39.2...v1.40.0) --- updated-dependencies: - dependency-name: standard dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 3e3e5f4ef9..d3d0473d11 100644 --- a/Gemfile +++ b/Gemfile @@ -157,7 +157,7 @@ group :development, :test do gem 'rubocop-performance' gem "rubocop-rails", "~> 2.25.1" # Default rules for Rubocop. - gem "standard", "~> 1.39" + gem "standard", "~> 1.40" # Erb linter. gem "erb_lint" end diff --git a/Gemfile.lock b/Gemfile.lock index ee194df0c6..00eb91036d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -441,8 +441,8 @@ GEM paper_trail (15.1.0) activerecord (>= 6.1) request_store (~> 1.4) - parallel (1.25.1) - parser (3.3.4.0) + parallel (1.26.3) + parser (3.3.4.2) ast (~> 2.4.1) racc pdf-core (0.9.0) @@ -553,7 +553,7 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.3.4) + rexml (3.3.6) strscan rolify (6.0.1) rouge (4.1.2) @@ -578,18 +578,18 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) - rubocop (1.64.1) + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.31.3) + rubocop-ast (1.32.1) parser (>= 3.3.1.0) rubocop-performance (1.21.1) rubocop (>= 1.48.1, < 2.0) @@ -649,10 +649,10 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - standard (1.39.2) + standard (1.40.0) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) - rubocop (~> 1.64.0) + rubocop (~> 1.65.0) standard-custom (~> 1.0.0) standard-performance (~> 1.4) standard-custom (1.0.2) @@ -792,7 +792,7 @@ DEPENDENCIES simple_form simplecov sprockets (~> 4.2.1) - standard (~> 1.39) + standard (~> 1.40) stimulus-rails strong_migrations (= 1.8.0) terser From cf51c1b46d586cab8a4ef6ced90266535ca1f180 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 04:24:44 +0000 Subject: [PATCH 09/15] build(deps): bump newrelic_rpm from 9.12.0 to 9.13.0 Bumps [newrelic_rpm](https://github.com/newrelic/newrelic-ruby-agent) from 9.12.0 to 9.13.0. - [Release notes](https://github.com/newrelic/newrelic-ruby-agent/releases) - [Changelog](https://github.com/newrelic/newrelic-ruby-agent/blob/dev/CHANGELOG.md) - [Commits](https://github.com/newrelic/newrelic-ruby-agent/compare/9.12.0...9.13.0) --- updated-dependencies: - dependency-name: newrelic_rpm dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 00eb91036d..a919a6a26f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -401,7 +401,7 @@ GEM timeout net-smtp (0.5.0) net-protocol - newrelic_rpm (9.12.0) + newrelic_rpm (9.13.0) nio4r (2.7.3) nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) From de5135614e5f94c5258368d7fc410771057c3b5f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 04:25:11 +0000 Subject: [PATCH 10/15] build(deps): bump stimulus-rails from 1.3.3 to 1.3.4 Bumps [stimulus-rails](https://github.com/hotwired/stimulus-rails) from 1.3.3 to 1.3.4. - [Release notes](https://github.com/hotwired/stimulus-rails/releases) - [Commits](https://github.com/hotwired/stimulus-rails/compare/v1.3.3...v1.3.4) --- updated-dependencies: - dependency-name: stimulus-rails dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index a919a6a26f..39090ec92c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -661,7 +661,7 @@ GEM standard-performance (1.4.0) lint_roller (~> 1.1) rubocop-performance (~> 1.21.0) - stimulus-rails (1.3.3) + stimulus-rails (1.3.4) railties (>= 6.0.0) stringio (3.1.1) strong_migrations (1.8.0) From 3d89b5d0fe3673983a8cefd605fb6888063b6a70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:50:15 -0400 Subject: [PATCH 11/15] build(deps-dev): bump brakeman from 6.1.2 to 6.2.1 (#4628) Bumps [brakeman](https://github.com/presidentbeef/brakeman) from 6.1.2 to 6.2.1. - [Release notes](https://github.com/presidentbeef/brakeman/releases) - [Changelog](https://github.com/presidentbeef/brakeman/blob/main/CHANGES.md) - [Commits](https://github.com/presidentbeef/brakeman/compare/v6.1.2...v6.2.1) --- updated-dependencies: - dependency-name: brakeman dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 39090ec92c..c8a029d17d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,7 +115,7 @@ GEM autoprefixer-rails (>= 9.1.0) popper_js (>= 2.11.6, < 3) sassc-rails (>= 2.0.0) - brakeman (6.1.2) + brakeman (6.2.1) racc bugsnag (6.27.1) concurrent-ruby (~> 1.0) From b923647c8918ac8a712c2baa8a1d0b8538880825 Mon Sep 17 00:00:00 2001 From: Faizah Aulia R Date: Tue, 3 Sep 2024 00:53:29 +0700 Subject: [PATCH 12/15] Fix distribution export, item columns in alphabetically order (#4617) --- app/services/exports/export_distributions_csv_service.rb | 2 +- spec/services/exports/export_distributions_csv_service_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/exports/export_distributions_csv_service.rb b/app/services/exports/export_distributions_csv_service.rb index dae6df149c..64557e3369 100644 --- a/app/services/exports/export_distributions_csv_service.rb +++ b/app/services/exports/export_distributions_csv_service.rb @@ -118,7 +118,7 @@ def base_headers def item_headers return @item_headers if @item_headers - @item_headers = @organization.items.order(:created_at).distinct.select([:created_at, :name]).map(&:name) + @item_headers = @organization.items.select("DISTINCT ON (LOWER(name)) items.name").order("LOWER(name) ASC").map(&:name) end def build_row_data(distribution) diff --git a/spec/services/exports/export_distributions_csv_service_spec.rb b/spec/services/exports/export_distributions_csv_service_spec.rb index 5d31de5c75..89c041d825 100644 --- a/spec/services/exports/export_distributions_csv_service_spec.rb +++ b/spec/services/exports/export_distributions_csv_service_spec.rb @@ -44,7 +44,7 @@ let(:item_id) { duplicate_item.id } let(:item_name) { duplicate_item.name } let(:filters) { {by_item_id: item_id} } - let(:all_org_items) { Item.where(organization:).uniq.sort_by(&:created_at) } + let(:all_org_items) { Item.where(organization:).uniq.sort_by { |item| item.name.downcase } } let(:total_item_quantities) do template = all_org_items.pluck(:name).index_with(0) From 33053af8a6880e15ed27db0cc1af6211e487b1eb Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Tue, 3 Sep 2024 11:19:52 -0400 Subject: [PATCH 13/15] Enable read-events feature in dev/staging by default (#4591) * Enable read-events feature in dev/staging by default We have manually enabled this in production * Remove more Event Sourcing separation * Minor documentation whitespace cleanup * Put back read_events check in specs This is needed just a bit longer until we completely remove the feature flag for Events --- .github/workflows/rspec-events.yml | 92 ---------------------- .github/workflows/rspec-system-events.yml | 93 ----------------------- CONTRIBUTING.md | 36 +++++---- db/seeds.rb | 2 + spec/rails_helper.rb | 4 +- 5 files changed, 20 insertions(+), 207 deletions(-) delete mode 100644 .github/workflows/rspec-events.yml delete mode 100644 .github/workflows/rspec-system-events.yml diff --git a/.github/workflows/rspec-events.yml b/.github/workflows/rspec-events.yml deleted file mode 100644 index 4d490859a7..0000000000 --- a/.github/workflows/rspec-events.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: rspec-events - -on: - push: - paths-ignore: - - "doc/**" - - "*.md" - - "bin/*" - pull_request: - paths-ignore: - - "doc/**" - - "*.md" - - "bin/*" - -jobs: - rspec-events: - runs-on: ubuntu-latest - - services: - db: - image: postgres:12.3 - env: - POSTGRES_PASSWORD: password - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix - strategy: - fail-fast: false - matrix: - # Set N number of parallel jobs you want to run tests on. - # Use higher number if you have slow tests to split them on more parallel jobs. - # Remember to update ci_node_index below to 0..N-1 - ci_node_total: [2] - # set N-1 indexes for parallel jobs - # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc - ci_node_index: [0, 1] - steps: - - uses: actions/checkout@v4 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - - name: Install PostgreSQL client - run: | - sudo apt-get -yqq install libpq-dev - - name: Build App - env: - POSTGRES_HOST: localhost - DATABASE_HOST: localhost - PG_USERNAME: postgres - PG_PASSWORD: password - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_PORT: 5432 - RAILS_ENV: test - run: | - bundle exec rake db:create - bundle exec rake db:schema:load - - name: Run rspec with events - env: - POSTGRES_HOST: localhost - DATABASE_HOST: localhost - PG_USERNAME: postgres - PG_PASSWORD: password - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_PORT: 5432 - PGHOST: localhost - PGUSER: postgres - RAILS_ENV: test - KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }} - KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} - KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }} - KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true - KNAPSACK_PRO_LOG_LEVEL: info - KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN: "{spec/system/**{,/*/**}/*_spec.rb,spec/requests/**{,/*/**}/*_spec.rb}" - EVENTS_READ: true - run: | - RUBYOPT='-W:no-deprecated -W:no-experimental' bin/knapsack_pro_rspec - - name: Upload artifacts - if: ${{ failure() }} - uses: actions/upload-artifact@v4 - with: - name: failed-browser-tests - path: | - tmp/screenshots - tmp/capybara diff --git a/.github/workflows/rspec-system-events.yml b/.github/workflows/rspec-system-events.yml deleted file mode 100644 index a8ac952e31..0000000000 --- a/.github/workflows/rspec-system-events.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: rspec-system-events - -on: - push: - paths-ignore: - - "doc/**" - - "*.md" - - "bin/*" - pull_request: - paths-ignore: - - "doc/**" - - "*.md" - - "bin/*" - -jobs: - rspec-system-events: - runs-on: ubuntu-latest - - services: - db: - image: postgres:12.3 - env: - POSTGRES_PASSWORD: password - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix - strategy: - fail-fast: false - matrix: - # Set N number of parallel jobs you want to run tests on. - # Use higher number if you have slow tests to split them on more parallel jobs. - # Remember to update ci_node_index below to 0..N-1 - ci_node_total: [6] - # set N-1 indexes for parallel jobs - # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc - ci_node_index: [0, 1, 2, 3, 4, 5] - steps: - - uses: actions/checkout@v4 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - - name: Install PostgreSQL client - run: | - sudo apt-get -yqq install libpq-dev - - name: Build App with asset compilation - env: - POSTGRES_HOST: localhost - DATABASE_HOST: localhost - PG_USERNAME: postgres - PG_PASSWORD: password - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_PORT: 5432 - RAILS_ENV: test - run: | - bundle exec rake db:create - bundle exec rake db:schema:load - bundle exec rails assets:precompile - - name: Run rspec with events - env: - POSTGRES_HOST: localhost - DATABASE_HOST: localhost - PG_USERNAME: postgres - PG_PASSWORD: password - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_PORT: 5432 - PGHOST: localhost - PGUSER: postgres - RAILS_ENV: test - KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }} - KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} - KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }} - KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true - KNAPSACK_PRO_LOG_LEVEL: info - KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/**{,/*/**}/*_spec.rb,spec/requests/**{,/*/**}/*_spec.rb}" - EVENTS_READ: true - run: | - RUBYOPT='-W:no-deprecated -W:no-experimental' bin/knapsack_pro_rspec - - name: Upload artifacts - if: ${{ failure() }} - uses: actions/upload-artifact@v4 - with: - name: failed-browser-tests - path: | - tmp/capybara - tmp/screenshots diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8a23fd295..fef2335cc1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,8 +9,8 @@ If you're new here, here are some things you should know: - This project relies entirely on volunteers, so please be patient with communication # Communication 💬 -If you have any questions about an issue, comment on the issue, open a new issue, or ask in [the RubyForGood slack](https://join.slack.com/t/rubyforgood/shared_invite/zt-2k5ezv241-Ia2Iac3amxDS8CuhOr69ZA). human-essentials has a `#human-essentials` channel in the Slack. Our channel in slack also contains a zoom link for office hours every day office hours are held. - +If you have any questions about an issue, comment on the issue, open a new issue, or ask in [the RubyForGood slack](https://join.slack.com/t/rubyforgood/shared_invite/zt-2k5ezv241-Ia2Iac3amxDS8CuhOr69ZA). human-essentials has a `#human-essentials` channel in the Slack. Our channel in slack also contains a zoom link for office hours every day office hours are held. + Many helpful members are available to answer your questions. Just ask, and someone will be there to help you! You won't be yelled at for giving your best effort. The worst that can happen is that you'll be politely asked to change something. We appreciate any sort of contributions, and don't want a wall of rules to get in the way of that. @@ -37,7 +37,7 @@ Make sure to install **Ubuntu** as your Linux distribution. (This should be defa 4. Run `bin/setup` 5. Run `bin/start` and visit http://localhost:3000/ to see the human essentials page. 6. Log in as a sample user with the default [credentials](#credentials). - + ## Credentials These credentials also work for [staging](https://staging.humanessentials.app/): @@ -97,7 +97,7 @@ Make sure to install **Ubuntu** as your Linux distribution. (This should be defa - Or follow instructions to [create a new Codespace.](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository) - To clone this repo and run the container locally, follow instructions to [install VSCode and Docker](https://code.visualstudio.com/docs/devcontainers/containers). Click the Dev Container link above. Don't forget to add a git remote pointing to your fork once the container is setup and you want to push changes. 2. Wait for the container to start. This will take a few (10-15) minutes since Ruby needs to be installed, the database needs to be created, and the `bin/setup` script needs to run -3. Run `bin/start`. On the Ports tab, visit the forwarded port 3000 URL marked as Application to see the human essentials page. +3. Run `bin/start`. On the Ports tab, visit the forwarded port 3000 URL marked as Application to see the human essentials page. 4. Login as a sample user with the default [credentials](#credentials). ## Troubleshooting 👷🏼‍♀️ @@ -126,21 +126,21 @@ Please let us know by opening up an issue! We have many new contributors come th 10. **Squash smaller commits.** Read guidelines [here](#squashing-commits). 11. **Push** up the branch 12. **Create a pull request** and indicate the addressed issue (e.g. `Resolves #1`) in the title, which will ensure the issue gets closed automatically when the pull request gets merged. Read PR guidelines [here](#pull-requests). -13. **Code review**: At this point, someone will work with you on doing a code review. The automated tests will run linting, rspec, and brakeman tests. If the automated tests give :+1: to the PR merging, we can then do any additional (staging) testing as needed. +13. **Code review**: At this point, someone will work with you on doing a code review. The automated tests will run linting, rspec, and brakeman tests. If the automated tests give :+1: to the PR merging, we can then do any additional (staging) testing as needed. -14. **Merge**: Finally if all looks good the core team will merge your code in; if your feature branch was in this main repository, the branch will be deleted after the PR is merged. +14. **Merge**: Finally if all looks good the core team will merge your code in; if your feature branch was in this main repository, the branch will be deleted after the PR is merged. 15. Deploys are currently done about once a week! Read the deployment process [here](#deployment-process). -## Issues +## Issues Please feel free to contribute! While we welcome all contributions to this app, pull-requests that address outstanding Issues *and* have appropriate test coverage for them will be strongly prioritized. In particular, addressing issues that are tagged with the next milestone should be prioritized higher. -All work is organized by issues. -[Find issues here.](https://github.com/rubyforgood/human-essentials/issues) +All work is organized by issues. +[Find issues here.](https://github.com/rubyforgood/human-essentials/issues) -If you would like to contribute, please ask for an issue to be assigned to you. -If you would like to contribute something that is not represented by an issue, please make an issue and assign yourself. -Only take multiple issues if they are related and you can solve all of them at the same time with the same pull request. +If you would like to contribute, please ask for an issue to be assigned to you. +If you would like to contribute something that is not represented by an issue, please make an issue and assign yourself. +Only take multiple issues if they are related and you can solve all of them at the same time with the same pull request. ## Becoming a Repo Contributor @@ -165,7 +165,7 @@ Consider the balance of "polluting the git log with commit messages" vs. "provid Only commit the schema.rb only if you have committed anything that would change the DB schema (i.e. a migration). -## Pull Requests +## Pull Requests ### Stay scoped Try to keep your PRs limited to one particular issue, and don't make changes that are out of scope for that issue. If you notice something that needs attention but is out of scope, please [create a new issue](https://github.com/rubyforgood/human-essentials/issues/new). @@ -184,7 +184,6 @@ If you are inexperienced in writing tests or get stuck on one, please reach out #### Guidelines - Prefer request tests over system tests (which run much slower) unless you need to test Javascript or other interactivity - When creating factories, in each RSpec test, hard code all values that you check with a RSpec matcher. Don't check FactoryBot default values. See [#4217](https://github.com/rubyforgood/human-essentials/issues/4217) for why. -- Write tests to pass with Event Sourcing turned both on and off, see the [Event Sourcing wiki page](https://github.com/rubyforgood/human-essentials/wiki/Event-Sourcing). - Keep individual tests tightly scoped, only test the endpoint that you want to test. E.g. create inventory directly using `TestInventory` rather than using an additional endpoint. - You probably don't need to write new tests when simple re-stylings are done (ie. the page may look slightly different but the Test suite is unaffected by those changes). @@ -199,7 +198,7 @@ If you are inexperienced in writing tests or get stuck on one, please reach out magic_test end ``` - and run the spec using this command: + and run the spec using this command: ``` MAGIC_TEST=1 NOT_HEADLESS=true bundle exec rspec ` ``` @@ -210,13 +209,12 @@ If you are inexperienced in writing tests or get stuck on one, please reach out Before submitting a pull request, run all tests and lints. Fix any broken tests and lints before submitting a pull request. #### Continuous Integration -- There are Github Actions workflows which will run all tests with and without Event Sourcing in parallel using Knapsack and lints whenever you push a commit to your fork. +- There are Github Actions workflows which will run all tests in parallel using Knapsack and lints whenever you push a commit to your fork. - Once your first PR has been merged, all commits pushed to an open PR will also run these workflows. #### Local testing -- Run all lints with `bin/lint`. -- Run all tests without Event Sourcing with `bundle exec rspec` -- Run all tests with Event Sourcing with `EVENTS_READ=true bundle exec rspec` +- Run all lints with `bin/lint`. +- Run all tests with `bundle exec rspec` - You can run a single test with `bundle exec rspec {path_to_test_name}_spec.rb` or on a specific line by appending `:LineNumber` - If you need to skip a failing test, place `pending("Reason you are skipping the test")` into the `it` block rather than skipping with `xit`. This will allow rspec to deliver the error message without causing the test suite to fail. diff --git a/db/seeds.rb b/db/seeds.rb index 614143cbd0..3d89c8606a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -707,6 +707,8 @@ def seed_quantity(item_name, organization, storage_location, quantity) # ---------------------------------------------------------------------------- Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "new_logo") +Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "read_events") +Flipper.enable(:read_events) # ---------------------------------------------------------------------------- # Account Requests diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ec498f97c3..a8130707cd 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -171,9 +171,7 @@ def self.capybara_tmp_path end config.before(:each) do - if ENV['EVENTS_READ'] == 'true' - allow(Event).to receive(:read_events?).and_return(true) - end + allow(Event).to receive(:read_events?).and_return(true) end config.before do From a4de391d4d0ba6770518f411350bf7fef100203d Mon Sep 17 00:00:00 2001 From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:29:35 -0700 Subject: [PATCH 14/15] Updates the re-render of create on a fail to also filter out the deactivated partners --- app/controllers/distributions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/distributions_controller.rb b/app/controllers/distributions_controller.rb index f7f0e0d62a..c85217d60a 100644 --- a/app/controllers/distributions_controller.rb +++ b/app/controllers/distributions_controller.rb @@ -130,7 +130,7 @@ def create format.turbo_stream do flash.now[:error] = flash_error render turbo_stream: [ - turbo_stream.replace(@distribution, partial: "form", locals: {distribution: @distribution, date_place_holder: @distribution.issued_at}), + turbo_stream.replace(@distribution, partial: "form", locals: {distribution: @distribution, date_place_holder: @distribution.issued_at, source: 'new'}), turbo_stream.replace("flash", partial: "shared/flash") ], status: :bad_request end From 5729cec6161edb7b6271354211562f530a5b2156 Mon Sep 17 00:00:00 2001 From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:04:50 -0700 Subject: [PATCH 15/15] Adds in unit tests for distribution dropdown --- spec/system/distribution_system_spec.rb | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/spec/system/distribution_system_spec.rb b/spec/system/distribution_system_spec.rb index 05ebb31492..e10b404a93 100644 --- a/spec/system/distribution_system_spec.rb +++ b/spec/system/distribution_system_spec.rb @@ -293,6 +293,58 @@ visit new_distribution_path expect(page).to have_no_content "Inactive R Us" end + + context "Deactivated partners should not be displayed in partner dropdown" do + before do + valid_partner = create(:partner, name: 'Active Partner', organization: organization, status: "approved") + deactivated_partner = create(:partner, name: 'Deactivated Partner', organization: organization, status: "deactivated") + end + + it "should not display deactivated partners on new distribution" do + visit new_distribution_path + expect(page).to have_no_content "Deactivated Partner" + expect(page).to have_content "Active Partner" + end + + it "should not display deactivated partners after error and re-render of form" do + visit new_distribution_path + + select "Test Partner", from: "Partner" + select "Test Storage Location", from: "From storage location" + choose "Delivery" + + fill_in "Comment", with: "Take my wipes... please" + + item = View::Inventory.new(organization.id).items_for_location(storage_location.id).first + quantity = item.quantity + select item.name, from: "distribution_line_items_attributes_0_item_id" + fill_in "distribution_line_items_attributes_0_quantity", with: quantity * 2 + + expect do + click_button "Save", match: :first + + expect(page).to have_selector('#distributionConfirmationModal') + within "#distributionConfirmationModal" do + expect(page).to have_content("You are about to create a distribution for") + expect(find(:element, "data-testid": "distribution-confirmation-partner")).to have_text("Test Partner") + expect(find(:element, "data-testid": "distribution-confirmation-storage")).to have_text("Test Storage Location") + expect(page).to have_content(item.name) + expect(page).to have_content(quantity * 2) + click_button "Yes, it's correct" + end + + page.find('.alert') + end.not_to change { Distribution.count } + + expect(page).to have_content("New Distribution") + message = Event.read_events?(organization) ? 'Could not reduce quantity' : 'items exceed the available inventory' + expect(page.find(".alert")).to have_content message + + visit new_distribution_path + expect(page).to have_no_content "Deactivated Partner" + expect(page).to have_content "Active Partner" + end + end end it "errors if user does not fill storage_location" do @@ -410,6 +462,14 @@ expect(page).to have_content "reclaimed" end end + + it "should display deactivated partners in partner dropdown" do + valid_partner = create(:partner, name: 'Active Partner', organization: organization, status: "approved") + deactivated_partner = create(:partner, name: 'Deactivated Partner', organization: organization, status: "deactivated") + click_on "Edit", match: :first + expect(page).to have_content "Deactivated Partner" + expect(page).to have_content "Active Partner" + end end context "When attempting to edit a distribution" do