Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to handle nil values in json_safe_and_pretty #823

Merged
merged 2 commits into from
Apr 27, 2017
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project's source code will be documented in this fil
Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.

## [Unreleased]
*Please add entries here for your pull requests.*

## [7.0.1] - 2017-04-27
### Fixed
- Fix to handle nil values in json_safe_and_pretty [#823](https://github.com/shakacode/react_on_rails/pull/823) by [dzirtusss](https://github.com/dzirtusss)

## [7.0.0] - 2017-04-25
### Changed
- Any version differences in gem and node package for React on Rails throw an error [#821](https://github.com/shakacode/react_on_rails/pull/821) by [justin808](https://github.com/justin808)
Expand Down Expand Up @@ -541,7 +547,8 @@ Best done with Object destructing:
##### Fixed
- Fix several generator related issues.

[Unreleased]: https://github.com/shakacode/react_on_rails/compare/7.0.0...master
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/7.0.1...master
[7.0.1]: https://github.com/shakacode/react_on_rails/compare/7.0.0...7.0.1
[7.0.0]: https://github.com/shakacode/react_on_rails/compare/6.10.1...7.0.0
[6.10.1]: https://github.com/shakacode/react_on_rails/compare/6.10.0...6.10.1
[6.10.0]: https://github.com/shakacode/react_on_rails/compare/6.9.3...6.10.0
Expand Down
1 change: 1 addition & 0 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def server_render_js(js_expression, options = {})
end

def json_safe_and_pretty(hash_or_string)
return if hash_or_string.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a quick test?

unless hash_or_string.class.in?([Hash, String])
raise "#{__method__} only accepts String or Hash as argument "\
"(#{hash_or_string.class} given)."
Expand Down
7 changes: 6 additions & 1 deletion spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
end

describe "#json_safe_and_pretty(hash_or_string)" do
it "should raise an error if not hash nor string passed" do
it "should raise an error if not hash nor string nor nil passed" do
expect { helper.json_safe_and_pretty(false) }.to raise_error
end

it "should allow nil values" do
escaped_json = helper.json_safe_and_pretty(nil)
expect(escaped_json).to eq(nil)
end

it "converts a hash to escaped JSON" do
escaped_json = helper.json_safe_and_pretty(hash)
expect(escaped_json).to eq(json_string_sanitized)
Expand Down