Skip to content

Commit

Permalink
ci: add lint parallel job (#40)
Browse files Browse the repository at this point in the history
- Add installation notes on how to setup git hooks
- Add pre-commit library to support git hooks.
- Fix issues detected by standardrb.
- Remove old code from accounts controller
  • Loading branch information
EduardoSimon authored Oct 15, 2023
1 parent 54c2c37 commit 160332e
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 54 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ env:
POSTGRES_PASSWORD: postgres

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1.0"
bundler-cache: true

- name: Install deps
run: bundle install --retry 3

- name: Check lint issues
run: bundle exec rake standard
test:
runs-on: ubuntu-latest
services:
Expand Down
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: local
hooks:
- id: standardrb
name: Check Ruby style with StandardRB
description: Enforce Ruby style guide with StandardRB
entry: bin/standardrb-wrapper.sh
language: script
types: ["ruby"]
stages: [commit]
verbose: true
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ GEM
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.20.0)
monetize (1.12.0)
money (~> 6.12)
Expand All @@ -180,6 +181,9 @@ GEM
net-protocol
net-ssh (7.2.0)
nio4r (2.5.9)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
Expand Down Expand Up @@ -289,6 +293,8 @@ GEM
stimulus-rails (1.2.2)
railties (>= 6.0.0)
stringio (3.0.8)
tailwindcss-rails (2.0.30)
railties (>= 6.0.0)
tailwindcss-rails (2.0.30-aarch64-linux)
railties (>= 6.0.0)
tailwindcss-rails (2.0.30-x86_64-darwin)
Expand Down Expand Up @@ -323,6 +329,7 @@ GEM

PLATFORMS
aarch64-linux
ruby
x86_64-darwin-22
x86_64-linux

Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ application up and running.

Things you may want to cover:

* Ruby version
# Development

## Ruby version

Use a ruby dependency manager like rbenv or asdf. The supported ruby version is stated in the .ruby-version file

* System dependencies
## Setup

1. Install rails
1. Install dependencies

`gem install rails`
`bundle install`

2. Install postgres

Expand All @@ -25,12 +27,25 @@ Use a ruby dependency manager like rbenv or asdf. The supported ruby version is

4. Prepare dabatase

`rails db:create db:migrate db:seed`
`bin/rails db:create db:migrate db:seed`

5. Run the server

`rails s`
`bin/rails s`

## Installing git hooks

You might install the provided git hooks to prevent committing changes that do not conform to the established style guide.

For such please install `pre-commit` in your system. Refer to the [docs](https://pre-commit.com/#install) on how to install it.

Once set up, you will need to install the hooks in your local repository. Please run:

```
pre-commit install
```

After a successful execution, the commit hoo will trigger when committing files.

# Testing

Expand All @@ -43,19 +58,18 @@ Use a ruby dependency manager like rbenv or asdf. The supported ruby version is
# Domain

✅ A `budget` is a collection of `categories`.
✅ A `category` has a name and an `allocated_amount` per month.
✅ A `category` has a name and an `allocated_amount` per month.
✅ A `target amount` is the desired allocated amount for a given `category`
A `category` can be:

- `overspent` when the sum of movements is greater than the `allocated_amount`
- `underfunded` when the `allocated_amount` is smaller than the `target amount`
- `funded` when the `allocated_amount` is equal or greater than the `target_amount` and the sum of movements is fewer tham the `allocated_amount`


The `allocated_amount` of a category is depleted by each `movement`.
A `movement` belongs to an account. It can be a `credit` or a `debit`.
✅ A `credit` is a money movement flowing out of your account.
✅ A `debit` is a money movement flowing into your account.
✅ A `movement` has a `payer`.
✅ A `movement` can be assigned to a `category`
Every unassigned movement will be considered `Ready to asign` funds, i.e funds to be added to the budget.

9 changes: 0 additions & 9 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ def sync
PullAccountMovementsJob.perform_later(account_id: params[:account_id])
end

def authentication_result
reference = params[:ref]

# Add the authenticated check to the account
# Add a common REF for all of the accounts
# Associate the account_id coming as part of the response to the account itself
# Use that account_id to fetch the rest of the details and save them
end

# POST /accounts or /accounts.json
def create
@account = Account.new(account_params)
Expand Down
4 changes: 4 additions & 0 deletions bin/standardrb-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

bundle install >/dev/null
git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec standardrb --fix
6 changes: 3 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
external_account_id: "48883f05-bfe1-46fb-818c-d272ace6a069",
external_institution_id: "SANDBOXFINANCE_SFIN0000")

food_category = Category.create!(name: "Food", budget: budget, target_amount_cents: 200_00)
housing_category = Category.create!(name: "Housing", budget: budget, target_amount_cents: 0)
cat_category = Category.create!(name: "Cat", budget: budget, target_amount_cents: 0)
Category.create!(name: "Food", budget: budget, target_amount_cents: 200_00)
Category.create!(name: "Housing", budget: budget, target_amount_cents: 0)
Category.create!(name: "Cat", budget: budget, target_amount_cents: 0)

def create_movement(amount:, date:, account:, description:, category: nil)
Movement.create!(
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/accounts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
end

test "should update account" do
resopnse = patch account_url(@account), params: {account: {iban: @account.iban, name: @account.name}}
patch account_url(@account), params: {account: {iban: @account.iban, name: @account.name}}
assert_redirected_to account_url(@account)
end

Expand Down
4 changes: 2 additions & 2 deletions test/models/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def setup
budget: @budget
)

movement = Movement.create(account_id: account.id, payer: "payer", amount_cents: 100_00)
movement_2 = Movement.create(account_id: account.id, payer: "payer", amount_cents: -50_00)
Movement.create(account_id: account.id, payer: "payer", amount_cents: 100_00)
Movement.create(account_id: account.id, payer: "payer", amount_cents: -50_00)

assert_equal account.balance.cents, 50_00
end
Expand Down
Loading

0 comments on commit 160332e

Please sign in to comment.