Skip to content

Commit

Permalink
Schema and annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dreikanter committed Oct 18, 2015
1 parent 2b5b969 commit 2fcfa0f
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 42 deletions.
12 changes: 12 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# == Schema Information
#
# Table name: categories
#
# id :integer not null, primary key
# code :string default(""), not null
# title :string not null
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

class Category < ActiveRecord::Base
validates :title, presence: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/planned_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :integer default(0), not null
# amount_cents :decimal(8, ) not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
Expand Down
11 changes: 11 additions & 0 deletions app/models/reconciliation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# == Schema Information
#
# Table name: reconciliations
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :decimal(8, ) not null
# created_at :datetime not null
# updated_at :datetime not null
#

class Reconciliation < ActiveRecord::Base
validates :account_id, :amount, presence: true

Expand Down
17 changes: 8 additions & 9 deletions app/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#
# Table name: transactions
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :integer default(0), not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# reconsiliation :boolean default(FALSE)
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :decimal(8, ) default(0), not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

class Transaction < ActiveRecord::Base
Expand Down
16 changes: 16 additions & 0 deletions app/models/transfer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# == Schema Information
#
# Table name: transfers
#
# id :integer not null, primary key
# from_transaction_id :integer not null
# to_transaction_id :integer not null
# from_account_id :integer not null
# to_account_id :integer not null
# amount_cents :decimal(8, ) default(0), not null
# currency :string not null
# description :string
# created_at :datetime not null
# updated_at :datetime not null
#

class Transfer < ActiveRecord::Base
include Currency

Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20151018185207_create_transfers.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class CreateTransfers < ActiveRecord::Migration
def change
create_table :transfers do |t|
t.integer :from_transaction_id, references: :transactions
t.integer :to_transaction_id, references: :transactions
t.integer :from_account_id, references: :accounts
t.integer :to_account_id, references: :accounts
t.integer :from_transaction_id, null: false
t.integer :to_transaction_id, null: false
t.integer :from_account_id, null: false
t.integer :to_account_id, null: false
t.decimal :amount_cents, null: false, default: 0, precision: 8, scale: 0
t.string :currency, null: false
t.string :description
Expand Down
8 changes: 4 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
end

create_table "transfers", force: :cascade do |t|
t.integer "from_transaction_id"
t.integer "to_transaction_id"
t.integer "from_account_id"
t.integer "to_account_id"
t.integer "from_transaction_id", null: false
t.integer "to_transaction_id", null: false
t.integer "from_account_id", null: false
t.integer "to_account_id", null: false
t.decimal "amount_cents", precision: 8, default: 0, null: false
t.string "currency", null: false
t.string "description"
Expand Down
12 changes: 12 additions & 0 deletions test/factories/categories.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# == Schema Information
#
# Table name: categories
#
# id :integer not null, primary key
# code :string default(""), not null
# title :string not null
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

FactoryGirl.define do
factory :category do
code "MyString"
Expand Down
11 changes: 11 additions & 0 deletions test/factories/reconciliations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# == Schema Information
#
# Table name: reconciliations
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :decimal(8, ) not null
# created_at :datetime not null
# updated_at :datetime not null
#

FactoryGirl.define do
factory :reconciliation do
account_ai 1
Expand Down
16 changes: 16 additions & 0 deletions test/factories/transfers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# == Schema Information
#
# Table name: transfers
#
# id :integer not null, primary key
# from_transaction_id :integer not null
# to_transaction_id :integer not null
# from_account_id :integer not null
# to_account_id :integer not null
# amount_cents :decimal(8, ) default(0), not null
# currency :string not null
# description :string
# created_at :datetime not null
# updated_at :datetime not null
#

FactoryGirl.define do
factory :transfer do
from_id 1
Expand Down
10 changes: 6 additions & 4 deletions test/fixtures/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#
# Table name: categories
#
# id :integer not null, primary key
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# code :string default(""), not null
# title :string not null
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/planned_transactions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :integer default(0), not null
# amount_cents :decimal(8, ) not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/rates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Table name: rates
#
# id :integer not null, primary key
# ask :float not null
# bid :float not null
# rate :float not null
# from :string not null
# to :string not null
Expand Down
17 changes: 8 additions & 9 deletions test/fixtures/transactions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#
# Table name: transactions
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :integer default(0), not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# reconsiliation :boolean default(FALSE)
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :decimal(8, ) default(0), not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Expand Down
12 changes: 12 additions & 0 deletions test/models/category_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# == Schema Information
#
# Table name: categories
#
# id :integer not null, primary key
# code :string default(""), not null
# title :string not null
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

require 'test_helper'

class CategoryTest < ActiveSupport::TestCase
Expand Down
2 changes: 1 addition & 1 deletion test/models/planned_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :integer default(0), not null
# amount_cents :decimal(8, ) not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
Expand Down
2 changes: 2 additions & 0 deletions test/models/rate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Table name: rates
#
# id :integer not null, primary key
# ask :float not null
# bid :float not null
# rate :float not null
# from :string not null
# to :string not null
Expand Down
11 changes: 11 additions & 0 deletions test/models/reconciliation_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# == Schema Information
#
# Table name: reconciliations
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :decimal(8, ) not null
# created_at :datetime not null
# updated_at :datetime not null
#

require 'test_helper'

class ReconciliationTest < ActiveSupport::TestCase
Expand Down
17 changes: 8 additions & 9 deletions test/models/transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#
# Table name: transactions
#
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :integer default(0), not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# reconsiliation :boolean default(FALSE)
# id :integer not null, primary key
# account_id :integer not null
# amount_cents :decimal(8, ) default(0), not null
# currency :string not null
# category_id :integer
# description :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#

require 'test_helper'
Expand Down
16 changes: 16 additions & 0 deletions test/models/transfer_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# == Schema Information
#
# Table name: transfers
#
# id :integer not null, primary key
# from_transaction_id :integer not null
# to_transaction_id :integer not null
# from_account_id :integer not null
# to_account_id :integer not null
# amount_cents :decimal(8, ) default(0), not null
# currency :string not null
# description :string
# created_at :datetime not null
# updated_at :datetime not null
#

require 'test_helper'

class TransferTest < ActiveSupport::TestCase
Expand Down

0 comments on commit 2fcfa0f

Please sign in to comment.