diff --git a/.gitignore b/.gitignore
index ac13607..f627f9e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,5 +18,5 @@
config/database.yml
config/config.yml
-
+PocketMoneyDB.sql
**/.DS_Store
diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..4e1e0d2
--- /dev/null
+++ b/.rspec
@@ -0,0 +1 @@
+--color
diff --git a/Gemfile b/Gemfile
index f58c20f..e8dc562 100644
--- a/Gemfile
+++ b/Gemfile
@@ -33,6 +33,7 @@ gem 'haml'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'less-rails'
gem "therubyracer"
+gem "faker"
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
@@ -46,6 +47,14 @@ gem 'pry-rails'
gem 'ruby-progressbar'
+group :test do
+ gem 'rspec'
+ gem 'rspec-rails'
+ gem 'capybara'
+ gem 'factory_girl'
+ gem 'factory_girl_rails'
+end
+
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index cb0d74c..accc559 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -38,6 +38,12 @@ GEM
arel (4.0.0)
atomic (1.1.9)
builder (3.1.4)
+ capybara (2.1.0)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ xpath (~> 2.0)
coderay (1.0.9)
coffee-rails (4.0.0)
coffee-script (>= 2.2.0)
@@ -47,9 +53,17 @@ GEM
execjs
coffee-script-source (1.6.2)
commonjs (0.2.6)
+ diff-lcs (1.2.4)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ factory_girl (4.2.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (4.2.1)
+ factory_girl (~> 4.2.0)
+ railties (>= 3.0.0)
+ faker (1.2.0)
+ i18n (~> 0.5)
haml (4.0.3)
tilt
hike (1.2.2)
@@ -71,8 +85,11 @@ GEM
treetop (~> 1.4.8)
method_source (0.8.1)
mime-types (1.23)
+ mini_portile (0.5.1)
minitest (4.7.4)
multi_json (1.7.4)
+ nokogiri (1.6.0)
+ mini_portile (~> 0.5.0)
pg (0.15.1)
polyglot (0.3.3)
pry (0.9.12.2)
@@ -104,6 +121,21 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.5)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.3)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.3)
+ rspec-rails (2.14.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
ruby-progressbar (1.1.1)
sass (3.2.9)
sass-rails (4.0.0.rc1)
@@ -141,13 +173,19 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
+ xpath (2.0.0)
+ nokogiri (~> 1.3)
yard (0.8.7)
PLATFORMS
ruby
DEPENDENCIES
+ capybara
coffee-rails (~> 4.0.0)
+ factory_girl
+ factory_girl_rails
+ faker
haml
jbuilder (~> 1.0.1)
jquery-rails
@@ -157,6 +195,8 @@ DEPENDENCIES
pry-doc
pry-rails
rails (= 4.0.0.rc1)
+ rspec
+ rspec-rails
ruby-progressbar
sass-rails (~> 4.0.0.rc1)
sdoc
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index f3aa0e7..29c7716 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -6,5 +6,6 @@ def index
def show
@account = Account.find(params[:id])
+ @transactions = @account.active_transactions
end
end
diff --git a/app/models/account.rb b/app/models/account.rb
index 2ea98c4..fd4cfbb 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -22,7 +22,7 @@ def type_name
def active_transactions
- transactions.active.balance
+ transactions.transaction_includes.active.balance
end
def basic_balance
diff --git a/app/models/transaction.rb b/app/models/transaction.rb
index ee2cc2b..1e456a1 100644
--- a/app/models/transaction.rb
+++ b/app/models/transaction.rb
@@ -23,7 +23,8 @@ class Transaction < ActiveRecord::Base
belongs_to :account
has_many :splits
-
+ validates :account_id, presence: true
+ validates :amount, presence: true
def split?
@split ||= splits.size > 1
@@ -154,7 +155,7 @@ def transaction_query
t = transaction_interval
t = t.where(pm_type: pm_type) if pm_type
t = t.where(account_id: account_id) if account_id
- t = t.where('categories.id = ?', category_id) if category_id
+ #t = t.where('categories.id = ?', category_id) if category_id
t
end
diff --git a/app/views/accounts/show.haml b/app/views/accounts/show.haml
index 3ab3f5b..1f86647 100644
--- a/app/views/accounts/show.haml
+++ b/app/views/accounts/show.haml
@@ -7,5 +7,5 @@
= ['(',@account.transactions.count, ')'].join
-= render_transactions @account.active_transactions, show_balance: true
+= render_transactions @transactions.group_by {|t| t.date.to_s(:short_date) } , show_balance: true
diff --git a/app/views/transactions/_form.html.erb b/app/views/transactions/_form.html.erb
index 9258302..984c17f 100644
--- a/app/views/transactions/_form.html.erb
+++ b/app/views/transactions/_form.html.erb
@@ -31,14 +31,14 @@
<%= f.label :category_id %>
<%= f.number_field :category_id %>
-
- <%= f.label :class_id %>
- <%= f.number_field :class_id %>
-
-
- <%= f.label :memo %>
- <%= f.text_area :memo %>
-
+ <%#%>
+ <%#<%= f.label :class_id %>
%>
+ <%#<%= f.number_field :class_id %>%>
+ <%#
%>
+ <%#%>
+ <%#<%= f.label :memo %>
%>
+ <%#<%= f.text_area :memo %>%>
+ <%#
%>
<%= f.label :amount %>
<%= f.text_field :amount %>
@@ -47,18 +47,18 @@
<%= f.label :cleared %>
<%= f.check_box :cleared %>
-
- <%= f.label :currency_id %>
- <%= f.text_field :currency_id %>
-
-
- <%= f.label :currency_exchange_rate %>
- <%= f.text_field :currency_exchange_rate %>
-
-
- <%= f.label :balance %>
- <%= f.text_field :balance %>
-
+ <%#%>
+ <%#<%= f.label :currency_id %>
%>
+ <%#<%= f.text_field :currency_id %>%>
+ <%#
%>
+ <%#%>
+ <%#<%= f.label :currency_exchange_rate %>
%>
+ <%#<%= f.text_field :currency_exchange_rate %>%>
+ <%#
%>
+ <%#%>
+ <%#<%= f.label :balance %>
%>
+ <%#<%= f.text_field :balance %>%>
+ <%#
%>
<%= f.submit %>
diff --git a/app/views/transactions/_transaction.haml b/app/views/transactions/_transaction.haml
index b1adf79..b4a566b 100644
--- a/app/views/transactions/_transaction.haml
+++ b/app/views/transactions/_transaction.haml
@@ -3,7 +3,7 @@
%td= link_to transaction.date.to_s(:short_date), transaction
%td= transaction.account.name
%td= transaction.payee_name
- %td= transaction.category_name
+ %td= transaction.category_name
%td.currency= money transaction.amount
- if show_balance
diff --git a/app/views/transactions/_transactions.haml b/app/views/transactions/_transactions.haml
index 3833a75..aba61d4 100644
--- a/app/views/transactions/_transactions.haml
+++ b/app/views/transactions/_transactions.haml
@@ -11,7 +11,7 @@
%th Balance
%tbody
- - @filter.grouped_transactions.each do |header, transactions|
+ - transactions.each do |header, transactions|
%tr
%td.split(colspan=5)
= header
diff --git a/app/views/transactions/index.haml b/app/views/transactions/index.haml
index 37ef058..0a3462e 100644
--- a/app/views/transactions/index.haml
+++ b/app/views/transactions/index.haml
@@ -5,7 +5,7 @@
= render partial: 'filters'
.span9
= render partial: 'header'
- = render_transactions @filter.transactions, show_balance: false
+ = render_transactions @filter.grouped_transactions, show_balance: false
%br
diff --git a/config/initializers/pocket_money.rb b/config/initializers/pocket_money.rb
index d147d71..3ed789e 100644
--- a/config/initializers/pocket_money.rb
+++ b/config/initializers/pocket_money.rb
@@ -1 +1 @@
-require 'pocket_money'
+require 'pocket_money' if ENV["RAILS_ENV"] != 'test'
diff --git a/db/migrate/20130531005809_create_transactions.rb b/db/migrate/20130531005809_create_transactions.rb
index 9ca3316..8e02e5b 100644
--- a/db/migrate/20130531005809_create_transactions.rb
+++ b/db/migrate/20130531005809_create_transactions.rb
@@ -19,7 +19,7 @@ def change
t.integer :payee_id
t.integer :category_id
t.integer :department_id
- t.decimal :amount
+ t.decimal :amount, :precision => 10, :scale => 2
t.boolean :cleared
t.string :uuid
diff --git a/db/schema.rb b/db/schema.rb
index af83078..3965c60 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -13,9 +13,6 @@
ActiveRecord::Schema.define(version: 20130718222102) do
- # These are extensions that must be enabled in order to support this database
- enable_extension "plpgsql"
-
create_table "accounts", force: true do |t|
t.boolean "deleted"
t.datetime "updated_at"
@@ -134,7 +131,7 @@
t.integer "payee_id"
t.integer "category_id"
t.integer "department_id"
- t.decimal "amount"
+ t.decimal "amount", precision: 10, scale: 2
t.boolean "cleared"
t.string "uuid"
t.datetime "created_at"
diff --git a/db/seeds.rb b/db/seeds.rb
index 4edb1e8..34aafb4 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -1,7 +1,133 @@
-# This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
-#
-# Examples:
-#
-# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
-# Mayor.create(name: 'Emanuel', city: cities.first)
+boolean = [false] #To have inactive transactions, add true at array [true, false]
+currency = ["AED", "ALL", "CAD", "CNY", "MXN", "IRR", "JPY", "USD", "UYU"]
+#Seed to Account table
+15.times do
+ Account.create(
+ deleted: false,
+ pm_id: rand(0..8),
+ pm_account_type: rand(0..8),
+ display_order: rand(1..4),
+ name: Faker::Company.name,
+ balance_overall: rand*(5),
+ balance_cleared: rand*(5),
+ number: Faker::Number.number(2),
+ institution: Faker::Company.suffix,
+ phone: Faker::PhoneNumber.cell_phone,
+ expiration_date: Faker::Business.credit_card_expiry_date.strftime("%d,%m,%Y"),
+ check_number: Faker::Number.digit,
+ notes: Faker::Lorem.paragraph,
+ pm_icon: "image",
+ url: Faker::Internet.url,
+ of_x_id: "dummy",
+ of_x_url: Faker::Internet.domain_word,
+ password: Faker::Internet.password,
+ fee: rand*(100),
+ fixed_percent: rand*(20),
+ limit_amount: 1000 + rand*(9_000),
+ limit: boolean.sample,
+ total_worth: boolean.sample,
+ exchange_rate: rand*(10),
+ currency_code: currency.sample,
+ last_sync_time: (Time.now - rand(60).days).to_date,
+ routing_number: rand(100),
+ overdraft_account_id: rand(30).to_s,
+ keep_the_change_account_id: rand(30).to_s,
+ heek_change_round_to: rand*(5),
+ uuid: Faker::Code.isbn(64)
+ )
+ #seed to category table
+ Category.create(
+ name: Faker::Commerce.department,
+ deleted: boolean.sample,
+ pm_id: rand(0..8),
+ pm_type: rand(0..2),
+ budget_period: rand(100..10000),
+ budget_limit: rand(500..5000),
+ include_subcategories: boolean.sample,
+ rollover: boolean.sample,
+ uuid: Faker::Code.isbn
+ )
+ #seed to department table
+ Department.create(
+ name: Faker::Commerce.product_name,
+ pm_id: rand(0..8),
+ uuid: Faker::Code.isbn,
+ deleted: boolean.sample
+ )
+ #seed to Payee table
+ Payee.create(
+ name: Faker::Name.name,
+ deleted: boolean.sample,
+ pm_id: rand(0..8),
+ latitude: Faker::Address.latitude,
+ longitude: Faker::Address.longitude,
+ uuid: Faker::Code.isbn
+ )
+end
+
+
+40.times do
+ payee = Payee.all.sample
+ account = Account.all.sample
+ amount = 10 + rand*(10_000)
+
+ #seed to transaction table
+ Transaction.create(
+ pm_type: rand(0..2),
+ pm_id: rand(0..8),
+ account_id: account.id,
+ pm_account_id: account.pm_id,
+ pm_payee: payee.pm_id,
+ pm_sub_total: rand*(1_000),
+ pm_of_x_id: "dummy",
+ pm_image: "dummy",
+ pm_overdraft_id: rand(30).to_s,
+ date: Time.now - rand(0..60).days,
+ deleted: boolean.sample,
+ check_number: rand(10).to_s,
+ payee_name: payee.name,
+ payee_id: payee.id,
+ category_id: Category.all.map(&:id).sample,
+ department_id: Department.all.map(&:id).sample,
+ amount: amount,
+ cleared: boolean.sample,
+ uuid: Faker::Code.isbn
+ )
+ #create split to transaction
+ transaction = Transaction.last
+ num_of_split = rand(1..5)
+ max_amount_split = amount/(num_of_split - 1)
+ sum_split_amount = 0
+ (num_of_split - 1).times do
+ split_amount = 1 + rand(max_amount_split)
+ sum_split_amount += split_amount
+ Split.create(
+ pm_id: transaction.pm_id,
+ transaction_id: transaction.id,
+ amount: split_amount,
+ xrate: rand*(5),
+ category_id: transaction.category_id,
+ class_id: rand(0..10),
+ memo: Faker::Lorem.paragraph,
+ transfer_to_account_id: rand(100),
+ currency_code: currency.sample,
+ of_x_id: "dummy"
+ )
+ end
+ last_split_amount = amount - sum_split_amount
+ Split.create(
+ pm_id: transaction.pm_id,
+ transaction_id: transaction.id,
+ amount: last_split_amount,
+ xrate: rand*(5),
+ category_id: transaction.category_id,
+ class_id: rand(0..10),
+ memo: Faker::Lorem.paragraph,
+ transfer_to_account_id: rand(100),
+ currency_code: currency.sample,
+ of_x_id: "dummy"
+ )
+
+end
+
+
diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb
new file mode 100644
index 0000000..037f4a5
--- /dev/null
+++ b/spec/controllers/transactions_controller_spec.rb
@@ -0,0 +1,114 @@
+require 'spec_helper'
+describe TransactionsController do
+ let(:transaction) { create(:transaction) }
+ #spec to GET methods
+ describe "Get index" do
+ it "should render the index templates" do
+ get :index
+ expect(response).to render_template("index")
+ end
+ it "should response with 200 http code" do
+ get :index
+ response.should be_succes
+ end
+ end
+
+ describe 'GET #new' do
+ it 'should render new template' do
+ get :new
+ response.should render_template :new
+ end
+ it 'should response with 200 code' do
+ get :new
+ response.should be_success
+ end
+ end
+
+ describe 'GET #show' do
+ it 'should redirect to #show view' do
+ get :show, id: transaction
+ response.should render_template :show
+ end
+ it 'should response with 200 http code' do
+ get :show, id: transaction
+ response.should be_success
+ end
+ end
+
+ describe 'GET #edit' do
+ it 'should render #edit view' do
+ get :edit, id: transaction
+ response.should render_template :edit
+ end
+ it 'should response with 200 http code' do
+ get :edit, id: transaction
+ response.should be_success
+ end
+ end
+ #spec to post methods
+ describe 'POST #create' do
+ context "valid attributes" do
+ it 'should create a new transaction' do
+ expect{
+ post :create, transaction: attributes_for(:transaction)
+ }.to change(Transaction, :count).by(1)
+ end
+ it 'should redirect to #show view' do
+ post :create, transaction: attributes_for(:transaction)
+ response.should redirect_to Transaction.last
+ end
+ end
+ context "invalid attributes" do
+ it 'should not create a new transaction' do
+ expect{
+ post :create, transaction: attributes_for(:transaction, account_id: nil, amount: nil)
+ }.to_not change(Transaction, :count)
+ end
+ it 'should render to #new view' do
+ post :create, transaction: attributes_for(:transaction, account_id: nil, amount: nil)
+ response.should render_template :new
+ end
+
+ end
+ end
+
+ #spec to put method
+ describe 'PUT #update' do
+ new_uuid = "12yag172-1721nh-12"
+ new_amount = 99_999
+ context 'valid attributes' do
+ it 'should located the requested transaction' do
+ put :update, id: transaction, transaction: FactoryGirl.attributes_for(:transaction)
+ assigns(:transaction).should eq(transaction)
+ end
+ it "should change the transaction's attributes" do
+ put :update, id: transaction,
+ transaction: FactoryGirl.attributes_for(:transaction, amount: new_amount)
+ transaction.reload
+ transaction.amount.should eq(new_amount)
+ end
+ it "should redirect to #show view" do
+ put :update, id: transaction, transaction: FactoryGirl.attributes_for(:transaction)
+ response.should redirect_to transaction
+ end
+ end
+ context 'invalid attributes' do
+ it 'should not located the requested boook' do
+ put :update, id: transaction, transaction: FactoryGirl.attributes_for(:transaction, uuid: nil, amount: nil)
+ assigns(:transaction2).should_not eq(transaction)
+ end
+ it "should not change the transaction's attributes" do
+ put :update, id: transaction,
+ transaction: FactoryGirl.attributes_for(:transaction, uuid: nil, amount: nil)
+ transaction.reload
+ transaction.amount.should_not eq(new_amount)
+ transaction.uuid.should_not eq(new_uuid)
+ end
+ it "should redirect to #edit view" do
+ put :update, id: transaction,
+ transaction: attributes_for(:transaction, uuid: nil, amount: nil)
+ response.should render_template :edit
+ end
+ end
+ end
+end
diff --git a/spec/factories/account.rb b/spec/factories/account.rb
new file mode 100644
index 0000000..f52af00
--- /dev/null
+++ b/spec/factories/account.rb
@@ -0,0 +1,39 @@
+require 'faker'
+
+boolean = [true, false]
+currency = ["AED", "ALL", "CAD", "CNY", "MXN", "IRR", "JPY", "USD", "UYU"]
+FactoryGirl.define do
+ factory :account do
+ deleted false
+ pm_id (0..2).to_a.sample
+ pm_account_type (0..8).to_a.sample
+ display_order (1..9).to_a.sample
+ name Faker::Company.name
+ balance_overall (1..9).to_a.sample
+ balance_cleared (1..9).to_a.sample
+ number Faker::Number.number(2)
+ institution Faker::Company.suffix
+ phone Faker::PhoneNumber.cell_phone
+ expiration_date Faker::Business.credit_card_expiry_date.strftime("%d%m%Y")
+ check_number (1..9).to_a.sample
+ notes Faker::Lorem.paragraph
+ pm_icon "image"
+ url Faker::Internet.url
+ of_x_id "dummy"
+ of_x_url Faker::Internet.domain_word
+ password Faker::Internet.password
+ fee (1..9).to_a.sample
+ fixed_percent (1..9).to_a.sample
+ limit_amount (1..9).to_a.sample
+ limit boolean.sample
+ total_worth boolean.sample
+ exchange_rate (1..9).to_a.sample
+ currency_code currency.sample
+ last_sync_time Time.now
+ routing_number (1..9).to_a.sample
+ overdraft_account_id (1..9).to_a.sample
+ keep_the_change_account_id (1..9).to_a.sample
+ heek_change_round_to (1..9).to_a.sample
+ uuid Faker::Code.isbn(64)
+ end
+end
diff --git a/spec/factories/category.rb b/spec/factories/category.rb
new file mode 100644
index 0000000..018c146
--- /dev/null
+++ b/spec/factories/category.rb
@@ -0,0 +1,15 @@
+require 'faker'
+
+FactoryGirl.define do
+ factory :category do
+ name Faker::Commerce.department
+ deleted false
+ pm_id (0..8).to_a.sample
+ pm_type (0..2).to_a.sample
+ budget_period (100..1000).to_a.sample
+ budget_limit (50..500).to_a.sample
+ include_subcategories false
+ rollover false
+ uuid Faker::Code.isbn
+ end
+end
diff --git a/spec/factories/department.rb b/spec/factories/department.rb
new file mode 100644
index 0000000..a3b4e5d
--- /dev/null
+++ b/spec/factories/department.rb
@@ -0,0 +1,11 @@
+require 'faker'
+
+FactoryGirl.define do
+ factory :department do
+ name Faker::Commerce.product_name
+ pm_id (0..8).to_a.sample
+ uuid Faker::Code.isbn
+ deleted false
+ end
+end
+
diff --git a/spec/factories/payee.rb b/spec/factories/payee.rb
new file mode 100644
index 0000000..e967919
--- /dev/null
+++ b/spec/factories/payee.rb
@@ -0,0 +1,13 @@
+require 'faker'
+
+FactoryGirl.define do
+ factory :payee do
+ name Faker::Name.name
+ deleted false
+ pm_id (0..8).to_a.sample
+ latitude Faker::Address.latitude
+ longitude Faker::Address.longitude
+ uuid Faker::Code.isbn
+
+ end
+end
diff --git a/spec/factories/split.rb b/spec/factories/split.rb
new file mode 100644
index 0000000..41e5390
--- /dev/null
+++ b/spec/factories/split.rb
@@ -0,0 +1,18 @@
+#require 'faker'
+#currency = ["AED", "ALL", "CAD", "CNY", "MXN", "IRR", "JPY", "USD", "UYU"]
+#transaction = FactoryGirl.create(:transaction)
+#FactoryGirl.define do
+ #factory :split do
+ #pm_id transaction.pm_id
+ #transaction_id transaction.id
+ #amount transaction.amount
+ #xrate (1..10).to_a.sample
+ #category_id transaction.category_id
+ #class_id (0..10).to_a.sample
+ #memo Faker::Lorem.paragraph
+ #transfer_to_account_id (1..100).to_a.sample
+ #currency_code currency.sample
+ #of_x_id "dummy"
+ #end
+#end
+
diff --git a/spec/factories/transaction.rb b/spec/factories/transaction.rb
new file mode 100644
index 0000000..60afb1a
--- /dev/null
+++ b/spec/factories/transaction.rb
@@ -0,0 +1,50 @@
+require 'faker'
+
+currency = ["AED", "ALL", "CAD", "CNY", "MXN", "IRR", "JPY", "USD", "UYU"]
+account = FactoryGirl.create(:account)
+payee = FactoryGirl.create(:payee)
+department = FactoryGirl.create(:department)
+category = FactoryGirl.create(:category)
+
+
+FactoryGirl.define do
+ factory :transaction do
+ pm_type (0..2).to_a.sample
+ pm_id (0..8).to_a.sample
+ account_id account.id
+ pm_account_id account.pm_id
+ pm_payee payee.name
+ pm_sub_total (10..10_000).to_a.sample
+ pm_of_x_id "dummy"
+ pm_image "dummy"
+ pm_overdraft_id (1..30).to_a.sample.to_s
+ date Time.now
+ deleted false
+ check_number (1..10).to_a.sample
+ payee_name payee.name
+ payee_id payee.pm_id
+ category_id category.id
+ department_id department.id
+ amount Faker::Number.number(2)
+ cleared true
+ uuid Faker::Code.isbn
+ end
+end
+
+transaction = FactoryGirl.create(:transaction)
+
+FactoryGirl.define do
+ factory :split do
+ pm_id transaction.pm_id
+ transaction_id transaction.id
+ amount transaction.amount
+ xrate (1..10).to_a.sample
+ category_id transaction.category_id
+ class_id (0..10).to_a.sample
+ memo Faker::Lorem.paragraph
+ transfer_to_account_id (1..100).to_a.sample
+ currency_code currency.sample
+ of_x_id "dummy"
+ end
+end
+
diff --git a/spec/factories_spec.rb b/spec/factories_spec.rb
new file mode 100644
index 0000000..d2e7753
--- /dev/null
+++ b/spec/factories_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+describe 'validate FactoryGirl factories' do
+ FactoryGirl.factories.each do |factory|
+ context "with factory for: #{factory.name}" do
+ subject { FactoryGirl.build(factory.name) }
+
+ it "is valid" do
+ subject.should be_valid if subject.class.ancestors.include?(ActiveRecord::Base)
+ end
+ end
+ end
+end
+
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
new file mode 100644
index 0000000..e59d45c
--- /dev/null
+++ b/spec/models/account_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Account do
+ let(:account) {create(:account)}
+
+ it "has a valid account" do
+ account.should be_valid
+ end
+end
+
diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb
new file mode 100644
index 0000000..5396105
--- /dev/null
+++ b/spec/models/category_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Category do
+ let(:category) {create(:category)}
+
+ it "has a valid category" do
+ category.should be_valid
+ end
+end
diff --git a/spec/models/department_spec.rb b/spec/models/department_spec.rb
new file mode 100644
index 0000000..343e023
--- /dev/null
+++ b/spec/models/department_spec.rb
@@ -0,0 +1,9 @@
+require 'department'
+
+describe Department do
+ let(:department) {create(:department)}
+
+ it "has avalid department" do
+ department.should be_valid
+ end
+end
diff --git a/spec/models/payee_spec.rb b/spec/models/payee_spec.rb
new file mode 100644
index 0000000..eeb8cf0
--- /dev/null
+++ b/spec/models/payee_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Payee do
+ let(:payee) {create(:payee)}
+
+ it "has a valid payee" do
+ payee.should be_valid
+ end
+end
diff --git a/spec/models/split_spec.rb b/spec/models/split_spec.rb
new file mode 100644
index 0000000..edb1ab6
--- /dev/null
+++ b/spec/models/split_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Split do
+ let(:split) {create(:split)}
+
+ it "has a valid split" do
+ split.should be_valid
+ end
+end
+
diff --git a/spec/models/transaction_spec.rb b/spec/models/transaction_spec.rb
new file mode 100644
index 0000000..85c7179
--- /dev/null
+++ b/spec/models/transaction_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Transaction do
+ let(:transaction) {create(:transaction)}
+
+ it "has a valid transaction" do
+ transaction.should be_valid
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..dc2c0d4
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,22 @@
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+require 'factory_girl_rails'
+
+Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
+
+ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
+
+RSpec.configure do |config|
+
+ config.include FactoryGirl::Syntax::Methods
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.use_transactional_fixtures = true
+
+ config.infer_base_class_for_anonymous_controllers = false
+
+ config.order = "random"
+
+
+end