Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/telephone/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Service
# Primary responsibility of initialize is to instantiate the
# attributes of the service object with the expected values.
def initialize(attributes = {})
attributes = attributes.transform_keys(&:to_sym)

attributes.each do |key, value|
send("#{key}=", value)
end
Expand Down
13 changes: 13 additions & 0 deletions spec/telephone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ def call
expect(subject.new(foo: "baz").foo).to be "baz"
end

it "accepts string keys" do
expect(subject.new("foo" => "baz").foo).to eq "baz"
end

it "handles string keys with callable defaults" do
service = Class.new(Telephone::Service) do
argument :name, default: "Default"
argument :message, default: -> { "Hello, #{name}!" }
end

expect(service.new("name" => "Custom").message).to eq "Hello, Custom!"
end

context "if there is a required argument" do
before { subject.public_send(:argument, :required_field, required: true) }

Expand Down