Skip to content

Commit 73db9c2

Browse files
committed
feat: support saving symbol configuration settings
1 parent a34d5f7 commit 73db9c2

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/pact_broker/config/setting.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def value_object
1414
JSON.parse(value, symbolize_names: true)
1515
when 'string'
1616
value
17+
when 'symbol'
18+
value.to_sym
1719
when 'integer'
1820
Integer(value)
1921
when 'float'
@@ -33,7 +35,7 @@ def self.get_db_value(object)
3335
"1"
3436
when FalseClass
3537
"0"
36-
when SpaceDelimitedStringList
38+
when SpaceDelimitedStringList, Symbol
3739
object.to_s
3840
when Array, Hash
3941
object.to_json
@@ -56,6 +58,8 @@ def self.get_db_type(object)
5658
'integer'
5759
when Float
5860
'float'
61+
when Symbol
62+
'symbol'
5963
else
6064
nil
6165
end

spec/lib/pact_broker/config/load_spec.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Config
77
describe ".call" do
88

99
class MockConfig
10-
attr_accessor :foo, :bar, :nana, :meep, :lalala, :meow, :peebo, :whitelist
10+
attr_accessor :foo, :bar, :nana, :meep, :lalala, :meow, :peebo, :whitelist, :blah
1111
end
1212

1313
before do
@@ -20,6 +20,7 @@ class MockConfig
2020
Setting.create(name: 'peebo', type: 'string', value: nil)
2121
Setting.create(name: 'unknown', type: 'string', value: nil)
2222
Setting.create(name: 'whitelist', type: 'space_delimited_string_list', value: 'foo bar')
23+
Setting.create(name: 'blah', type: 'symbol', value: 'boop')
2324
end
2425

2526
let(:configuration) { MockConfig.new }
@@ -36,6 +37,11 @@ class MockConfig
3637
expect(configuration.bar).to eq "bar"
3738
end
3839

40+
it "loads a Symbol setting" do
41+
subject
42+
expect(configuration.blah).to eq :boop
43+
end
44+
3945
it "loads an Integer setting" do
4046
subject
4147
expect(configuration.nana).to eq 1

spec/lib/pact_broker/config/save_spec.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ module Config
77
describe Save do
88

99
describe "#call" do
10-
let(:setting_names) { [:foo, :bar, :wiffle, :meep, :flop, :peebo, :lalala, :meow, :whitelist] }
10+
let(:setting_names) { [:foo, :bar, :wiffle, :meep, :flop, :peebo, :lalala, :meow, :whitelist, :blah] }
1111
let(:configuration) do
1212
double("PactBroker::Configuration",
1313
foo: true,
1414
bar: false,
1515
wiffle: ["a", "b", "c"],
1616
meep: {a: 'thing'},
1717
flop: nil,
18+
blah: :boop,
1819
peebo: 1,
1920
lalala: 1.2,
2021
meow: Object.new,
@@ -23,6 +24,13 @@ module Config
2324

2425
subject { Save.call(configuration, setting_names) }
2526

27+
it "saves a Symbol" do
28+
subject
29+
setting = Setting.find(name: 'blah')
30+
expect(setting.type).to eq 'symbol'
31+
expect(setting.value).to eq 'boop'
32+
end
33+
2634
it "saves a false config setting to the database" do
2735
subject
2836
setting = Setting.find(name: 'foo')

0 commit comments

Comments
 (0)