1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00

Add validation to security price model

This commit is contained in:
Zach Gollwitzer 2024-10-30 09:51:05 -04:00
parent cd91e66618
commit c9917674aa
3 changed files with 5 additions and 3 deletions

View file

@ -3,6 +3,8 @@ class Security::Price < ApplicationRecord
belongs_to :security
validates :price, :currency, presence: true
class << self
def find_price(security:, date:, cache: true)
result = find_by(security:, date:)

2
db/schema.rb generated
View file

@ -119,7 +119,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_30_121302) do
t.boolean "is_active", default: true, null: false
t.date "last_sync_date"
t.uuid "institution_id"
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY (ARRAY[('Loan'::character varying)::text, ('CreditCard'::character varying)::text, ('OtherLiability'::character varying)::text])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
t.uuid "import_id"
t.string "mode"
t.index ["accountable_id", "accountable_type"], name: "index_accounts_on_accountable_id_and_accountable_type"

View file

@ -36,7 +36,7 @@ class Security::PriceTest < ActiveSupport::TestCase
.returns(
OpenStruct.new(
success?: true,
prices: [ { date: tomorrow, price: expected_price } ]
prices: [ { date: tomorrow, price: expected_price, currency: "USD" } ]
)
)
@ -89,7 +89,7 @@ class Security::PriceTest < ActiveSupport::TestCase
mic_code: security.exchange_mic,
start_date: 2.days.ago.to_date,
end_date: 2.days.ago.to_date)
.returns(OpenStruct.new(success?: true, prices: [ { date: 2.days.ago.to_date, price: missing_price } ]))
.returns(OpenStruct.new(success?: true, prices: [ { date: 2.days.ago.to_date, price: missing_price, currency: "USD" } ]))
.once
price1 = security_prices(:one) # AAPL today