Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Use Current association in AccountsController and add tests (#298)

Dwight Watson1cded2af903d
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 814a8854..035a8330 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -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
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
new file mode 100644
index 00000000..f2e4d7f5
--- /dev/null
+++ b/test/controllers/accounts_controller_test.rb
@@ -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