2020-12-04 08:05:56 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe CustomWizard::Cache do
|
|
|
|
it "writes and reads values to the cache" do
|
2024-10-16 13:52:03 +02:00
|
|
|
CustomWizard::Cache.new("list").write([1, 2, 3])
|
|
|
|
expect(CustomWizard::Cache.new("list").read).to eq([1, 2, 3])
|
2020-12-04 08:05:56 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-12-04 08:05:56 +01:00
|
|
|
it "deletes values from the cache" do
|
2024-10-16 13:52:03 +02:00
|
|
|
CustomWizard::Cache.new("list").delete
|
|
|
|
expect(CustomWizard::Cache.new("list").read).to eq(nil)
|
2020-12-04 08:05:56 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-12-04 08:05:56 +01:00
|
|
|
describe "#wrap" do
|
2024-10-16 13:52:03 +02:00
|
|
|
before { @raw = [1, 2, 3] }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-12-04 08:05:56 +01:00
|
|
|
def list
|
2024-10-16 13:52:03 +02:00
|
|
|
CustomWizard::Cache.wrap("list") { @raw }
|
2020-12-04 08:05:56 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-12-04 08:05:56 +01:00
|
|
|
it "returns value from passed block" do
|
2021-03-11 07:30:15 +01:00
|
|
|
expect(list).to eq([1, 2, 3])
|
2020-12-04 08:05:56 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-12-04 08:05:56 +01:00
|
|
|
it "returns cached value" do
|
|
|
|
cached = list
|
2021-03-11 07:30:15 +01:00
|
|
|
@raw = [3, 2, 1]
|
2020-12-04 08:05:56 +01:00
|
|
|
expect(list).to eq(cached)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|