diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index 2759ebfd3..a749f948f 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -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 diff --git a/app/interactions/actions/account_activity_create.rb b/app/interactions/actions/account_activity_create.rb new file mode 100644 index 000000000..41b351fbe --- /dev/null +++ b/app/interactions/actions/account_activity_create.rb @@ -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 diff --git a/test/system/admin_area/accounts_test.rb b/test/system/admin_area/accounts_test.rb index 1316e63b6..f07ced9c3 100644 --- a/test/system/admin_area/accounts_test.rb +++ b/test/system/admin_area/accounts_test.rb @@ -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'