Skip to content

Commit

Permalink
[Fix #301] Revert fund_source to fund_source_id.
Browse files Browse the repository at this point in the history
  • Loading branch information
k1T4eR committed Feb 2, 2018
1 parent 0e79cba commit f21a43b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions app/api/api_v2/withdraws.rb
Expand Up @@ -61,10 +61,10 @@ class Withdraws < Grape::API
post '/withdraws' do
currency = Currency.find_by_code(params[:currency].downcase)
withdraw = "withdraws/#{currency.key}".camelize.constantize.new \
fund_source: params[:address_id],
sum: params[:amount],
member_id: current_user.id,
currency: currency.code
fund_source_id: params[:address_id],
sum: params[:amount],
member_id: current_user.id,
currency: currency.code

if withdraw.save
withdraw.submit!
Expand Down
Expand Up @@ -44,7 +44,7 @@ app.controller 'WithdrawsController', ['$scope', '$stateParams', '$http', '$gon'
@createWithdraw = (currency) ->
withdraw_channel = WithdrawChannel.findBy('currency', currency)
account = withdraw_channel.account()
data = { withdraw: { member_id: current_user.id, currency: currency, sum: @withdraw.sum, fund_source: _selectedFundSourceId } }
data = { withdraw: { member_id: current_user.id, currency: currency, sum: @withdraw.sum, fund_source_id: _selectedFundSourceId } }

$('.form-submit > input').attr('disabled', 'disabled')

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/concerns/withdraws/withdrawable.rb
Expand Up @@ -29,16 +29,16 @@ def destroy
private

def fetch
@account = current_user.get_account(channel.currency)
@model = model_kls
@account = current_user.get_account(channel.currency)
@model = model_kls
@fund_sources = current_user.fund_sources.with_currency(channel.currency)
@assets = model_kls.without_aasm_state(:submitting).where(member: current_user).order(:id).reverse_order.limit(10)
@assets = model_kls.without_aasm_state(:submitting).where(member: current_user).order(:id).reverse_order.limit(10)
end

def withdraw_params
params[:withdraw][:currency] = channel.currency
params[:withdraw][:currency] = channel.currency
params[:withdraw][:member_id] = current_user.id
params.require(:withdraw).permit(:fund_source, :member_id, :currency, :sum)
params.require(:withdraw).permit(:fund_source_id, :member_id, :currency, :sum)
end

end
Expand Down
6 changes: 3 additions & 3 deletions app/models/concerns/fund_sourceable.rb
Expand Up @@ -2,13 +2,13 @@ module FundSourceable
extend ActiveSupport::Concern

included do
attr_accessor :fund_source
attr_accessor :fund_source_id
before_validation :set_fund_source_attributes, on: :create
validates :fund_source, presence: true, on: :create
validates :fund_source_id, presence: true, on: :create
end

def set_fund_source_attributes
if fs = FundSource.find_by(id: fund_source)
if fs = FundSource.find_by(id: fund_source_id)
self.fund_extra = fs.extra
self.fund_uid = fs.uid.strip
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/withdraw.rb
Expand Up @@ -3,7 +3,7 @@
sum { 10.to_d }
currency :btc
member { create :member }
fund_source { create(:btc_fund_source) }
fund_source_id { create(:btc_fund_source).id }
type 'Withdraws::Satoshi'

account do
Expand All @@ -30,7 +30,7 @@
member { create :member }
currency :usd
sum { 1000.to_d }
fund_source { create(:usd_fund_source) }
fund_source_id { create(:usd_fund_source).id }
type 'Withdraws::Bank'

account do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/withdraw_spec.rb
Expand Up @@ -9,7 +9,7 @@
context 'fund source' do
it 'should strip trailing spaces in fund_uid' do
fund_source = create(:btc_fund_source, uid: 'test')
@withdraw = create(:satoshi_withdraw, fund_source: fund_source)
@withdraw = create(:satoshi_withdraw, fund_source_id: fund_source.id)
expect(@withdraw.fund_uid).to eq('test')
end
end
Expand Down

0 comments on commit f21a43b

Please sign in to comment.