Skip to content

Commit

Permalink
HashWithIndifferent access for props threw
Browse files Browse the repository at this point in the history
Now, conversion of props works for HashWithIndifferentAccess. Previously
crashed.
  • Loading branch information
justin808 committed Jun 13, 2018
1 parent e86090f commit b98a941
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/react_on_rails/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def server_render_js(js_expression, options = {})

def json_safe_and_pretty(hash_or_string)
return "{}" if hash_or_string.nil?
unless hash_or_string.class.in?([Hash, String])
unless hash_or_string.is_a?(String) || hash_or_string.is_a?(Hash)
raise ReactOnRails::Error, "#{__method__} only accepts String or Hash as argument "\
"(#{hash_or_string.class} given)."
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: ../..
specs:
react_on_rails (11.0.6)
react_on_rails (11.0.7)
addressable
connection_pool
execjs (~> 2.5)
Expand Down Expand Up @@ -350,4 +350,4 @@ DEPENDENCIES
webpacker

BUNDLED WITH
1.16.1
1.16.2
4 changes: 3 additions & 1 deletion spec/dummy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@
"url": "https://github.com/shakacode/react_on_rails/issues"
},
"devDependencies": {},
"dependencies": {}
"dependencies": {
"fsevents": "^1.2.4"
}
}
10 changes: 10 additions & 0 deletions spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
expect { helper.json_safe_and_pretty(false) }.to raise_error
end

it "should return empty json when an empty Hash" do
escaped_json = helper.json_safe_and_pretty({})
expect(escaped_json).to eq("{}")
end

it "should return empty json when an empty HashWithIndifferentAccess" do
escaped_json = helper.json_safe_and_pretty(HashWithIndifferentAccess.new)
expect(escaped_json).to eq("{}")
end

it "should return empty json when nil" do
escaped_json = helper.json_safe_and_pretty(nil)
expect(escaped_json).to eq("{}")
Expand Down
Loading

0 comments on commit b98a941

Please sign in to comment.