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

Return empty json when nil in json_safe_and_pretty #824

Merged
merged 1 commit into from
Apr 28, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]

## [Unreleased]
*Please add entries here for your pull requests.*
- Return empty json when nil in json_safe_and_pretty [#824](https://github.com/shakacode/react_on_rails/pull/824) by [dzirtusss](https://github.com/dzirtusss)

## [7.0.3] - 2017-04-27
Same as 7.0.1.
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def server_render_js(js_expression, options = {})
end

def json_safe_and_pretty(hash_or_string)
return if hash_or_string.nil?
return "{}" if hash_or_string.nil?
unless hash_or_string.class.in?([Hash, String])
raise "#{__method__} only accepts String or Hash as argument "\
"(#{hash_or_string.class} given)."
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
expect { helper.json_safe_and_pretty(false) }.to raise_error
end

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

it "converts a hash to escaped JSON" do
Expand Down