-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Improve json conversion with tests and support for older Rails 3.x #787
Improve json conversion with tests and support for older Rails 3.x #787
Conversation
Looking great! Reviewed 1 of 2 files at r1, 1 of 1 files at r2. app/helpers/react_on_rails_helper.rb, line 223 at r2 (raw file):
Can we throw here if the value passed is not a hash or a string? What else could the value be? app/helpers/react_on_rails_helper.rb, line 231 at r2 (raw file):
Can we move this catch block around the JSON.parse above? we can do something like: hash_value = if hash_or_string.is_a?(String)
begin
JSON.parse(hash_or_string)
rescue JSON::ParserError => e
raise e, %(Cannot parse #{hash_or_string} \n Backtrace: #{e.backtrace.join("\n")})
else
hash_or_string
end app/helpers/react_on_rails_helper.rb, line 242 at r2 (raw file):
Can you provide a comment with a link on to the github source of this? spec/dummy/spec/helpers/react_on_rails_helper_spec.rb, line 40 at r2 (raw file):
Can we add a couple tests that confirm the exceptions:
Also, we're never testing the part where we check we're in development mode. I'd try to mock/stub out the Rails.env for that test. # RSpec version
it 'tests my code' do
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development'))
# test code
end Comments from Reviewable |
See note below. I might just release a temp patch on this. Review status: all files reviewed at latest revision, 5 unresolved discussions. app/helpers/react_on_rails_helper.rb, line 224 at r2 (raw file):
djudji [1:57 AM] [1:59] djudji [3:31 AM] djudji [3:53 AM] [3:55] [3:56] justin [8:16 AM] djudji [9:49 AM] OK, this is a bit strange.
Now everything is working fine in production, but in dev I still have the same error. This is the URL -> https://calendar-react-on-rails.herokuapp.com/ I can confirm that both of the apps work when pushed to production. This is the first URL -> https://calendar-railsreact.herokuapp.com/ (edited the error is in the conversion to the pretty JSON… for development mode.
Before, we used to call:
|
Note #789 is removing the pretty formatting. We can add it back in... |
@cheremukhin23 I thought more about the pretty formatting of json. Let's add a configuration flag for this, since it tends to break... Default is false. # Pretty printing props looks nice when you view the page source. However, if you have a large
# amount of props data, the page rendering can be a little slower.
config.pretty_print_props_in_development = false |
See #791. I fixed another critical bug...
|
See #799 |
…into improve-json-safe-and-pretty # Conflicts: # app/helpers/react_on_rails_helper.rb
Review status: 0 of 2 files reviewed at latest revision, 5 unresolved discussions. app/helpers/react_on_rails_helper.rb, line 223 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
We discard this code app/helpers/react_on_rails_helper.rb, line 224 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
discarded code app/helpers/react_on_rails_helper.rb, line 242 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
added link spec/dummy/spec/helpers/react_on_rails_helper_spec.rb, line 40 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
added test for arguments Comments from Reviewable |
We need to fix this deprecation for React.
|
Looking good:
Reviewed 2 of 2 files at r3. app/helpers/react_on_rails_helper.rb, line 234 at r3 (raw file):
I think this not right. What if the Rails version is "10.0". Please google for a proper version comparator. Something like this (you creating the
Comments from Reviewable |
@cheremukhin23 See comment: #799 (comment) |
@cheremukhin23 @squadette Maybe I should merge this one and let's add the feature in a new PR? |
please rebase on master and that should fix the CI, @cheremukhin23 |
…into improve-json-safe-and-pretty # Conflicts: # app/helpers/react_on_rails_helper.rb
1 similar comment
Review status: 1 of 3 files reviewed at latest revision, 1 unresolved discussion. app/helpers/react_on_rails_helper.rb, line 234 at r3 (raw file): Previously, justin808 (Justin Gordon) wrote…
Used Gem::Version to compare versions Comments from Reviewable |
Very close. But missing tests on part of the PR. Reviewed 1 of 1 files at r5, 1 of 1 files at r6. app/helpers/react_on_rails_helper.rb, line 251 at r6 (raw file):
This code is not tested. We need a test to confirm this method works as well as the method rails_version_less_than. Please add a couple simple tests for rails_version_less_than with cases "3.2", "3", "4.2", "10.0". Comments from Reviewable |
@cheremukhin23 Please let me know if you can finish this. If you don't have time, I need to find an alternate resource. @squadette, any chance that you can help with this one? |
@Ynote, is there chance that you can give us a hand with this one? |
@@ -224,8 +224,33 @@ def server_render_js(js_expression, options = {}) | |||
# rubocop:enable Style/RaiseArgs | |||
end | |||
|
|||
def json_safe_and_pretty(hash_or_string) | |||
unless hash_or_string.class.in?([Hash, String]) | |||
raise "#{hash_or_string.class} is unsupported argument class for this method" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name the types that are accepted by the method in this error.
Hi, I can help on the PR. @cheremukhin23, can you give me permission on the PR so I can fetch the branch and add the missing tests? |
@Ynote @cheremukhin23 You can also pull his changes into your own fork and make a new branch. @squadette would like us to put back in JSON props as pretty. I'm ok with that either in this or a different PR, but I won't accept any PR without full test coverage and documentation changes. |
See #812. |
…ails older than 4.1 (#812) * Improve json_safe_and_pretty method to handle parse error * Add tests to json_safe_and_pretty method * Add old json escape method for Rails versions less than 4 * Add json safe and pretty argument class test * Add rails version less than method * Add tests for json encoding helper methods * Move rails_version_less_than method into Utils module * Extract json escaping logic into JsonOutput class * Remove "or equal" logic from rails_version_less_than util method * Use monkey patch json escape from Rails 4.2 instead of Rails 4 * Memoize result for static method rails_version_less_than * Update json escaping method into class methods
This change is