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

288 support wicked pdf #358

Merged

Conversation

johannesengl
Copy link
Contributor

@johannesengl johannesengl commented May 28, 2020

Summary

This PR aims to solve conflicts with other gems also monkey-patching the ActionView and ActionController render method by giving users an option config to disable the monkey patch and instead of using the render method in view component templates to use the render_component helper.

In < Rails 6.1 the method render_component gets included in ActionView and users can render view components in the following way:

<%= render_component Component.new(message: "bar") %>

The method render_component and render_component_to_string also get included in ActionController

Related Issue
#288

@johannesengl johannesengl marked this pull request as draft May 28, 2020 15:46
@johannesengl johannesengl requested a review from joelhawksley May 28, 2020 17:36
@johannesengl johannesengl requested a review from jonspalmer June 1, 2020 20:28
@joelhawksley joelhawksley marked this pull request as ready for review June 1, 2020 21:04
@joelhawksley
Copy link
Member

@johannesengl thanks for the PR! I've marked it as ready for review. Would you be willing to resolve the merge conflicts?

@johannesengl johannesengl force-pushed the 288-support-wicked-pdf branch from 5c9b81b to 1e72c73 Compare June 2, 2020 07:16
@johannesengl johannesengl force-pushed the 288-support-wicked-pdf branch from 1e72c73 to 06fffc7 Compare June 2, 2020 09:33
@johannesengl
Copy link
Contributor Author

johannesengl commented Jun 2, 2020

@johannesengl thanks for the PR! I've marked it as ready for review. Would you be willing to resolve the merge conflicts?

@joelhawksley Sure no problem. I just resolved the conflicts.

When should I open a PR in draft mode and when should it be set to ready for review? The current PR introduces two new tests that are failing and I opened the PR so we could discuss how to solve this issue:
#358 (comment)

Copy link
Member

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

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

Looking good! Might you add some README updates, including your name on the contributor list, along with a CHANGELOG entry?

When should I open a PR in draft mode and when should it be set to ready for review?

Once want the code reviewed 😄. I moved this to ready to review as I felt it was directionally correct ❤️

@rmacklin
Copy link
Contributor

rmacklin commented Jun 11, 2020

Disclaimer: This is totally not a big deal and I'm happy to stick with Joel's preference for this project.

IMHO, the draft PR state indicates "not ready for merge" (which GitHub helpfully enforces!) but doesn't make a claim about whether it can/should be reviewed; since it's possible to explicitly request a review on a draft PR, that action is the indication that you'd like a review on the PR as it currently stands. With that interpretation, I consider clicking the "Ready for review" button to mean "Ready for review and potentially ready for merge". (All that button really does is take it out of the draft state, which allows the PR to be merged once the other required conditions (status checks/required reviews/no merge conflicts) are met.)

There are times when I'll mark a PR as a draft even if CI has passed, it's been reviewed and approved, and I don't plan on making any further changes to the PR. I do that when I want to prevent it from being merged until something else is done - for example, the PR might not be truly shippable until another system/database/etc. has been updated.

- Set default to true
- Group with oter mattr_accessor
- Add documentation
Copy link
Member

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

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

Looks good! Can you add an entry to CHANGELOG and update the README to include your info?

Run test suit for RAILS_ENV=test_render_monkey_patch_enabled and test_render_monkey_patch_disabled.
That way we are initializing the dummy app once with render_monkey_patch_enabled set to true and once set to false.
@johannesengl
Copy link
Contributor Author

johannesengl commented Jun 18, 2020

Looks good! Can you add an entry to CHANGELOG and update the README to include your info?

@joelhawksley Sure. Just updated the CHANGELOG and README: 685d402

@johannesengl
Copy link
Contributor Author

johannesengl commented Jun 19, 2020

@joelhawksley

I would love to discuss a bit more in detail how we would like to setup a second dummy app in our test suit.

Do we want to have only one process running our test suite and then in the test_helper initialize two dummy apps?
I tried this out and pushed a new branch: https://github.com/johannesengl/view_component/tree/second-dummy-app-same-process/test

This approach fails at the point of initializing the second rails application. When executing Dummy2::Application.initialize! I get an error wrong argument type NilClass (expected Proc/Method/UnboundMethod) (TypeError)

Another option would be to invoke two rake tasks and have two folders for reach app including test files. I tried this approach and pushed it to this branch:
https://github.com/johannesengl/view_component/tree/second-dummy-app/test

The issue here is that we also have unexpected behavior when running tests and passing a specific path to a test file. Furthermore, the second run will override the first test coverage reports.

Also happy to jump on a call to discuss this further.

@rmacklin
Copy link
Contributor

Furthermore, the second run will override the first test coverage reports.

SimpleCov declares support for merging of coverage across test suites. Have we tried this setup:
https://github.com/colszowka/simplecov/blob/v0.18.5/README.md#using-simplecov-for-centralized-config

@joelhawksley
Copy link
Member

@johannesengl this is a tricky one! I paired with my colleague @seejohnrun on this, and he recommended that we look into using the build_app pattern Rails uses to test similar functionality:

https://github.com/rails/rails/blob/e4b6c719cd1df3dd2bf16645dbe7780dd541ec78/railties/test/isolation/abstract_unit.rb#L99

Perhaps you could look into going that route? Let me know what you think.

Just a note: I'm going to be away from my computer for the next week, so I'll plan to catch up on this PR on or around June 29th 😄

Executing simplecov in the rake task led to incorrect test coverage
@johannesengl
Copy link
Contributor Author

@johannesengl this is a tricky one! I paired with my colleague @seejohnrun on this, and he recommended that we look into using the build_app pattern Rails uses to test similar functionality:

https://github.com/rails/rails/blob/e4b6c719cd1df3dd2bf16645dbe7780dd541ec78/railties/test/isolation/abstract_unit.rb#L99

Perhaps you could look into going that route? Let me know what you think.

Just a note: I'm going to be away from my computer for the next week, so I'll plan to catch up on this PR on or around June 29th 😄

@joelhawksley Welcome back. I hope you had a nice break :) Lets maybe align on what we want to archive and also rethink different options.

Option always include render_component
We decided to only add the render_component helper if render_monkey_patch_enabled = false. If we would be willing to add render_component in any case we could test the functionality without the need for a second dummy app.
However, we would still not be able to write a test making sure that the render monkey patches are not included if render_monkey_patch_enabled config is set to false. What do you think regarding this option?

Option several rake tasks
Current issues:

  • Combine simplecov reports
  • Find fix for making it still possible on passing a TEST parameter to test rake task

Option Booting up new rails app based on abstract_unit.rb used in rails testing
Just to clarify. We want to boot up a second rails app in the same process using the build_app pattern right?
I played around with the abstract_unit code. What it does is it boots up rails from an empty state by including some modules in ActiveSupport::TestCase. This opposes from what we have since we already initialized one dummy rails app.
The build_app method actually invokes the rails new generator. I assume more fitting for us would be the make_basic_app method. I was able to archive that the view component engine got executed a second time with the new config options which led to including render_component. However the render monkey patches were still included in ActionView and ActionCntroller.

I was able to run the following test case in isolation successfully. When running the entire test suit other tests however failed.

  test "rendering component using the render_component helper" do
    make_basic_app do |app|
      app.config.view_component.render_monkey_patch_enabled = false    
    end

    assert !Rails.application.config.view_component.render_monkey_patch_enabled

    get "/render_component"
    assert_includes last_response.body, "bar"

    get "/controller_inline_render_component"
    assert_includes last_response.body, "bar"

    get "/controller_to_string_render_component"
    assert_includes last_response.body, "bar"
  end

I would love to maybe pair with someone on this to move this PR forward.

@rmacklin
Copy link
Contributor

Option always include render_component

I would support always providing render_component. Being explicit and using render_component would offer a minor optimization since it jumps straight to https://github.com/rails/rails/blob/cf1881237a3b40c6232cb321bed4f03ccc897cf5/actionview/lib/action_view/helpers/rendering_helper.rb#L43 without evaluating the case or the if, so it could be useful even in Rails 6.1.

@joelhawksley
Copy link
Member

I would support always providing render_component. [...]

I'm wary of going this route. I care a lot about the APIs we provide by default, and I'd much prefer that we use the Rails render call stack in 6.1.

Option Booting up new rails app based on abstract_unit.rb used in rails testing

This looks directionally correct. Let's pair on getting this resolved ❤️

Running the test suite two times with different environments has the following issues:
Generates simplecov reports
Cant pass TEST parameter to test rake task since one task hardcodes test_files
# Conflicts:
#	CHANGELOG.md
#	README.md
#	coverage/coverage.txt
#	test/view_component/integration_test.rb
@johannesengl johannesengl force-pushed the 288-support-wicked-pdf branch from 5f0bb18 to 83b9d03 Compare July 2, 2020 08:47
@johannesengl
Copy link
Contributor Author

I would support always providing render_component. [...]

I'm wary of going this route. I care a lot about the APIs we provide by default, and I'd much prefer that we use the Rails render call stack in 6.1.

Option Booting up new rails app based on abstract_unit.rb used in rails testing

This looks directionally correct. Let's pair on getting this resolved ❤️

After having paired on the Option of booting up new rails app based on abstract_unit.rb with @joelhawksley we decided not to further pursue this direction but rather always include render_component in < rails 6.1.
The option of rendering components via render_component is only given for better backward compatibility and therefore does not justify are more complex test setup using the build_app pattern from rails.

@johannesengl johannesengl requested a review from joelhawksley July 2, 2020 09:09
@joelhawksley joelhawksley merged commit 1b845c6 into ViewComponent:master Jul 2, 2020
@joelhawksley
Copy link
Member

@johannesengl thank you SO much for your work on this PR! I look forward to your next PR :)

@johannesengl
Copy link
Contributor Author

@johannesengl thank you SO much for your work on this PR! I look forward to your next PR :)

@joelhawksley It was my pleasure. I really enjoyed the collaboration with you. Thanks for making this a great first open-source experience! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants