Skip to content

Commit

Permalink
Avoid possible bugs with truthiness checks for Bool attributes
Browse files Browse the repository at this point in the history
Related to commit d6a6027.
  • Loading branch information
akadusei committed Oct 27, 2023
1 parent a55b05c commit daf5e01
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased] -

### Fixed
- Avoid possible bugs with truthiness checks for `Bool` operation attributes

## [0.14.3] - 2023-10-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/bill/operations/mixins/set_default_quantity.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Bill::SetDefaultQuantity
end

private def set_default_quantity
quantity.value = 1 unless quantity.value
quantity.value = 1 if quantity.value.nil?
end
end
end
2 changes: 1 addition & 1 deletion src/bill/operations/mixins/set_default_status.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Bill::SetDefaultStatus
end

private def set_default_status
return if status.value
return unless status.value.nil?
status.value = {{ T }}Status.new(:draft)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/bill/operations/mixins/set_finalized_created_at.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Bill::SetFinalizedCreatedAt
end

private def set_finalized_created_at
return unless created_at.value
return if created_at.value.nil?
created_at.value = Time.utc if {{ T }}Status.now_finalized?(status)
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/bill/operations/refund_payment.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Bill::RefundPayment
end

private def set_amount
return if amount.value
return unless amount.value.nil?
receipt.try { |receipt| amount.value = receipt.amount }
end

Expand All @@ -46,7 +46,7 @@ module Bill::RefundPayment
end

private def set_default_description
return if description.value
return unless description.value.nil?

receipt.try do |receipt|
description.value = Rex.t(
Expand All @@ -57,10 +57,10 @@ module Bill::RefundPayment
end

private def validate_amount_lte_receipt
return unless value = amount.value
amount.value.try do |value|
receipt.try do |receipt|
return if value <= receipt.amount

receipt.try do |receipt|
if value > receipt.amount
amount.add_error Rex.t(
:"operation.error.refund_exceeds_receipt",
amount: value,
Expand Down

0 comments on commit daf5e01

Please sign in to comment.