mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Vehicle view (#1117)
This commit is contained in:
parent
e856691c86
commit
359bceb58e
15 changed files with 259 additions and 8 deletions
71
test/controllers/vehicles_controller_test.rb
Normal file
71
test/controllers/vehicles_controller_test.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
require "test_helper"
|
||||
|
||||
class VehiclesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
@account = accounts(:vehicle)
|
||||
end
|
||||
|
||||
test "creates vehicle" do
|
||||
assert_difference -> { Account.count } => 1,
|
||||
-> { Vehicle.count } => 1,
|
||||
-> { Account::Valuation.count } => 2,
|
||||
-> { Account::Entry.count } => 2 do
|
||||
post vehicles_path, params: {
|
||||
account: {
|
||||
name: "Vehicle",
|
||||
balance: 30000,
|
||||
currency: "USD",
|
||||
accountable_type: "Vehicle",
|
||||
start_date: 1.year.ago.to_date,
|
||||
start_balance: 35000,
|
||||
accountable_attributes: {
|
||||
make: "Toyota",
|
||||
model: "Camry",
|
||||
year: 2020,
|
||||
mileage_value: 15000,
|
||||
mileage_unit: "mi"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_account = Account.order(:created_at).last
|
||||
|
||||
assert_equal "Toyota", created_account.vehicle.make
|
||||
assert_equal "Camry", created_account.vehicle.model
|
||||
assert_equal 2020, created_account.vehicle.year
|
||||
assert_equal 15000, created_account.vehicle.mileage_value
|
||||
assert_equal "mi", created_account.vehicle.mileage_unit
|
||||
|
||||
assert_redirected_to account_path(created_account)
|
||||
assert_equal "Vehicle created successfully", flash[:notice]
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
|
||||
test "updates vehicle" do
|
||||
assert_no_difference [ "Account.count", "Vehicle.count", "Account::Valuation.count", "Account::Entry.count" ] do
|
||||
patch vehicle_path(@account), params: {
|
||||
account: {
|
||||
name: "Updated Vehicle",
|
||||
balance: 28000,
|
||||
currency: "USD",
|
||||
accountable_type: "Vehicle",
|
||||
accountable_attributes: {
|
||||
id: @account.accountable_id,
|
||||
make: "Honda",
|
||||
model: "Accord",
|
||||
year: 2021,
|
||||
mileage_value: 20000,
|
||||
mileage_unit: "mi",
|
||||
purchase_price: 32000
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_path(@account)
|
||||
assert_equal "Vehicle updated successfully", flash[:notice]
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
end
|
|
@ -34,7 +34,12 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
test "can create vehicle account" do
|
||||
assert_account_created("Vehicle")
|
||||
assert_account_created "Vehicle" do
|
||||
fill_in "Make", with: "Toyota"
|
||||
fill_in "Model", with: "Camry"
|
||||
fill_in "Year", with: "2020"
|
||||
fill_in "Mileage", with: "30000"
|
||||
end
|
||||
end
|
||||
|
||||
test "can create other asset account" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue