2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe SiteSettings::LocalProcessProvider do
|
2013-06-22 23:35:06 -04:00
|
|
|
def expect_same_setting(actual, expected)
|
|
|
|
expect(actual.name).to eq(expected.name)
|
|
|
|
expect(actual.value).to eq(expected.value)
|
|
|
|
expect(actual.data_type).to eq(expected.data_type)
|
|
|
|
end
|
|
|
|
|
2019-04-16 14:42:47 -04:00
|
|
|
let(:provider) { described_class.new }
|
2013-06-22 23:35:06 -04:00
|
|
|
|
|
|
|
def setting(name, value, data_type)
|
2019-04-16 14:42:47 -04:00
|
|
|
described_class::Setting.new(name, data_type).tap { |s| s.value = value }
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "all" do
|
|
|
|
it "starts off empty" do
|
|
|
|
expect(provider.all).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can allows additional settings" do
|
|
|
|
provider.save("test", "bla", 2)
|
|
|
|
expect_same_setting(provider.all[0], setting("test", "bla", 2))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not leak new stuff into list" do
|
|
|
|
provider.save("test", "bla", 2)
|
|
|
|
provider.save("test", "bla1", 2)
|
|
|
|
expect_same_setting(provider.all[0], setting("test", "bla1", 2))
|
|
|
|
expect(provider.all.length).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "find" do
|
|
|
|
it "starts off empty" do
|
|
|
|
expect(provider.find("bla")).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can find a new setting" do
|
|
|
|
provider.save("one", "two", 3)
|
|
|
|
expect_same_setting(provider.find("one"), setting("one", "two", 3))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can amend a setting" do
|
|
|
|
provider.save("one", "three", 4)
|
|
|
|
expect_same_setting(provider.find("one"), setting("one", "three", 4))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "destroy" do
|
|
|
|
it "can destroy a setting" do
|
|
|
|
provider.save("one", "three", 4)
|
|
|
|
provider.destroy("one")
|
|
|
|
expect(provider.find("one")).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the correct site name" do
|
2020-08-18 09:38:30 -04:00
|
|
|
expect(provider.current_site).to eq("default")
|
|
|
|
end
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|