-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
[Extends #787] - Improve json conversion with tests and support for Rails older than 4.1 #812
[Extends #787] - Improve json conversion with tests and support for Rails older than 4.1 #812
Conversation
…into improve-json-safe-and-pretty # Conflicts: # app/helpers/react_on_rails_helper.rb
…into improve-json-safe-and-pretty # Conflicts: # app/helpers/react_on_rails_helper.rb
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 did not implement the test for Rails 10.0
. It was interesting raising the point to implement a better Rails version comparator but I'm not sure it is useful as a test. What is your opinion about this?
end | ||
|
||
context 'with Rails 3' do | ||
before { allow(Rails).to receive(:version).and_return(3) } |
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'm not really sure that mocking the version is the better way to do.
Could it be a good idea to configure Travis to lauch the tests with differents Rails version? I'm just raising the question, I know this imply to extend the tests duration and to change the Travis configuration.
It seems I cannot fetch the upstream to be up-to-date with the |
Please resolve the conflicts a add a test with a Rails version of 10. We can't easily run CI on rails 32. If you want to submit a PR on that, that would be awesome. Contact me if you want advice on how to do that. |
A couple comments. I'd like to see the escaping part refactored to it's own class for better testing. CC: @cheremukhin23 @Ynote @squadette Reviewed 2 of 3 files at r1, 1 of 1 files at r2. CHANGELOG.md, line 9 at r2 (raw file):
@Ynote you can add you as an author as well ;-) app/helpers/react_on_rails_helper.rb, line 229 at r2 (raw file):
list what types are supported in the error message app/helpers/react_on_rails_helper.rb, line 243 at r2 (raw file):
need tests for this this main issue is that we originally had string comparisons and "10.0" is < "4" In order to best test private methods like this, I'd like to see this escaping functionality moved to a different ruby class. That will work best with @squadette's idea to pretty print in some cases. See #760. spec/dummy/spec/helpers/react_on_rails_helper_spec.rb, line 59 at r2 (raw file): Previously, Ynote (Little Cheung) wrote…
Yes, but it would take (see #814):
Comments from Reviewable |
…into improve-json-safe-and-pretty * upstream/master: Release 6.10.0 Update CHANGELOG.md Add ^ to react-helmut (shakacode#805)
Review status: 0 of 7 files reviewed at latest revision, 4 unresolved discussions. app/helpers/react_on_rails_helper.rb, line 243 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
I moved this method into ReactOnRails::Util as it could be used elsewhere too. Is it ok for you? spec/dummy/spec/helpers/react_on_rails_helper_spec.rb, line 59 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Ok, I'll have a look at this later. I'll try to find some time to work on it. Comments from Reviewable |
Wow! @Ynote GREAT JOB! This is really OUTSTANDING! Reviewed 7 of 7 files at r3. Comments from Reviewable |
@Ynote Please be sure that your PR passes CI. You have many linter errors. Many will be fixed by running https://travis-ci.org/shakacode/react_on_rails/jobs/224013592 |
@Ynote Do you need any help from me to get this one finished up? I want to do one last 6.x release before I merge in the webpacker changes and go to 7.0.0-beta.0 |
Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. lib/react_on_rails/json_output.rb, line 13 at r3 (raw file):
We need to confirm this is less than 4 and not less than 4.2, per #815 and #816 by @EdmundLeex Comments from Reviewable |
Hi, Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. lib/react_on_rails/json_output.rb, line 13 at r3 (raw file): Previously, justin808 (Justin Gordon) wrote…
Ok, I'm gonna change the tested version number. Comments from Reviewable |
Sorry I didn't run rubocop before -_-" It is fixed now! Hope it will be ok for your release. Review status: 3 of 7 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. lib/react_on_rails/json_output.rb, line 13 at r3 (raw file): Previously, Ynote (Little Cheung) wrote…
After reading #815 and #816, I suppose what you meant was to confirm this is less than 4.2 and not 4 :) Comments from Reviewable |
Bumping into this because running into this json issue when I tried out the gem in our app.
This method is called in every request and maybe multiple times in each request. Think we might want to pay more attention to performance. |
Suppose an XSS is discovered. We want to leverage what's in the Rails code. @Ynote, @EdmundLeex: can we do some small memoization, maybe at the class level to address @EdmundLeex's concerns. I agree with him that anything in the rendering cycle should be fairly efficient. That being said. I bet if this were profiled, there would be ZERO difference if we optimized this. I need to get this merged and shipped this weekend, as I'm about to go beta for 7.0.0 |
Review status: 3 of 7 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. lib/react_on_rails/json_output.rb, line 13 at r3 (raw file): Previously, Ynote (Little Cheung) wrote…
I'm not 100% sure on the exact version to compare. This sounds reasonable! lib/react_on_rails/json_output.rb, line 19 at r4 (raw file):
@Ynote Let's add a method that encapsulates the 4.2 check and memoize the result. We also can make the method static, since this class is so simple. I believe that would address @EdmundLeex concerns. Comments from Reviewable |
Reviewed 4 of 4 files at r4. Comments from Reviewable |
FYI: 4.1.1 was the first version that corrected this issue. |
Thanks @EdmundLeex for your concern about performance! @justin808, I added the memoization and follow @EdmundLeex's advice using the test on Rails 4.1.1. Review status: 3 of 7 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. Comments from Reviewable |
lib/react_on_rails/utils.rb
Outdated
@rails_version_less_than ||= {} | ||
@rails_version_less_than[version] = begin | ||
Gem::Version.new(Rails.version) < Gem::Version.new(version) | ||
end |
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.
hmm. I believe this block runs every time instead of using the memoized result?
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.
True. I'm gonna fix it, thanks for the review. Can you tell me why my test passes and so, is not correct? https://github.com/shakacode/react_on_rails/pull/812/files#diff-ad2d9ab6a9a22bf3f00405aba4094cbaR38
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.
this is because subject
is memoized by rspec.
app/helpers/react_on_rails_helper.rb
Outdated
|
||
json_value = hash_or_string.is_a?(String) ? hash_or_string : hash_or_string.to_json | ||
|
||
ReactOnRails::JsonOutput.new(json_value).escaped |
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.
This is where the performance might suffer because a new JsonOutput
object is instantiated each time. Rather, JsonOutput.escape_json(...)
, with escape_json
being a class method can avoid this instantiation.
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.
@EdmundLeex You are right. I'm gonna update it.
1 similar comment
Reviewed 3 of 3 files at r6, 2 of 2 files at r7. lib/react_on_rails/utils.rb, line 39 at r7 (raw file):
was the bug fixed in 4.1.1? (rather than 4.2?) Comments from Reviewable |
@Ynote Please confirm that we should merge and release. Review status: all files reviewed at latest revision, 7 unresolved discussions, some commit checks failed. Comments from Reviewable |
I just tested the PR again with my stack. Everything is ok for me. I think we can merge and release. Review status: all files reviewed at latest revision, 7 unresolved discussions, some commit checks failed. lib/react_on_rails/utils.rb, line 39 at r7 (raw file): Previously, justin808 (Justin Gordon) wrote…
This is the PR that fixes the eating quotes issue and the issue with Comments from Reviewable |
Thank you @Ynote! |
This change is