Skip to content

Commit

Permalink
Merge branch 'main' into 4172-fix-donation-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Aug 4, 2024
2 parents ba5af77 + d303832 commit 559b67d
Show file tree
Hide file tree
Showing 302 changed files with 2,856 additions and 803 deletions.
7 changes: 4 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# it will be more efficient to change the image.
# See https://github.com/devcontainers/images/blob/main/src/ruby/history/
FROM mcr.microsoft.com/devcontainers/ruby:dev-3.2-buster
RUN apt -y update && apt install -y vim curl gpg postgresql postgresql-contrib
RUN export DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get -y install vim curl gpg postgresql postgresql-contrib
RUN cd /tmp
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt install -y ./google-chrome-stable_current_amd64.deb
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get -y install ./google-chrome-stable_current_amd64.deb
21 changes: 19 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/postgres
{
"dockerComposeFile": "docker-compose.yml",
"forwardPorts": [3000, 5432],
"features": {
"ghcr.io/devcontainers/features/desktop-lite:1": {}
},
"forwardPorts": [3000, 5432, 6080],
"portsAttributes": {
"3000": {
"label": "Application",
"onAutoForward": "silent"
},
"5432": {
"label": "Database",
"onAutoForward": "silent"
},
"6080": {
"label": "Desktop",
"onAutoForward": "silent"
}
},
"workspaceFolder": "/workspaces/human-essentials",
"service": "app",
"customizations": {
Expand All @@ -21,5 +38,5 @@
"DOCKER": "true"
},

"postCreateCommand": ".devcontainer/post-create.sh"
"postCreateCommand": "bash -i .devcontainer/post-create.sh"
}
3 changes: 3 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ services:
volumes:
- ../..:/workspaces:cached

# Increase shared memory for Chrome to run in Fluxbox
shm_size: "2gb"

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

Expand Down
32 changes: 32 additions & 0 deletions .devcontainer/launch.json.codespaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "ruby_lsp",
"request": "launch",
"name": "Debug rspec at cursor with browser",
"program": "bundle exec rspec ${file}:${lineNumber}",
"env": {
"NOT_HEADLESS": "true"
}
},
{
"type": "ruby_lsp",
"request": "launch",
"name": "Debug with Events rspec at cursor with browser",
"program": "bundle exec rspec ${file}:${lineNumber}",
"env": {
"NOT_HEADLESS": "true",
"EVENTS_READ": "true"
}
},
{
"type": "ruby_lsp",
"request": "attach",
"name": "Attach to a live server"
}
]
}
5 changes: 5 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ RUBY_VERSION="$(cat .ruby-version | tr -d '\n')"

# copy the file only if it doesn't already exist
cp -n .devcontainer/.env.codespaces .env
mkdir -p .vscode && cp -n .devcontainer/launch.json.codespaces .vscode/launch.json

# If the project's required ruby version changes from 3.2.2, this command
# will download and compile the correct version, but it will take a long time.
Expand All @@ -11,4 +12,8 @@ if [ "$RUBY_VERSION" != "3.2.2" ]; then
echo "Ruby $RUBY_VERSION installed"
fi

nvm install node
rbenv init bash
rbenv init zsh

bin/setup
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ updates:
- dependency-name: geocoder
versions:
- 1.6.7
- dependency-name: strong_migrations
versions:
- 1.8.0
- dependency-name: devise_invitable
versions:
- 2.0.4
Expand Down
84 changes: 60 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
We ♥ contributors! By participating in this project, you agree to abide by the Ruby for Good [code of conduct](https://github.com/rubyforgood/human-essentials/blob/main/code-of-conduct.md).

If you're new here, here are some things you should know:
- A great introductory overview of the application is available at the [wiki](https://github.com/rubyforgood/human-essentials/wiki/Application-Overview).
- Issues tagged "Help Wanted" are self-contained and great for new contributors
- Pull Requests are reviewed within a week or so
- Ensure your build passes linting and tests and addresses the issue requirements
Expand Down Expand Up @@ -77,13 +78,18 @@ You won't be yelled at for giving your best effort. The worst that can happen is
```
</details>

## Codespaces - EXPERIMENTAL 🛠️
## Codespaces and Dev Container - EXPERIMENTAL 🛠️

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/rubyforgood/human-essentials/tree/main?quickstart=1)

1. Follow the link above or follow instructions to [create a new Codespace.](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository); You can use the web editor, or even better open the Codespace in VSCode
[![Clone and open in VSCode Dev Container](https://img.shields.io/static/v1?label=Dev%20Containers&message=Clone%20and%20Open%20in%20VSCode&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/rubyforgood/human-essentials)

1. Create the container:
- To run the container on a Github VM, follow the Codespace link above. You can connect to the Codespace using VSCode or the VSCode web editor.
- 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` and visit the URL that pops in VSCode up 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 👷🏼‍♀️
Expand All @@ -92,7 +98,13 @@ Please let us know by opening up an issue! We have many new contributors come th

- *"My RBENV installation didn't work!"* - The rbenv repository provides a [rbenv-doctor script](https://github.com/rbenv/rbenv-installer#rbenv-doctor) to verify the installation and check if a ruby version is installed

# 🤝 Contributing workflow
# Wiki Contribution Workflow
1. Follow this [SO post](https://stackoverflow.com/a/56480628/13342792) to force push the main repo's Wiki to your fork's Wiki.
2. Make edits to your fork's Wiki.
3. Create a documentation issue about your changes. Make sure to note which pages you changed and link to your fork's Wiki.
4. Someone will review and approve your changes and merge them into the main Wiki following this [SO post](https://stackoverflow.com/a/56810747/13342792)

# 🤝 Code Contribution Workflow

1. **Identify an unassigned issue**. Read more [here](#issues) about how to pick a good issue.
2. **Assign it** to avoid duplicated efforts (or request assignment by adding a comment).
Expand Down Expand Up @@ -132,6 +144,13 @@ If starting server directly, via `rail s` or `rail console`, or built-in debugge
If starting via Procfile with `bin/start`, then drop a ``binding.remote_pry`` into the line where you want execution to pause at. Then run ``pry-remote`` in the terminal to connect to it.
https://github.com/Mon-Ouie/pry-remote

If you want to connect via Shopify Ruby LSP VSCode extension or rdbg, start the server with `bundle exec rdbg -O -n -c -- bin/rails server -p 3000`

### Codespaces
When running tests in browser, visit the forwarded port 6080 URL to see the browser in Codespaces. You can also visit this port to access the GUI desktop in Codespaces.

In VSCode Run and Debug view, there are some helpful defaults for running RSpec tests in browser at your cursor as well as attaching to a live server. Make sure the Ruby LSP server is started before debugging.

## Squashing commits

Consider the balance of "polluting the git log with commit messages" vs. "providing useful detail about the history of changes in the git log". If you have several smaller commits that serve a one purpose, you are encouraged to squash them into a single commit. There's no hard and fast rule here about this (for now), just use your best judgement. Please don't squash other people's commits. Everyone who contributes here deserves credit for their work! :)
Expand All @@ -150,29 +169,46 @@ If you are so inclined, you can open a draft PR as you continue to work on it. S
## Tests 🧪
### Writing Browser/System/Feature Tests/Specs

Add a test for your change. If you are adding functionality or fixing a bug, you should add a test!

If you are inexperienced in writing tests or get stuck on one, please reach out for help :). 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).

If you need to see a browser/system spec run in the browser, you can use the following env variable:
Add a test for your change. If you are adding functionality or fixing a bug, you should add a test!

If you are inexperienced in writing tests or get stuck on one, please reach out for help :)

#### 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).

#### Useful Tips
- If you need to see a browser/system spec run in the browser, you can use the following env variable
```
NOT_HEADLESS=true bundle exec rspec
```
- We've added [magic_test](https://github.com/bullet-train-co/magic_test) which makes creating browser specs much easier. It allows you to record actions on the browser running the specs and easily paste them into the spec. You can do this by adding `magic_test` within your system spec:
```rb
it "does some browser stuff" do
magic_test
end
```
and run the spec using this command:
```
MAGIC_TEST=1 NOT_HEADLESS=true bundle exec rspec <path_to_spec>`
```
**See videos of it in action [here](https://twitter.com/andrewculver/status/1366062684802846721)**
- Helpful classes for viewing and modifying inventory include `View::Inventory`, `TestInventory` and various `CreateService` services, see the [Event Sourcing wiki page](https://github.com/rubyforgood/human-essentials/wiki/Event-Sourcing).

```
NOT_HEADLESS=true bundle exec rspec
```

We've added [magic_test](https://github.com/bullet-train-co/magic_test) which makes creating browser specs much easier. It allows you to record actions on the browser running the specs and easily paste them into the spec. You can do this by adding `magic_test` within your system spec:
```rb
it "does some browser stuff" do
magic_test
end
```
and run the spec using this command: `MAGIC_TEST=1 NOT_HEADLESS=true bundle exec rspec <path_to_spec>`
### Test before submitting pull requests
Before submitting a pull request, run all tests and lints. Fix any broken tests and lints before submitting a pull request.

**See videos of it in action [here](https://twitter.com/andrewculver/status/1366062684802846721)**
#### 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.
- Once your first PR has been merged, all commits pushed to an open PR will also run these workflows.

### Test before submitting pull requests
- Before submitting a pull request, run all tests and rake tasks with `bundle exec rake` and run lints with `bin/lint`. Fix any broken tests and lints before submitting a pull request.
- You can run all the tests without rake tasks with `bundle exec rspec`
#### 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`
- 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.

Expand Down
15 changes: 10 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
# User management and login workflow.
gem "devise", '>= 4.7.1'
# Postgres database adapter.
gem "pg", "~> 1.5.6"
gem "pg", "~> 1.5.7"
# Web server.
gem "puma"
# Rails web framework.
Expand All @@ -32,6 +32,8 @@ gem "paper_trail"
# Associates users with roles.
gem "rolify", "~> 6.0"
# Enforces "safe" migrations.
# Pinned to 1.8.0 because 2.0.0 no longer support postgres v10
# And as of now we are using postgres v10 in production
gem "strong_migrations", "1.8.0"
# used in events
gem 'dry-struct'
Expand Down Expand Up @@ -103,7 +105,6 @@ gem "clockwork"
# These are gems that aren't used directly, only as dependencies for other gems.
# Technically they don't need to be in this Gemfile at all, but we are pinning them to
# specific versions for compatibility reasons.
gem "mini_racer", "~> 0.12.0"
gem "nokogiri", ">= 1.10.4"
gem "image_processing"
gem "sprockets", "~> 4.2.1"
Expand All @@ -124,7 +125,7 @@ group :development, :test, :staging do
# Generate models based on factory definitions.
gem 'factory_bot_rails'
# Ensure the database is in a clean state on every test.
gem "database_cleaner-active_record", '~> 2.1'
gem "database_cleaner-active_record", '~> 2.2'
# Generate fake data for use in tests.
gem 'faker'
end
Expand All @@ -146,15 +147,17 @@ group :development, :test do
gem "pry-remote"
# Add-on for command line to create a simple debugger.
gem "pry-nav"
# 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"
# Static analysis / linter.
gem "rubocop"
# Rails add-on for static analysis.
gem 'rubocop-performance'
gem "rubocop-rails", "~> 2.25.0"
gem "rubocop-rails", "~> 2.25.1"
# Default rules for Rubocop.
gem "standard", "~> 1.37"
gem "standard", "~> 1.39"
# Erb linter.
gem "erb_lint"
end
Expand Down Expand Up @@ -199,6 +202,8 @@ group :test do
gem "webmock", "~> 3.23"
# Interface capybara to chrome headless
gem "cuprite"
# Read PDF files for tests
gem "pdf-reader"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
Loading

0 comments on commit 559b67d

Please sign in to comment.