mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Add Property Details View (#1116)
* Add backend for property account details
* Rubocop updates
* Add property form with details
* Revert "Rubocop updates"
This reverts commit 05b0b8f3a4
.
* Bump brakeman to latest version
* Add overview section to property view
* Lint fixes
This commit is contained in:
parent
4433488562
commit
e856691c86
30 changed files with 547 additions and 81 deletions
79
test/controllers/properties_controller_test.rb
Normal file
79
test/controllers/properties_controller_test.rb
Normal file
|
@ -0,0 +1,79 @@
|
|||
require "test_helper"
|
||||
|
||||
class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
@account = accounts(:property)
|
||||
end
|
||||
|
||||
test "creates property" do
|
||||
assert_difference -> { Account.count } => 1,
|
||||
-> { Property.count } => 1,
|
||||
-> { Account::Valuation.count } => 2,
|
||||
-> { Account::Entry.count } => 2 do
|
||||
post properties_path, params: {
|
||||
account: {
|
||||
name: "Property",
|
||||
balance: 500000,
|
||||
currency: "USD",
|
||||
accountable_type: "Property",
|
||||
start_date: 3.years.ago.to_date,
|
||||
start_balance: 450000,
|
||||
accountable_attributes: {
|
||||
year_built: 2002,
|
||||
area_value: 1000,
|
||||
area_unit: "sqft",
|
||||
address_attributes: {
|
||||
line1: "123 Main St",
|
||||
line2: "Apt 1",
|
||||
locality: "Los Angeles",
|
||||
region: "CA", # ISO3166-2 code
|
||||
country: "US", # ISO3166-1 Alpha-2 code
|
||||
postal_code: "90001"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_account = Account.order(:created_at).last
|
||||
|
||||
assert created_account.property.year_built.present?
|
||||
assert created_account.property.address.line1.present?
|
||||
|
||||
assert_redirected_to account_path(created_account)
|
||||
assert_equal "Property created successfully", flash[:notice]
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
|
||||
test "updates property" do
|
||||
assert_no_difference [ "Account.count", "Property.count", "Account::Valuation.count", "Account::Entry.count" ] do
|
||||
patch property_path(@account), params: {
|
||||
account: {
|
||||
name: "Updated Property",
|
||||
balance: 500000,
|
||||
currency: "USD",
|
||||
accountable_type: "Property",
|
||||
accountable_attributes: {
|
||||
id: @account.accountable_id,
|
||||
year_built: 2002,
|
||||
area_value: 1000,
|
||||
area_unit: "sqft",
|
||||
address_attributes: {
|
||||
line1: "123 Main St",
|
||||
line2: "Apt 1",
|
||||
locality: "Los Angeles",
|
||||
region: "CA", # ISO3166-2 code
|
||||
country: "US", # ISO3166-1 Alpha-2 code
|
||||
postal_code: "90001"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_path(@account)
|
||||
assert_equal "Property updated successfully", flash[:notice]
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
end
|
9
test/fixtures/addresses.yml
vendored
Normal file
9
test/fixtures/addresses.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
one:
|
||||
line1: 123 Main Street
|
||||
line2: Apt 4B
|
||||
locality: Los Angeles
|
||||
region: CA
|
||||
country: US
|
||||
postal_code: 90001
|
||||
addressable: one
|
||||
addressable_type: Property
|
5
test/fixtures/properties.yml
vendored
5
test/fixtures/properties.yml
vendored
|
@ -1 +1,4 @@
|
|||
one: { }
|
||||
one:
|
||||
year_built: 2002
|
||||
area_value: 1000
|
||||
area_unit: "sqft"
|
15
test/models/address_test.rb
Normal file
15
test/models/address_test.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require "test_helper"
|
||||
|
||||
class AddressTest < ActiveSupport::TestCase
|
||||
test "can print a formatted address" do
|
||||
address = Address.new(
|
||||
line1: "123 Main St",
|
||||
locality: "San Francisco",
|
||||
region: "CA",
|
||||
country: "US",
|
||||
postal_code: "94101"
|
||||
)
|
||||
|
||||
assert_equal "123 Main St\n\nSan Francisco, CA 94101\nUS", address.to_s
|
||||
end
|
||||
end
|
|
@ -21,7 +21,16 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
test "can create property account" do
|
||||
assert_account_created("Property")
|
||||
assert_account_created "Property" do
|
||||
fill_in "Year built (optional)", with: 2005
|
||||
fill_in "Area value (optional)", with: 2250
|
||||
fill_in "Address line 1", with: "123 Main St"
|
||||
fill_in "Address line 2", with: "Apt 4B"
|
||||
fill_in "City", with: "San Francisco"
|
||||
fill_in "State", with: "CA"
|
||||
fill_in "Postal code (optional)", with: "94101"
|
||||
fill_in "Country", with: "US"
|
||||
end
|
||||
end
|
||||
|
||||
test "can create vehicle account" do
|
||||
|
@ -50,7 +59,7 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
click_link "sidebar-new-account"
|
||||
end
|
||||
|
||||
def assert_account_created(accountable_type)
|
||||
def assert_account_created(accountable_type, &block)
|
||||
click_link humanized_accountable(accountable_type)
|
||||
click_link "Enter account balance manually"
|
||||
|
||||
|
@ -59,9 +68,11 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
fill_in "Account name", with: account_name
|
||||
select "Chase", from: "Financial institution"
|
||||
fill_in "account[balance]", with: 100.99
|
||||
check "Add a start balance for this account"
|
||||
fill_in "Start date (optional)", with: 10.days.ago.to_date
|
||||
fill_in "Start balance (optional)", with: 95
|
||||
|
||||
yield if block_given?
|
||||
|
||||
click_button "Add #{humanized_accountable(accountable_type).downcase}"
|
||||
|
||||
find("details", text: humanized_accountable(accountable_type)).click
|
||||
|
@ -69,6 +80,17 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
|
||||
visit accounts_url
|
||||
assert_text account_name
|
||||
|
||||
visit account_url(Account.order(:created_at).last)
|
||||
|
||||
within "header" do
|
||||
find('button[data-menu-target="button"]').click
|
||||
click_on "Edit"
|
||||
end
|
||||
|
||||
fill_in "Account name", with: "Updated account name"
|
||||
click_button "Update #{humanized_accountable(accountable_type).downcase}"
|
||||
assert_selector "h2", text: "Updated account name"
|
||||
end
|
||||
|
||||
def humanized_accountable(accountable_type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue