Skip to content

Commit 538842a

Browse files
committed
Allow negative values for Block.set!
1 parent 6d4fc1b commit 538842a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/pecorino/block.rb

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Pecorino::Block
1313
def self.set!(key:, block_for:, adapter: Pecorino.adapter)
1414
adapter.set_block(key: key, block_for: block_for)
1515
Time.now + block_for
16+
rescue ArgumentError # negative block
17+
nil
1618
end
1719

1820
# Returns the time until a certain block is in effect

test/block_test.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class BlockTest < ActiveSupport::TestCase
1515
test "does not return a block which has lapsed" do
1616
k = Base64.strict_encode64(Random.bytes(4))
1717
assert_nil Pecorino::Block.blocked_until(key: k)
18-
assert Pecorino::Block.set!(key: k, block_for: -30.minutes)
19-
18+
Pecorino::Block.set!(key: k, block_for: -30.minutes)
2019
blocked_until = Pecorino::Block.blocked_until(key: k)
2120
assert_nil blocked_until
2221
end

0 commit comments

Comments
 (0)