Skip to content

Commit

Permalink
add #any? and #empty? to Lucky::FlashStore (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdtomlin authored and paulcsmith committed Nov 23, 2019
1 parent b6588de commit 33606a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions spec/lucky/cookies/flash_store_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,38 @@ describe Lucky::FlashStore do
end
end

describe "#any?" do
it "returns true if there are key/value pairs" do
flash_store = build_flash_store(next: {
"some_key" => "some_value",
})

flash_store.any?.should be_true
end

it "returns false if there are no key/value pairs" do
flash_store = build_flash_store

flash_store.any?.should be_false
end
end

describe "#empty?" do
it "returns false if there are key/value pairs" do
flash_store = build_flash_store(next: {
"some_key" => "some_value",
})

flash_store.empty?.should be_false
end

it "returns true if there are no key/value pairs" do
flash_store = build_flash_store

flash_store.empty?.should be_true
end
end

describe "#all" do
it "prefers values from @next over @now" do
next_hash = {"name" => "Paul"}
Expand Down
2 changes: 1 addition & 1 deletion src/lucky/cookies/flash_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Lucky::FlashStore
SESSION_KEY = "_flash"
alias Key = String | Symbol

delegate each, to: all
delegate any?, each, empty?, to: all

@now = {} of String => String
@next = {} of String => String
Expand Down

0 comments on commit 33606a6

Please sign in to comment.