From 766dca79e7f21d50c06f6e4e0fe192354348728a Mon Sep 17 00:00:00 2001 From: Us Dmitry Date: Fri, 2 Feb 2018 23:03:43 +0200 Subject: [PATCH] [Fix #301] Revert fund_source to fund_source_id. (#365) --- app/api/api_v2/withdraws.rb | 8 ++++---- .../funds/controllers/withdraws_controller.js.coffee | 2 +- app/controllers/concerns/withdraws/withdrawable.rb | 10 +++++----- app/models/concerns/fund_sourceable.rb | 6 +++--- spec/factories/withdraw.rb | 4 ++-- spec/models/withdraw_spec.rb | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/api/api_v2/withdraws.rb b/app/api/api_v2/withdraws.rb index a71e4c1ee3..1cb64beae7 100644 --- a/app/api/api_v2/withdraws.rb +++ b/app/api/api_v2/withdraws.rb @@ -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! diff --git a/app/assets/javascripts/funds/controllers/withdraws_controller.js.coffee b/app/assets/javascripts/funds/controllers/withdraws_controller.js.coffee index 75fa4bdb6d..48fefae855 100644 --- a/app/assets/javascripts/funds/controllers/withdraws_controller.js.coffee +++ b/app/assets/javascripts/funds/controllers/withdraws_controller.js.coffee @@ -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') diff --git a/app/controllers/concerns/withdraws/withdrawable.rb b/app/controllers/concerns/withdraws/withdrawable.rb index 662aec5ca8..07d21f0b1b 100644 --- a/app/controllers/concerns/withdraws/withdrawable.rb +++ b/app/controllers/concerns/withdraws/withdrawable.rb @@ -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 diff --git a/app/models/concerns/fund_sourceable.rb b/app/models/concerns/fund_sourceable.rb index d31d90903c..76c0f4634f 100644 --- a/app/models/concerns/fund_sourceable.rb +++ b/app/models/concerns/fund_sourceable.rb @@ -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 diff --git a/spec/factories/withdraw.rb b/spec/factories/withdraw.rb index 0dd7a77172..94688a25e5 100644 --- a/spec/factories/withdraw.rb +++ b/spec/factories/withdraw.rb @@ -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 @@ -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 diff --git a/spec/models/withdraw_spec.rb b/spec/models/withdraw_spec.rb index b54df9256b..09b97bf523 100644 --- a/spec/models/withdraw_spec.rb +++ b/spec/models/withdraw_spec.rb @@ -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