- Ruby x
- Rails 6x
- Docker-Compose
For ubuntu try using ... https://gorails.com/setup/ubuntu/19.10
- Download rails, gem install rails — brew install gem
- brew install postgresql
- Install heroku cli
- bundle install --path vendor/bundle
- rails db:create
- rails db:migrate
- heroku local web -> localhost:5000
- test: heroku local:run bundle exec rspec
NOTE: Please clone and create your branches in the main repo, PR's from forked repos will have tests fail due to missing CI environmental variables
- Download Ruby 2.6.6
- rvm install ruby-X.X.X
If you don't have rvm, gem install rvm:
\curl -sSL https://get.rvm.io | bash -s stable --ruby
- Download postgres
brew install postgresql
- cd to ruby/ and run
bundle install
. You might have togem install bundler
- Create a
.env
file (the secret sauce) by running this commandcp .env.example .env
- Follow the following guide to fill the .env file in https://docs.google.com/document/d/1UPNCwjWS_T7XT5AXsewphu6NvNdV7TQLSJub-RBRAG0/edit?ts=5ec88e82
Windows specific setup docs here
- Run the server (see below) and create and migrate your DB:
rails db:create && rails db:migrate && rails db:seed
If you see an error likeCouldn't create 'myapp_development' database. Please check your configuration. rails aborted! PG::ConnectionBad: could not connect to server: No such file or directory
, try runningbrew services restart postgresql
source
If you get a migration error like PG::UndefinedTable: ERROR:
or PG::NotNullViolation
, try running rails db:environment:set RAILS_ENV=development
--> rails db:reset
--> rails db:migrate
-
Run the server:
heroku local web
If you see an error that looks likeNo such file or directory @ rb_sysopen - tmp/pids/puma.pid
, run:mkdir tmp
mkdir tmp/pids
-
Run the server on port 5000:
heroku local web -p 5000
-
Run all tests:
heroku local:run bundle exec rspec
-
Run specific tests:
heroku local:run bundle exec "rspec -e '<insert string from test description>'"
-
Run console:
heroku local:run rails console
-
Run local migrations in prod
heroku run rake db:migrate
(do this after submitting a change with a local migration) -
Install annotate
gem install annotate
-
Annotate models
annotate --models
-
Annotate everything
annotate
rails generate model <ModelName>
rails generate controller <ControllerName>
rails generate migration <MigrationName>
For you to work with webhooks, you need a domain for square to send events to. To do this without a hosted service, you can forward your localhost port using something like ngrok or localhost.run. This also enables you to share your local environment in pull requests for additional validations.
- Setup localhost.run or ngrok or any derivatives to forward your localhost port to the web.
- Make the port forwarder point to your local port. localhost.run cmd:
ssh -R 80:localhost:5000 ssh.localhost.run
- Make sure to append
/webhooks
to the forwarding URL so you're hitting the correct route - Go to: https://developer.squareup.com/apps
- Go to the webhooks pane and create a sandbox api to point to domain created above.
- Enable the following events:
- refund.created
- refund.updated
- payment.updated
- Edit
.env
file.- Edit
SQUARE_WEBHOOK_SIGNATURE_KEY
to the signature key from when you created the webhooks. - Edit
RAILS_WEBHOOK_URL
to your domain + webhooks url. For instancehttps://example.com/webhooks
. This is used for validating requests.
- Edit
First evaluate which seller the gift cards are going to go towards, how many are needed, and who is going to distribute the gift cards.
Run the command below
NOTE: A dollar is 100. If you wish to seed $5, put 500 as the amount.
heroku run -a {HEROKU APP} 'rake gift_cards:create -s {SELLER_ID} -m {DISTRIBUTOR_EMAIL} -q {QUANTITY} -a {AMOUNT}'
If you're getting errors related to your local environment variables not being set, you probably need to create a .env file https://docs.google.com/document/d/1UPNCwjWS_T7XT5AXsewphu6NvNdV7TQLSJub-RBRAG0/edit?ts=5ec88e82
Anytime a new migration is created, you'll have to run rails db:migrate
for your local dev environment, and rails db:migrate RAILS_ENV=test
for your local test environment
Running a containerized version of the app requires Docker and Docker Compose. In addition, some updates will be required to the config/database.yml
file for the app to work within Docker. You may also need to enable Square webhooks, so reference the Enabling Webhooks section.
docker volume create --name=postgres-data-volume
cd <local repo directory name> && docker-compose up
accessing rail CLI after docker-compose
is running.
# check what containers are being run by Docker Compose
cd <local repo directory name> && docker-compose ps
docker exec -it <name of the container with "web_1" in it> bash
# now inside docker container example of commands that can be run
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec rails g model Todo title:string created_by:string
Tests can be run locally with:
RAILS_ENV=test bundle exec rspec
Or you can run a specific test with:
RAILS_ENV=test bundle exec rspec path/to/specific/test-file
install heroku-cli
After heroku login
and you are added the project
if you setup your heroku app, you should have a remote added; if not explicitly run
git remote add heroku https://git.heroku.com/sendchinatownlove.git`
git subtree push --prefix api heroku master
or if pipelines already setup, push naturally to branches
Follow instructions to enable DNS. https://devcenter.heroku.com/articles/custom-domains
heroku comes with auto-ssl for all hobby and up dynos
run
heroku certs:auto:enable