Permalink
Browse files

rename column name type to transaction_type. update all required refe…

…rences
  • Loading branch information...
1 parent be48599 commit cee23bb6c4fcd3b8dac061f078f6f9c0a0d0a1e4 @pragashonlink pragashonlink committed May 2, 2012
@@ -1,23 +1,23 @@
class TransactionsController < ApplicationController
def transfer
params[:info] = "receiver: #{params[:to_user_id]}\ntransferer: #{params[:user_id]}"
- params[:type] = "TF"
+ params[:transaction_type] = "TF"
binding.pry
respond_to do |format|
format.html { render :json => Transaction.process_transaction(params)}
end
end
def add
- params[:type] = "AC"
+ params[:transaction_type] = "AC"
respond_to do |format|
format.html { render :json => Transaction.process_transaction(params)}
end
end
def deduct
- params[:type] = "DC"
+ params[:transaction_type] = "DC"
respond_to do |format|
format.html { render :json => Transaction.process_transaction(params)}
@@ -22,10 +22,8 @@ class Transaction < ActiveRecord::Base
#callbacks
before_save :set_user_id, :if => :transfer?
- scope :user_fund, lambda do |u_id|
- where("user_id = ?", u_id)
- end
-
+ scope :user_fund, lambda { |u_id| where("user_id = ?", u_id) }
+
private
def set_user_id
@@ -37,7 +35,7 @@ def transfer?
end
def validation
- self.errors.add :fund, "200" if self.type == "TF" &&
+ self.errors.add :fund, "200" if self.transaction_type == "TF" &&
self.fund &&
self.operation == "deduct" &&
!self.fund_available?
@@ -13,14 +13,14 @@ def process_transaction(params)
deduct = nil
add = nil
- if params[:type] == "TF"
+ if params[:transaction_type] == "TF"
Transaction.transaction do
deduct = deduct_credit(params)
add = add_credit(params)
end
- elsif params[:type] == "AC"
+ elsif params[:transaction_type] == "AC"
add = add_credit(params)
- elsif params[:type] == "DC"
+ elsif params[:transaction_type] == "DC"
deduct = deduct_credit(params)
end
@@ -31,7 +31,7 @@ def add_credit(params)
receiver = Transaction.new() do |r|
r.user_id = params[:to_user_id] ||= params[:user_id]
r.account_id = ActsAsTenant.current_tenant.id
- r.type = params[:type]
+ r.transaction_type = params[:transaction_type]
r.info = params[:info]
r.fund = params[:fund]
r.operation = "add"
@@ -45,7 +45,7 @@ def deduct_credit(params)
deducter = Transaction.new() do |r|
r.user_id = params[:user_id]
r.account_id = ActsAsTenant.current_tenant.id
- r.type = params[:type]
+ r.transaction_type = params[:transaction_type]
r.info = params[:info]
r.fund = "-#{params[:fund]}".to_f
r.operation = "deduct"
@@ -2,21 +2,21 @@
class TransactionTest < ActiveSupport::TestCase
- # def test_successful_fund_transfer
- # load_fixtures_to_db
+ def test_successful_fund_transfer
+ load_fixtures_to_db
- # ActsAsTenant.current_tenant = accounts(:aightify)
+ ActsAsTenant.current_tenant = accounts(:aightify)
- # params = {}
- # params[:user_id] = users(:pragash).id
- # params[:to_user_id] = users(:mathu).id
- # params[:fund] = 100
- # params[:currency] = "POUND"
- # params[:info] = "receiver: #{params[:to_user_id]}\ntransferer: #{params[:user_id]}"
- # params[:type] = "TF"
+ params = {}
+ params[:user_id] = users(:pragash).id
+ params[:to_user_id] = users(:mathu).id
+ params[:fund] = 100
+ params[:currency] = "POUND"
+ params[:info] = "receiver: #{params[:to_user_id]}\ntransferer: #{params[:user_id]}"
+ params[:transaction_type] = "TF"
- # assert_equal Transaction.process_transaction(params).length, 0
- # end
+ assert_equal Transaction.process_transaction(params).length, 0
+ end
def test_un_successful_fund_transfer
load_fixtures_to_db
@@ -33,64 +33,64 @@ def test_un_successful_fund_transfer
assert_equal Transaction.process_transaction(params).length, 4
end
- # def test_successful_add_credit
- # load_fixtures_to_db
+ def test_successful_add_credit
+ load_fixtures_to_db
- # ActsAsTenant.current_tenant = accounts(:aightify)
+ ActsAsTenant.current_tenant = accounts(:aightify)
- # params = {}
- # params[:user_id] = 1
- # params[:fund] = 100
- # params[:currency] = "POUND"
- # params[:info] = "receiver: #{params[:user_id]}"
- # params[:type] = "AC"
+ params = {}
+ params[:user_id] = 1
+ params[:fund] = 100
+ params[:currency] = "POUND"
+ params[:info] = "receiver: #{params[:user_id]}"
+ params[:transaction_type] = "AC"
- # assert_equal Transaction.process_transaction(params).length, 0
- # end
+ assert_equal Transaction.process_transaction(params).length, 0
+ end
- # def test_un_successful_add_credit
- # load_fixtures_to_db
+ def test_un_successful_add_credit
+ load_fixtures_to_db
- # ActsAsTenant.current_tenant = accounts(:aightify)
+ ActsAsTenant.current_tenant = accounts(:aightify)
- # params = {}
- # params[:user_id] = 90
- # params[:cash] = 100
- # params[:currency] = "POUND"
- # params[:info] = "receiver: #{params[:user_id]}"
- # params[:type] = "AC"
+ params = {}
+ params[:user_id] = 90
+ params[:cash] = 100
+ params[:currency] = "POUND"
+ params[:info] = "receiver: #{params[:user_id]}"
+ params[:transaction_type] = "AC"
- # assert_equal Transaction.process_transaction(params).length, 2
- # end
+ assert_equal Transaction.process_transaction(params).length, 2
+ end
- # def test_successful_deduct_credit
- # load_fixtures_to_db
+ def test_successful_deduct_credit
+ load_fixtures_to_db
- # ActsAsTenant.current_tenant = accounts(:aightify)
+ ActsAsTenant.current_tenant = accounts(:aightify)
- # params = {}
- # params[:user_id] = 1
- # params[:fund] = 100
- # params[:currency] = "POUND"
- # params[:info] = "receiver: #{params[:user_id]}"
- # params[:type] = "DC"
+ params = {}
+ params[:user_id] = 1
+ params[:fund] = 100
+ params[:currency] = "POUND"
+ params[:info] = "receiver: #{params[:user_id]}"
+ params[:transaction_type] = "DC"
- # assert_equal Transaction.process_transaction(params).length, 0
- # end
+ assert_equal Transaction.process_transaction(params).length, 0
+ end
- # def test_un_successful_deduct_credit
- # load_fixtures_to_db
+ def test_un_successful_deduct_credit
+ load_fixtures_to_db
- # ActsAsTenant.current_tenant = accounts(:aightify)
+ ActsAsTenant.current_tenant = accounts(:aightify)
- # params = {}
- # params[:user_id] = 9
- # params[:cash] = 100
- # params[:currency] = "POUND"
- # params[:info] = "receiver: #{params[:user_id]}"
- # params[:type] = "DC"
+ params = {}
+ params[:user_id] = 9
+ params[:cash] = 100
+ params[:currency] = "POUND"
+ params[:info] = "receiver: #{params[:user_id]}"
+ params[:transaction_type] = "DC"
- # assert_equal Transaction.process_transaction(params).length, 1
- # end
+ assert_equal Transaction.process_transaction(params).length, 1
+ end
end

0 comments on commit cee23bb

Please sign in to comment.