From b57c60905385c5c3a498943a330c22f795e4a4b7 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 16:15:32 -0500 Subject: [PATCH 01/35] added @filter variable in show method --- app/controllers/accounts_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index f3aa0e7..a99d14d 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]) + @filter = @account.transactions.filter(params) end end From ca243aee068d631ccc962534a4f02227b261e487 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 19:42:14 -0500 Subject: [PATCH 02/35] added instance variable @transactions --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index a99d14d..29c7716 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -6,6 +6,6 @@ def index def show @account = Account.find(params[:id]) - @filter = @account.transactions.filter(params) + @transactions = @account.active_transactions end end From 9c36ef2cefd4ed412ae3f3836b83fe8bdf626b89 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 19:44:16 -0500 Subject: [PATCH 03/35] changed query in active transaction method --- app/models/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From f07a3f08ef741919e12bed346584cbf2b7de5510 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 19:46:24 -0500 Subject: [PATCH 04/35] changed variable @account to @transactions --- app/views/accounts/show.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 02af398d3b2f87fa8e3928ca83d58286314c962b Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 19:48:17 -0500 Subject: [PATCH 05/35] changed method transactions to grouped_transactions --- app/views/transactions/index.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 29811c71af2aba3ab894c4206ae5c7bf6d660dc2 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 19:50:48 -0500 Subject: [PATCH 06/35] used the variable transaction --- app/views/transactions/_transactions.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From d7862168cfbe7a0846a01ba03671adccf7f0c54e Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Mon, 14 Oct 2013 11:13:46 -0500 Subject: [PATCH 07/35] added faker gem and few dummy data to application works, also comment some lines --- Gemfile | 1 + Gemfile.lock | 3 ++ app/models/transaction.rb | 2 +- app/views/transactions/_form.html.erb | 40 ++++++++++++------------ app/views/transactions/_transaction.haml | 2 +- db/schema.rb | 16 ---------- db/seeds.rb | 6 ++++ 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/Gemfile b/Gemfile index f58c20f..bd697e5 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. diff --git a/Gemfile.lock b/Gemfile.lock index cb0d74c..f7a381a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,8 @@ GEM erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) + faker (1.2.0) + i18n (~> 0.5) haml (4.0.3) tilt hike (1.2.2) @@ -148,6 +150,7 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 4.0.0) + faker haml jbuilder (~> 1.0.1) jquery-rails diff --git a/app/models/transaction.rb b/app/models/transaction.rb index ee2cc2b..f817a05 100644 --- a/app/models/transaction.rb +++ b/app/models/transaction.rb @@ -154,7 +154,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/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..a33df5f 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= "Category" %td.currency= money transaction.amount - if show_balance diff --git a/db/schema.rb b/db/schema.rb index af83078..925310b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,21 +1,5 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - 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" diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..77b6dd7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,9 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +Account.create( + deleted: false + pm_id: 1 + pm_acunt_type: 1 + + From 00136af25831f65b4a68a9e106d9232dabfb7d2b Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Mon, 14 Oct 2013 14:07:22 -0500 Subject: [PATCH 08/35] created seeds to bernard application --- db/seeds.rb | 134 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 11 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 77b6dd7..adb7c24 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,13 +1,125 @@ -# 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) -Account.create( - deleted: false - pm_id: 1 - pm_acunt_type: 1 +boolean = [true, false] +currency = ["AED", "ALL", "CAD", "CNY", "MXN", "IRR", "JPY", "USD", "UYU"] +#Seed to Account table +5.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..8), + 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 + +10.times do + + pm = rand(0..2) + pm_id = rand(0..8) + account = Account.all.map(&:id).sample + payee = Payee.all.map(&:id).sample + #seed to transaction table + Transaction.create( + pm_type: pm, + pm_id: pm_id, + account_id: account, + pm_account_id: account, + pm_payee: Payee.find(payee).name, + 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.find(payee).name, + payee_id: payee, + category_id: Category.all.map(&:id).sample, + department_id: Department.all.map(&:id).sample, + amount: 10 + rand*(10_000), + cleared: boolean.sample, + uuid: Faker::Code.isbn + ) + +end +3.times do + transaction_id = Transaction.all.map(&:id).sample + transaction = Transaction.find(transaction_id) + #seed to split table + Split.create( + pm_id: transaction.pm_id, + transaction_id: transaction_id, + amount: transaction.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 + + + + + + + + + From b375358eae57a9043b99b440b36062393deb5e4f Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Mon, 14 Oct 2013 14:09:37 -0500 Subject: [PATCH 09/35] added category_id in the transactions view --- app/views/transactions/_transaction.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/transactions/_transaction.haml b/app/views/transactions/_transaction.haml index a33df5f..76a66b7 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= "Category" + %td= transaction.category_id %td.currency= money transaction.amount - if show_balance From 916119468ae502b4aad46e34520c23cc082ac214 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 10:47:44 -0500 Subject: [PATCH 10/35] refactor seed to have relation between transactions and splits --- .rspec | 1 + config/initializers/pocket_money.rb | 2 +- .../20130531005809_create_transactions.rb | 2 +- db/schema.rb | 15 ++++- db/seeds.rb | 63 +++++++++++-------- 5 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/config/initializers/pocket_money.rb b/config/initializers/pocket_money.rb index d147d71..37ad7c4 100644 --- a/config/initializers/pocket_money.rb +++ b/config/initializers/pocket_money.rb @@ -1 +1 @@ -require 'pocket_money' +#require 'pocket_money' 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 925310b..3965c60 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,16 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + ActiveRecord::Schema.define(version: 20130718222102) do create_table "accounts", force: true do |t| @@ -118,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 adb7c24..54dfcce 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,4 @@ -boolean = [true, false] +boolean = [true] #To have inactive transactions, add false at array [true, false] currency = ["AED", "ALL", "CAD", "CNY", "MXN", "IRR", "JPY", "USD", "UYU"] #Seed to Account table 5.times do @@ -40,7 +40,7 @@ name: Faker::Commerce.department, deleted: boolean.sample, pm_id: rand(0..8), - pm_type: rand(0..8), + pm_type: rand(0..2), budget_period: rand(100..10000), budget_limit: rand(500..5000), include_subcategories: boolean.sample, @@ -65,17 +65,19 @@ ) end +account_all = Account.all.map(&:id) +payee_all = Payee.all.map(&:id) + 10.times do - pm = rand(0..2) - pm_id = rand(0..8) - account = Account.all.map(&:id).sample - payee = Payee.all.map(&:id).sample - + account = account_all.sample + amount = 10 + rand*(10_000) + payee = payee_all.sample + #seed to transaction table Transaction.create( - pm_type: pm, - pm_id: pm_id, + pm_type: rand(0..2), + pm_id: rand(0..8), account_id: account, pm_account_id: account, pm_payee: Payee.find(payee).name, @@ -90,20 +92,36 @@ payee_id: payee, category_id: Category.all.map(&:id).sample, department_id: Department.all.map(&:id).sample, - amount: 10 + rand*(10_000), + amount: amount, cleared: boolean.sample, uuid: Faker::Code.isbn ) - -end -3.times do - transaction_id = Transaction.all.map(&:id).sample - transaction = Transaction.find(transaction_id) - #seed to split table + #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: transaction.amount, + transaction_id: transaction.id, + amount: last_split_amount, xrate: rand*(5), category_id: transaction.category_id, class_id: rand(0..10), @@ -112,14 +130,7 @@ currency_code: currency.sample, of_x_id: "dummy" ) -end - - - - - - - +end From 99e0764bf6504dfd23d20762b0264ed33453724c Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 11:08:02 -0500 Subject: [PATCH 11/35] change value from true to false --- db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index 54dfcce..20986f6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,4 @@ -boolean = [true] #To have inactive transactions, add false at array [true, false] +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 5.times do From 04ee6b98a4b3ff59f9b947f26d22045d30a9d423 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 11:12:04 -0500 Subject: [PATCH 12/35] increased seeds to transactions and accounts --- db/seeds.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 20986f6..455ee5a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ 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 -5.times do +10.times do Account.create( deleted: false, pm_id: rand(0..8), @@ -68,7 +68,7 @@ account_all = Account.all.map(&:id) payee_all = Payee.all.map(&:id) -10.times do +30.times do account = account_all.sample amount = 10 + rand*(10_000) From c3ee360757790df49d7ab092955ed2c0009f6c38 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Mon, 14 Oct 2013 16:27:55 -0500 Subject: [PATCH 13/35] added group test in gemfile --- Gemfile | 6 ++++++ Gemfile.lock | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Gemfile b/Gemfile index bd697e5..a8d12f9 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,12 @@ gem 'pry-rails' gem 'ruby-progressbar' +group :test do + gem 'rspec' + gem 'capybara' + gem 'factory_girl' +end + # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index f7a381a..0d1bb75 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,12 @@ 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) faker (1.2.0) i18n (~> 0.5) haml (4.0.3) @@ -73,8 +82,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) @@ -106,6 +118,14 @@ 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) ruby-progressbar (1.1.1) sass (3.2.9) sass-rails (4.0.0.rc1) @@ -143,13 +163,17 @@ 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 faker haml jbuilder (~> 1.0.1) @@ -160,6 +184,7 @@ DEPENDENCIES pry-doc pry-rails rails (= 4.0.0.rc1) + rspec ruby-progressbar sass-rails (~> 4.0.0.rc1) sdoc From 6580d9d398eff876f46e7b8c316ad9dd6fab675d Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Mon, 14 Oct 2013 16:52:54 -0500 Subject: [PATCH 14/35] added rspec-rails --- Gemfile | 1 + Gemfile.lock | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index a8d12f9..f8659ad 100644 --- a/Gemfile +++ b/Gemfile @@ -49,6 +49,7 @@ gem 'ruby-progressbar' group :test do gem 'rspec' + gem 'rspec-rails' gem 'capybara' gem 'factory_girl' end diff --git a/Gemfile.lock b/Gemfile.lock index 0d1bb75..7de74a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,6 +126,13 @@ GEM 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) @@ -185,6 +192,7 @@ DEPENDENCIES pry-rails rails (= 4.0.0.rc1) rspec + rspec-rails ruby-progressbar sass-rails (~> 4.0.0.rc1) sdoc From 1dc0c24b20f800d0a72dccb5748550de39878a6f Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 09:55:07 -0500 Subject: [PATCH 15/35] added some basic test --- spec/factories/account.rb | 39 +++++++++++++++++++++++++++++++++++++ spec/factories_spec.rb | 13 +++++++++++++ spec/models/account_spec.rb | 10 ++++++++++ spec/spec_helper.rb | 21 ++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 spec/factories/account.rb create mode 100644 spec/factories_spec.rb create mode 100644 spec/models/account_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/spec/factories/account.rb b/spec/factories/account.rb new file mode 100644 index 0000000..2249665 --- /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 Faker::Number.digit + pm_account_type Faker::Number.digit + display_order Faker::Number.digit + name Faker::Company.name + balance_overall Faker::Number.digit + balance_cleared Faker::Number.digit + 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 Faker::Number.digit + fixed_percent Faker::Number.digit + limit_amount Faker::Number.digit + limit boolean.sample + total_worth boolean.sample + exchange_rate Faker::Number.digit + currency_code currency.sample + last_sync_time Time.now + routing_number Faker::Number.digit + overdraft_account_id Faker::Number.digit + keep_the_change_account_id Faker::Number.digit + heek_change_round_to Faker::Number.digit + uuid Faker::Code.isbn(64) + 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/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..a7c3d62 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,21 @@ +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'rspec/autorun' + +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 From 5dfba288361d0d1f029d6f70ebf845eb918edeef Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 09:55:41 -0500 Subject: [PATCH 16/35] added rspec_rails --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index f8659ad..e8dc562 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ group :test do gem 'rspec-rails' gem 'capybara' gem 'factory_girl' + gem 'factory_girl_rails' end # Use ActiveModel has_secure_password From e34395a02c553bde51192a2d723231321ca9a0f6 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 11:06:47 -0500 Subject: [PATCH 17/35] added gems --- Gemfile.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 7de74a2..accc559 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,6 +59,9 @@ GEM 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) @@ -181,6 +184,7 @@ DEPENDENCIES capybara coffee-rails (~> 4.0.0) factory_girl + factory_girl_rails faker haml jbuilder (~> 1.0.1) From d6e7b0c5e416f7eb4d55608808744f193a175df9 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 16:24:22 -0500 Subject: [PATCH 18/35] added factories to create account, category, department, payee and transaction --- spec/factories/account.rb | 4 ++-- spec/factories/category.rb | 15 +++++++++++++++ spec/factories/department.rb | 11 +++++++++++ spec/factories/payee.rb | 13 +++++++++++++ spec/factories/transaction.rb | 31 +++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 spec/factories/category.rb create mode 100644 spec/factories/department.rb create mode 100644 spec/factories/payee.rb create mode 100644 spec/factories/transaction.rb diff --git a/spec/factories/account.rb b/spec/factories/account.rb index 2249665..b37cd23 100644 --- a/spec/factories/account.rb +++ b/spec/factories/account.rb @@ -5,8 +5,8 @@ FactoryGirl.define do factory :account do deleted false - pm_id Faker::Number.digit - pm_account_type Faker::Number.digit + pm_id (0..2).to_a.sample + pm_account_type (0..8).to_a.sample display_order Faker::Number.digit name Faker::Company.name balance_overall Faker::Number.digit 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..934c205 --- /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/transaction.rb b/spec/factories/transaction.rb new file mode 100644 index 0000000..6aef20f --- /dev/null +++ b/spec/factories/transaction.rb @@ -0,0 +1,31 @@ +require 'faker' + +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.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.id + category_id category.id + department_id department.id + amount Faker::Number.number(2) + cleared true + uuid Faker::Code.isbn + + end +end From 956346faa700d0934aba81b449741f730c0ba0f4 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 16:25:01 -0500 Subject: [PATCH 19/35] added test at models --- spec/models/category_spec.rb | 9 +++++++++ spec/models/department_spec.rb | 9 +++++++++ spec/models/payee_spec.rb | 9 +++++++++ spec/models/transaction_spec.rb | 9 +++++++++ 4 files changed, 36 insertions(+) create mode 100644 spec/models/category_spec.rb create mode 100644 spec/models/department_spec.rb create mode 100644 spec/models/payee_spec.rb create mode 100644 spec/models/transaction_spec.rb 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/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 From 54d323731c5b18138c304105b54da9f25a0a733f Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 16:39:34 -0500 Subject: [PATCH 20/35] refactored seed in create transactions --- db/seeds.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 455ee5a..7fd3892 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -65,22 +65,19 @@ ) end -account_all = Account.all.map(&:id) -payee_all = Payee.all.map(&:id) 30.times do - - account = account_all.sample + payee = Payee.all.sample + account = Account.all.sample amount = 10 + rand*(10_000) - payee = payee_all.sample #seed to transaction table Transaction.create( pm_type: rand(0..2), pm_id: rand(0..8), - account_id: account, - pm_account_id: account, - pm_payee: Payee.find(payee).name, + 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", @@ -88,8 +85,8 @@ date: Time.now - rand(0..60).days, deleted: boolean.sample, check_number: rand(10).to_s, - payee_name: Payee.find(payee).name, - payee_id: payee, + payee_name: payee.name, + payee_id: payee.id, category_id: Category.all.map(&:id).sample, department_id: Department.all.map(&:id).sample, amount: amount, From 983d984b0e78947916d8bdf6b3ec5bb5944b2bd6 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 16:40:43 -0500 Subject: [PATCH 21/35] increased number of seeds --- db/seeds.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 7fd3892..34aafb4 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ 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 -10.times do +15.times do Account.create( deleted: false, pm_id: rand(0..8), @@ -66,7 +66,7 @@ end -30.times do +40.times do payee = Payee.all.sample account = Account.all.sample amount = 10 + rand*(10_000) From 1b37b74f75c49fba6508755fa0007a1adbbba0f9 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Tue, 15 Oct 2013 18:50:29 -0500 Subject: [PATCH 22/35] added factories and refactored factory to account --- Gemfile | 3 +-- spec/factories/account.rb | 24 ++++++++++++------------ spec/factories/split.rb | 20 ++++++++++++++++++++ spec/factories/transaction.rb | 16 ++++++++-------- spec/factories_spec.rb | 1 + spec/models/split_spec.rb | 10 ++++++++++ 6 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 spec/factories/split.rb create mode 100644 spec/models/split_spec.rb diff --git a/Gemfile b/Gemfile index e8dc562..eb59ee3 100644 --- a/Gemfile +++ b/Gemfile @@ -52,9 +52,8 @@ group :test do gem 'rspec-rails' gem 'capybara' gem 'factory_girl' - gem 'factory_girl_rails' end - +gem 'factory_girl_rails' # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/spec/factories/account.rb b/spec/factories/account.rb index b37cd23..f52af00 100644 --- a/spec/factories/account.rb +++ b/spec/factories/account.rb @@ -7,33 +7,33 @@ deleted false pm_id (0..2).to_a.sample pm_account_type (0..8).to_a.sample - display_order Faker::Number.digit + display_order (1..9).to_a.sample name Faker::Company.name - balance_overall Faker::Number.digit - balance_cleared Faker::Number.digit + 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 Faker::Number.digit + 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 Faker::Number.digit - fixed_percent Faker::Number.digit - limit_amount Faker::Number.digit + 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 Faker::Number.digit + exchange_rate (1..9).to_a.sample currency_code currency.sample last_sync_time Time.now - routing_number Faker::Number.digit - overdraft_account_id Faker::Number.digit - keep_the_change_account_id Faker::Number.digit - heek_change_round_to Faker::Number.digit + 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/split.rb b/spec/factories/split.rb new file mode 100644 index 0000000..68fa4c8 --- /dev/null +++ b/spec/factories/split.rb @@ -0,0 +1,20 @@ +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 + x_of_id "dummy" + end +end + + diff --git a/spec/factories/transaction.rb b/spec/factories/transaction.rb index 6aef20f..4d80912 100644 --- a/spec/factories/transaction.rb +++ b/spec/factories/transaction.rb @@ -1,18 +1,18 @@ require 'faker' -account = FactoryGirl.create(:account) -payee = FactoryGirl.create(:payee) -department = FactoryGirl.create(:department) -category = FactoryGirl.create(:category) +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.id + pm_account_id account.pm_id pm_payee payee.name - pm_sub_total (10..10_000).to_a.sample + 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 @@ -20,12 +20,12 @@ deleted false check_number (1..10).to_a.sample payee_name payee.name - payee_id payee.id + 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 + diff --git a/spec/factories_spec.rb b/spec/factories_spec.rb index d2e7753..83a1c36 100644 --- a/spec/factories_spec.rb +++ b/spec/factories_spec.rb @@ -2,6 +2,7 @@ describe 'validate FactoryGirl factories' do FactoryGirl.factories.each do |factory| context "with factory for: #{factory.name}" do + #binding.pry subject { FactoryGirl.build(factory.name) } it "is valid" do diff --git a/spec/models/split_spec.rb b/spec/models/split_spec.rb new file mode 100644 index 0000000..b957b06 --- /dev/null +++ b/spec/models/split_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Split do + let(:split) {create(:account)} + + it "has a valid split" do + split.should be_valid + end +end + From 20d6ebc585743a3d6980ab4d591a1dd3f58445cf Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 11:07:57 -0500 Subject: [PATCH 23/35] change factory split at transaction factory file --- spec/factories/payee.rb | 2 +- spec/factories/split.rb | 36 +++++++++++++++++------------------ spec/factories/transaction.rb | 19 ++++++++++++++++++ spec/factories_spec.rb | 1 - spec/models/split_spec.rb | 2 +- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/spec/factories/payee.rb b/spec/factories/payee.rb index 934c205..e967919 100644 --- a/spec/factories/payee.rb +++ b/spec/factories/payee.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :payee do - name Faker::Name.name + name Faker::Name.name deleted false pm_id (0..8).to_a.sample latitude Faker::Address.latitude diff --git a/spec/factories/split.rb b/spec/factories/split.rb index 68fa4c8..41e5390 100644 --- a/spec/factories/split.rb +++ b/spec/factories/split.rb @@ -1,20 +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 - x_of_id "dummy" - end -end - +#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 index 4d80912..60afb1a 100644 --- a/spec/factories/transaction.rb +++ b/spec/factories/transaction.rb @@ -1,10 +1,12 @@ 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 @@ -29,3 +31,20 @@ 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 index 83a1c36..d2e7753 100644 --- a/spec/factories_spec.rb +++ b/spec/factories_spec.rb @@ -2,7 +2,6 @@ describe 'validate FactoryGirl factories' do FactoryGirl.factories.each do |factory| context "with factory for: #{factory.name}" do - #binding.pry subject { FactoryGirl.build(factory.name) } it "is valid" do diff --git a/spec/models/split_spec.rb b/spec/models/split_spec.rb index b957b06..edb1ab6 100644 --- a/spec/models/split_spec.rb +++ b/spec/models/split_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Split do - let(:split) {create(:account)} + let(:split) {create(:split)} it "has a valid split" do split.should be_valid From 7a0a2016538dca8481bad4bd3f4ea373d1868224 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 12:30:38 -0500 Subject: [PATCH 24/35] created spec/controllers folder and test to index in TransactionsController --- spec/controllers/transactions_controller_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/controllers/transactions_controller_spec.rb diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb new file mode 100644 index 0000000..3943e69 --- /dev/null +++ b/spec/controllers/transactions_controller_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' +describe TransactionsController do + describe "Get index" do + it "render the index templates" do + get :index + expect(response).to render_template("index") + end + end +end From 4de84e7cfc14b68b7957320b9022f9c74502b0ff Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 13:20:45 -0500 Subject: [PATCH 25/35] added test to get methods --- .../transactions_controller_spec.rb | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index 3943e69..4692cee 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -1,9 +1,37 @@ require 'spec_helper' describe TransactionsController do + let(:transaction) { create(:transaction) } + #spec to GET methods describe "Get index" do - it "render the index templates" 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 end From 655229b04d0e643aff2fe0dcc4ec0dd8d4834a76 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 13:24:29 -0500 Subject: [PATCH 26/35] completed get methods --- spec/controllers/transactions_controller_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index 4692cee..a8519e7 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -34,4 +34,16 @@ 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 + end From e19f6506ea5295c7c100212155cd5c23674bb0d8 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 15:05:58 -0500 Subject: [PATCH 27/35] add test to create method --- spec/controllers/transactions_controller_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index a8519e7..20b0d9d 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -45,5 +45,17 @@ response.should be_success end end + #spec to post methods + describe 'POST #create' 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 end From 70d7aa998494d6f3db5e5344fa76049429cb2a7e Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 15:20:04 -0500 Subject: [PATCH 28/35] added vadilation of presece to transaction model in amount and account_id --- app/models/transaction.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/transaction.rb b/app/models/transaction.rb index f817a05..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 From 55dd014ca12c94b24f7c28e89d028e0705803580 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 15:20:35 -0500 Subject: [PATCH 29/35] added test to create method --- spec/controllers/transactions_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index 20b0d9d..eab83a2 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -47,6 +47,7 @@ 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) @@ -56,6 +57,19 @@ 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 end From f92bf63c78c3300b922aa19936f7436ba630ec8e Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Wed, 16 Oct 2013 18:24:45 -0500 Subject: [PATCH 30/35] added tests to transactions controller in put method --- Gemfile | 3 +- .../transactions_controller_spec.rb | 39 +++++++++++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index eb59ee3..e8dc562 100644 --- a/Gemfile +++ b/Gemfile @@ -52,8 +52,9 @@ group :test do gem 'rspec-rails' gem 'capybara' gem 'factory_girl' + gem 'factory_girl_rails' end -gem 'factory_girl_rails' + # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index eab83a2..037f4a5 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -72,4 +72,43 @@ 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/spec_helper.rb b/spec/spec_helper.rb index a7c3d62..dc2c0d4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ 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 } From 5a41e123d7afb1861eb4690b015dbbae25bc26a5 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 15:57:51 -0500 Subject: [PATCH 31/35] uncommented require pocket_money --- config/initializers/pocket_money.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/pocket_money.rb b/config/initializers/pocket_money.rb index 37ad7c4..d147d71 100644 --- a/config/initializers/pocket_money.rb +++ b/config/initializers/pocket_money.rb @@ -1 +1 @@ -#require 'pocket_money' +require 'pocket_money' From e9198fbb23a160192ad166a152ffd2cebb6c6b88 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 15:58:43 -0500 Subject: [PATCH 32/35] ignored my database --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3c557dfc9c83c4c314daa34b42ca3f58ea0d5a03 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Thu, 17 Oct 2013 16:00:45 -0500 Subject: [PATCH 33/35] reverted change in category_name --- app/views/transactions/_transaction.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/transactions/_transaction.haml b/app/views/transactions/_transaction.haml index 76a66b7..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_id + %td= transaction.category_name %td.currency= money transaction.amount - if show_balance From e72feb92bc70263ba45561a2c4bdf2f07f024ba9 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Fri, 18 Oct 2013 11:52:33 -0500 Subject: [PATCH 34/35] added validation to enviroment diferent to test --- config/initializers/pocket_money.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' From eeafc9de3e0c2b7f8397e9ae3b506a189cd1be68 Mon Sep 17 00:00:00 2001 From: Jesus Romero Date: Fri, 18 Oct 2013 11:58:10 -0500 Subject: [PATCH 35/35] added validation to enviroment diferent to test --- config/initializers/pocket_money.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'