2024-07-25 16:46:04 -04:00
|
|
|
require "test_helper"
|
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
class HoldingsControllerTest < ActionDispatch::IntegrationTest
|
2024-07-25 16:46:04 -04:00
|
|
|
setup do
|
|
|
|
sign_in users(:family_admin)
|
|
|
|
@account = accounts(:investment)
|
2024-12-12 08:56:52 -05:00
|
|
|
@holding = @account.holdings.first
|
2024-07-25 16:46:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "gets holdings" do
|
2025-04-14 11:40:34 -04:00
|
|
|
get holdings_url(account_id: @account.id)
|
2024-07-25 16:46:04 -04:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "gets holding" do
|
2025-04-14 11:40:34 -04:00
|
|
|
get holding_path(@holding)
|
2024-07-25 16:46:04 -04:00
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
end
|
2024-10-09 14:59:18 -04:00
|
|
|
|
|
|
|
test "destroys holding and associated entries" do
|
2025-04-14 11:40:34 -04:00
|
|
|
assert_difference -> { Holding.count } => -1,
|
|
|
|
-> { Entry.count } => -1 do
|
|
|
|
delete holding_path(@holding)
|
2024-10-09 14:59:18 -04:00
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
assert_redirected_to account_path(@holding.account)
|
|
|
|
assert_empty @holding.account.entries.where(entryable: @holding.account.trades.where(security: @holding.security))
|
2024-10-09 14:59:18 -04:00
|
|
|
end
|
2024-07-25 16:46:04 -04:00
|
|
|
end
|