Skip to content

Commit

Permalink
Added logic to support both string and symbol access to keys in dialo…
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanzillo committed Apr 3, 2019
1 parent 55621be commit b550694
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/services/api/request_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def self.parse_user(data)

def self.parse_options(data)
raise BadRequestError, "Request is missing options" if data["options"].blank?
data["options"].deep_symbolize_keys
# Need to preserve string keys in dialog sub-hash while still supporting access by symbols
dialog = data["options"].delete("dialog")
data["options"].deep_symbolize_keys.tap do |hash|
hash[:dialog] = dialog.with_indifferent_access if dialog.present?
end
end

def self.parse_auto_approve(data)
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/services/api/request_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
expected = {:foo => "bar", :foobar => {:bazz => "foo"}}
expect(actual).to eq(expected)
end

it "deep symbolizes keys except the dialog" do
actual = described_class.parse_options("options" => {"foo" => "bar", "dialog" => { "item" => "value"}})
expected = {:foo => "bar", :dialog => { "item" => "value" }}
expect(actual).to eq(expected)
expect(actual[:dialog][:item]).to eq("value")
expect(actual[:dialog]["item"]).to eq("value")
end
end

describe ".parse_auto_approve" do
Expand Down

0 comments on commit b550694

Please sign in to comment.