2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe PluginStore do
|
2017-11-15 09:10:20 -06:00
|
|
|
let(:store) { PluginStore.new("my_plugin_2") }
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def set(k, v)
|
2013-08-25 21:52:36 -05:00
|
|
|
PluginStore.set("my_plugin", k, v)
|
2017-11-15 09:10:20 -06:00
|
|
|
store.set(k, v)
|
2013-08-25 21:52:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(k)
|
2017-11-15 09:10:20 -06:00
|
|
|
value = PluginStore.get("my_plugin", k)
|
|
|
|
value == store.get(k) ? value : "values mismatch"
|
2013-08-25 21:52:36 -05:00
|
|
|
end
|
|
|
|
|
2018-08-01 11:42:40 -05:00
|
|
|
def get_all(k)
|
|
|
|
value = PluginStore.get_all("my_plugin", k)
|
|
|
|
value == store.get_all(k) ? value : "values mismatch"
|
|
|
|
end
|
|
|
|
|
2014-02-24 18:11:31 -06:00
|
|
|
def remove_row(k)
|
|
|
|
PluginStore.remove("my_plugin", k)
|
2017-11-15 09:10:20 -06:00
|
|
|
store.remove(k)
|
2014-02-24 18:11:31 -06:00
|
|
|
end
|
|
|
|
|
2013-08-25 21:52:36 -05:00
|
|
|
it "sets strings correctly" do
|
|
|
|
set("hello", "world")
|
|
|
|
expect(get("hello")).to eq("world")
|
|
|
|
|
|
|
|
set("hello", "world1")
|
|
|
|
expect(get("hello")).to eq("world1")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets fixnums correctly" do
|
|
|
|
set("hello", 1)
|
|
|
|
expect(get("hello")).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets bools correctly" do
|
|
|
|
set("hello", true)
|
|
|
|
expect(get("hello")).to eq(true)
|
|
|
|
|
|
|
|
set("hello", false)
|
|
|
|
expect(get("hello")).to eq(false)
|
|
|
|
|
|
|
|
set("hello", nil)
|
|
|
|
expect(get("hello")).to eq(nil)
|
|
|
|
end
|
|
|
|
|
2018-08-01 11:42:40 -05:00
|
|
|
it "gets all requested values" do
|
|
|
|
set("hello_str", "world")
|
|
|
|
set("hello_int", 1)
|
|
|
|
set("hello_bool", true)
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(get_all(%w[hello_str hello_int hello_bool])).to eq(
|
|
|
|
{ hello_str: "world", hello_int: 1, hello_bool: true }.stringify_keys,
|
|
|
|
)
|
2018-08-01 11:42:40 -05:00
|
|
|
end
|
|
|
|
|
2013-08-25 21:52:36 -05:00
|
|
|
it "handles hashes correctly" do
|
2017-07-27 20:20:09 -05:00
|
|
|
val = { "hi" => "there", "1" => 1 }
|
2013-08-25 21:52:36 -05:00
|
|
|
set("hello", val)
|
|
|
|
result = get("hello")
|
|
|
|
|
|
|
|
expect(result).to eq(val)
|
|
|
|
|
|
|
|
# ensure indiff access holds
|
|
|
|
expect(result[:hi]).to eq("there")
|
|
|
|
end
|
2014-02-24 18:11:31 -06:00
|
|
|
|
2014-03-10 04:22:59 -05:00
|
|
|
it "handles nested hashes correctly" do
|
2017-07-27 20:20:09 -05:00
|
|
|
val = { "hi" => "there", "nested" => { "a" => "b", "with list" => ["a", "b", 3] } }
|
2014-03-10 04:22:59 -05:00
|
|
|
set("hello", val)
|
|
|
|
result = get("hello")
|
|
|
|
|
|
|
|
expect(result).to eq(val)
|
|
|
|
|
|
|
|
# ensure indiff access holds
|
|
|
|
expect(result[:hi]).to eq("there")
|
|
|
|
expect(result[:nested][:a]).to eq("b")
|
|
|
|
expect(result[:nested]["with list"]).to eq(["a", "b", 3])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles arrays correctly" do
|
2017-07-27 20:20:09 -05:00
|
|
|
val = ["a", "b", { "hash" => "inside", "c" => 1 }]
|
2014-03-10 04:22:59 -05:00
|
|
|
set("hello", val)
|
|
|
|
result = get("hello")
|
|
|
|
|
|
|
|
expect(result).to eq(val)
|
|
|
|
|
|
|
|
# ensure indiff access holds
|
|
|
|
expect(result[2][:hash]).to eq("inside")
|
|
|
|
expect(result[2]["c"]).to eq(1)
|
|
|
|
end
|
|
|
|
|
2014-02-24 18:11:31 -06:00
|
|
|
it "removes correctly" do
|
|
|
|
set("hello", true)
|
|
|
|
remove_row("hello")
|
|
|
|
expect(get("hello")).to eq(nil)
|
|
|
|
end
|
2013-08-25 21:52:36 -05:00
|
|
|
end
|