Skip to content

Commit 93d6f21

Browse files
committed
#415: fee() must validate that tab is non-empty
1 parent 239d0a8 commit 93d6f21

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/baza-rb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ def transfer(recipient, amount, summary, job: nil, badge: nil)
476476
# @raise [ServerFailure] If the payment fails
477477
def fee(tab, amount, summary, job)
478478
raise(RuntimeError, 'The "tab" is nil') if tab.nil?
479+
raise(RuntimeError, 'The "tab" may not be empty') if tab.empty?
479480
raise(RuntimeError, 'The "amount" is nil') if amount.nil?
480481
unless amount.is_a?(Float) || amount.is_a?(BigDecimal)
481482
raise(RuntimeError, 'The "amount" must be Float or BigDecimal')

lib/baza-rb/fake.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def transfer(recipient, amount, summary, job: nil, badge: nil)
224224
# @return [Integer] Always returns 42 as the fake receipt ID
225225
def fee(tab, amount, summary, job)
226226
raise(RuntimeError, 'The "tab" is nil') if tab.nil?
227+
raise(RuntimeError, 'The "tab" may not be empty') if tab.empty?
227228
raise(RuntimeError, 'The "amount" is nil') if amount.nil?
228229
unless amount.is_a?(Float) || amount.is_a?(BigDecimal)
229230
raise(RuntimeError, 'The "amount" must be Float or BigDecimal')

test/test_baza_edge.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,13 @@ def test_fee_raises_when_amount_is_not_positive
813813
end
814814
end
815815

816+
def test_fee_raises_when_tab_is_empty
817+
assert_equal(
818+
'The "tab" may not be empty',
819+
assert_raises(RuntimeError) { fake_baza.fee('', 1.0, 'pay', 42) }.message
820+
)
821+
end
822+
816823
def test_fee_raises_when_summary_is_empty
817824
assert_equal(
818825
'The summary "" is empty',

test/test_fake.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ def test_fee_raises_when_amount_is_not_positive
297297
)
298298
end
299299

300+
def test_fee_raises_when_tab_is_empty
301+
assert_equal(
302+
'The "tab" may not be empty',
303+
assert_raises(RuntimeError) { BazaRb::Fake.new.fee('', 1.0, 'for fun', 44) }.message
304+
)
305+
end
306+
300307
def test_fee_raises_when_job_is_not_positive
301308
assert_equal(
302309
'The "job" must be positive',

0 commit comments

Comments
 (0)