diff --git a/lib/pact_broker/config/setting.rb b/lib/pact_broker/config/setting.rb index 1fec50b9b..33fd27292 100644 --- a/lib/pact_broker/config/setting.rb +++ b/lib/pact_broker/config/setting.rb @@ -14,6 +14,8 @@ def value_object JSON.parse(value, symbolize_names: true) when 'string' value + when 'symbol' + value.to_sym when 'integer' Integer(value) when 'float' @@ -33,7 +35,7 @@ def self.get_db_value(object) "1" when FalseClass "0" - when SpaceDelimitedStringList + when SpaceDelimitedStringList, Symbol object.to_s when Array, Hash object.to_json @@ -56,6 +58,8 @@ def self.get_db_type(object) 'integer' when Float 'float' + when Symbol + 'symbol' else nil end diff --git a/spec/lib/pact_broker/config/load_spec.rb b/spec/lib/pact_broker/config/load_spec.rb index c48398b27..ca860ae97 100644 --- a/spec/lib/pact_broker/config/load_spec.rb +++ b/spec/lib/pact_broker/config/load_spec.rb @@ -7,7 +7,7 @@ module Config describe ".call" do class MockConfig - attr_accessor :foo, :bar, :nana, :meep, :lalala, :meow, :peebo, :whitelist + attr_accessor :foo, :bar, :nana, :meep, :lalala, :meow, :peebo, :whitelist, :blah end before do @@ -20,6 +20,7 @@ class MockConfig Setting.create(name: 'peebo', type: 'string', value: nil) Setting.create(name: 'unknown', type: 'string', value: nil) Setting.create(name: 'whitelist', type: 'space_delimited_string_list', value: 'foo bar') + Setting.create(name: 'blah', type: 'symbol', value: 'boop') end let(:configuration) { MockConfig.new } @@ -36,6 +37,11 @@ class MockConfig expect(configuration.bar).to eq "bar" end + it "loads a Symbol setting" do + subject + expect(configuration.blah).to eq :boop + end + it "loads an Integer setting" do subject expect(configuration.nana).to eq 1 diff --git a/spec/lib/pact_broker/config/save_spec.rb b/spec/lib/pact_broker/config/save_spec.rb index 4491693be..5a03dbf79 100644 --- a/spec/lib/pact_broker/config/save_spec.rb +++ b/spec/lib/pact_broker/config/save_spec.rb @@ -7,7 +7,7 @@ module Config describe Save do describe "#call" do - let(:setting_names) { [:foo, :bar, :wiffle, :meep, :flop, :peebo, :lalala, :meow, :whitelist] } + let(:setting_names) { [:foo, :bar, :wiffle, :meep, :flop, :peebo, :lalala, :meow, :whitelist, :blah] } let(:configuration) do double("PactBroker::Configuration", foo: true, @@ -15,6 +15,7 @@ module Config wiffle: ["a", "b", "c"], meep: {a: 'thing'}, flop: nil, + blah: :boop, peebo: 1, lalala: 1.2, meow: Object.new, @@ -23,6 +24,13 @@ module Config subject { Save.call(configuration, setting_names) } + it "saves a Symbol" do + subject + setting = Setting.find(name: 'blah') + expect(setting.type).to eq 'symbol' + expect(setting.value).to eq 'boop' + end + it "saves a false config setting to the database" do subject setting = Setting.find(name: 'foo')