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 3b0fee1
Show file tree
Hide file tree
Showing 5 changed files with 418 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ before_install:

install:
- travis_retry gem install bundler
- travis_retry nvm install 9.11.1
- travis_retry nvm install 8.11.3
- node -v
- travis_retry npm i -g yarn@0.27.5
- travis_retry npm i -g yarn
- travis_retry yarn global add babel-cli
- travis_retry bundle install
- travis_retry yarn
Expand Down
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
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 3b0fee1

Please sign in to comment.