From d83c6dcd1083331f298e7f1c8df7e92a7a044dd4 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Tue, 3 Sep 2024 11:19:52 -0400 Subject: [PATCH] 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