Skip to content

Commit

Permalink
add basic seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosimonpicon committed Jun 4, 2023
1 parent 37bd57f commit 96fdd37
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Use a ruby dependency manager like rbenv or asdf. The supported ruby version is

`brew services start postgresql`

4. Preare dabatase
4. Prepare dabatase

`rails db:prepare db:seed`
`rails db:create db:migrate db:seed`

5. Run the server

Expand Down
57 changes: 55 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,60 @@
#
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
# Character.create(name: "Luke", movie: movies.first)
ENV['RAILS_ENV'] = 'development'

budget = Budget.create!(title: "Test budget")
account = Account.create!(name: "Test account", institution: Institution.first, budget: budget)
category = Category.create!(name: "groceries", assigned_amount: "20.00", budget: budget)

account = Account.create!(name: "Test account",
institution: Institution.first,
budget: budget,
institution_id: Institution.first.id,
external_account_id: "48883f05-bfe1-46fb-818c-d272ace6a069")

AuthSession.create!(account: account,
external_id: "707bbbe7-12e3-41e9-98f9-23277b1fb186",
status: "success",
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)

def create_movement(amount:, date:, account:,description:, category: nil)
Movement.create!(
payer: 'payer',
category: category,
account: account,
amount: Money.new(amount, "EUR"),
description: description,
created_at: date
)
end


current_month = DateTime.now.utc.beginning_of_month
previous_month = DateTime.now.utc.beginning_of_month.prev_month
next_month = DateTime.now.utc.beginning_of_month.next_month

create_movement(amount: 600_00, date: previous_month + 2.days, account: account, description: 'payment')
create_movement(amount: -50_00, date: previous_month + 4.days, account: account, description: 'payment')
create_movement(amount: 50_00, date: previous_month + 6.days, account: account, description: 'payment')
create_movement(amount: -40_00, date: previous_month + 8.days, account: account, description: 'payment')
create_movement(amount: -20_00, date: previous_month + 10.days, account: account, description: 'payment')
create_movement(amount: -40_00, date: previous_month + 12.days, account: account, description: 'payment')

create_movement(amount: 600_00, date: current_month + 2.days, account: account, description: 'payment')
create_movement(amount: -50_00, date: current_month + 4.days, account: account, description: 'payment')
create_movement(amount: 50_00, date: current_month + 6.days, account: account, description: 'payment')
create_movement(amount: -40_00, date: current_month + 8.days, account: account, description: 'payment')
create_movement(amount: -20_00, date: current_month + 10.days, account: account, description: 'payment')
create_movement(amount: -40_00, date: current_month + 12.days, account: account, description: 'payment')

create_movement(amount: 600_00, date: next_month + 2.days, account: account, description: 'payment')
create_movement(amount: -50_00, date: next_month + 4.days, account: account, description: 'payment')
create_movement(amount: 50_00, date: next_month + 6.days, account: account, description: 'payment')
create_movement(amount: -40_00, date: next_month + 8.days, account: account, description: 'payment')
create_movement(amount: -20_00, date: next_month + 10.days, account: account, description: 'payment')
create_movement(amount: -40_00, date: next_month + 12.days, account: account, description: 'payment')

0 comments on commit 96fdd37

Please sign in to comment.