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 a1c7e260a3..fef2335cc1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,27 +9,35 @@ 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. # Getting Started ## Local Environment 🛠️ + +#### 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` 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/): @@ -89,7 +97,7 @@ You won't be yelled at for giving your best effort. The worst that can happen is - 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 👷🏼‍♀️ @@ -118,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 @@ -157,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). @@ -176,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). @@ -191,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 ` ``` @@ -202,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/Gemfile b/Gemfile index 8bc1e4f459..d3d0473d11 100644 --- a/Gemfile +++ b/Gemfile @@ -150,14 +150,14 @@ 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. 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 54039a468f..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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -400,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) @@ -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) @@ -440,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) @@ -552,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) @@ -562,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) @@ -577,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) @@ -648,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) @@ -660,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) @@ -668,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) @@ -699,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 @@ -782,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) @@ -791,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 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 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/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' %>
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 %>
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" 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 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) 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