test fixed, controller refactored

This commit is contained in:
dinsmol 2021-08-23 09:11:41 +03:00
parent 48555c23b6
commit 83b9c58ad3
3 changed files with 37 additions and 16 deletions

View file

@ -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

View file

@ -0,0 +1,27 @@
module Actions
class AccountActivityCreate
def initialize(account, sum, description, type)
@account = account
@sum = sum
@description = description
@type = type
end
def call
create_activity
commit
end
def create_activity
@activity = AccountActivity.new(account: @account,
sum: @sum,
currency: @account.currency,
description: @description,
activity_type: @type)
end
def commit
@activity.save!
end
end
end

View file

@ -20,7 +20,6 @@ class AdminAccountsSystemTest < ApplicationSystemTestCase
end
def test_change_account_balance
puts @account.inspect
visit edit_admin_account_path(@account)
assert_button 'Save'
assert_field 'Balance'