mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Use Current association in AccountsController and add tests (#298)
* Add PagesControllerTest with authentication * Rubocop fixes * Move sign_in to setup block * Remove instance variable * Add tests for AccountsController * Use specific account
This commit is contained in:
parent
fb7411e163
commit
1cded2af90
2 changed files with 26 additions and 1 deletions
|
@ -17,7 +17,7 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@account = Account.new(account_params.merge(family: Current.family))
|
||||
@account = Current.family.accounts.build(account_params)
|
||||
@account.accountable = account_params[:accountable_type].constantize.new
|
||||
|
||||
if @account.save
|
||||
|
|
25
test/controllers/accounts_controller_test.rb
Normal file
25
test/controllers/accounts_controller_test.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require "test_helper"
|
||||
|
||||
class AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in @user = users(:bob)
|
||||
@account = accounts(:dylan_checking)
|
||||
end
|
||||
|
||||
test "new" do
|
||||
get new_account_path
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
test "show" do
|
||||
get account_path(@account)
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
test "create" do
|
||||
assert_difference -> { Account.count }, +1 do
|
||||
post accounts_path, params: { account: { accountable_type: "Account::Credit" } }
|
||||
assert_redirected_to accounts_url
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue