Skip to content

Commit

Permalink
Use Current association in AccountsController and add tests (#298)
Browse files Browse the repository at this point in the history
* Add PagesControllerTest with authentication

* Rubocop fixes

* Move sign_in to setup block

* Remove instance variable

* Add tests for AccountsController

* Use specific account
  • Loading branch information
dwightwatson authored Feb 5, 2024
1 parent fb7411e commit 1cded2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def show
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
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/accounts_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1cded2a

Please sign in to comment.