Skip to content

Commit

Permalink
Add validation to security price model
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgoll committed Oct 30, 2024
1 parent cd91e66 commit c991767
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/security/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/models/security/price_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" } ]
)
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c991767

Please sign in to comment.