Skip to content

Commit

Permalink
feat: support saving symbol configuration settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 10, 2020
1 parent a34d5f7 commit 73db9c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/pact_broker/config/setting.rb
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -56,6 +58,8 @@ def self.get_db_type(object)
'integer'
when Float
'float'
when Symbol
'symbol'
else
nil
end
Expand Down
8 changes: 7 additions & 1 deletion spec/lib/pact_broker/config/load_spec.rb
Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/lib/pact_broker/config/save_spec.rb
Expand Up @@ -7,14 +7,15 @@ 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,
bar: false,
wiffle: ["a", "b", "c"],
meep: {a: 'thing'},
flop: nil,
blah: :boop,
peebo: 1,
lalala: 1.2,
meow: Object.new,
Expand All @@ -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')
Expand Down

0 comments on commit 73db9c2

Please sign in to comment.