mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
test fixed, controller refactored
This commit is contained in:
parent
48555c23b6
commit
83b9c58ad3
3 changed files with 37 additions and 16 deletions
|
@ -17,7 +17,16 @@ module Admin
|
|||
def update
|
||||
if @account.valid?
|
||||
@sum = params[:account][:balance].to_f - @account.balance
|
||||
redirect_to admin_accounts_path, notice: t('.updated') if create_activity
|
||||
action = Actions::AccountActivityCreate.new(@account,
|
||||
@sum,
|
||||
params[:description],
|
||||
AccountActivity::UPDATE_CREDIT)
|
||||
|
||||
unless action.call
|
||||
handle_errors(@account)
|
||||
render 'edit'
|
||||
end
|
||||
redirect_to admin_accounts_path, notice: t('.updated')
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
|
@ -25,20 +34,6 @@ module Admin
|
|||
|
||||
private
|
||||
|
||||
def create_activity
|
||||
activity = AccountActivity.new(account: @account,
|
||||
sum: @sum,
|
||||
currency: @account.currency,
|
||||
description: params[:description],
|
||||
activity_type: AccountActivity::UPDATE_CREDIT)
|
||||
|
||||
if activity.save
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def account_params
|
||||
params.require(:account).permit(:id, :currency, :balance)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue