mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 12:17:30 +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
|
||||
|
|
27
app/interactions/actions/account_activity_create.rb
Normal file
27
app/interactions/actions/account_activity_create.rb
Normal 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
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue