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

Tighten up the AV::Base constructor #35093

Merged
merged 1 commit into from Jan 30, 2019
Merged

Tighten up the AV::Base constructor #35093

merged 1 commit into from Jan 30, 2019

Conversation

tenderlove
Copy link
Member

The AV::Base constructor was too complicated, and this commit tightens
up the parameters it will take. At runtime, AV::Base is most commonly
constructed here:

def view_context
view_context_class.new(view_renderer, view_assigns, self)
end

This provides an AV::Renderer instance, a hash of assignments, and a
controller instance. Since this is the common case for construction, we
should remove logic from the constructor that handles other cases. This
commit introduces special constructors for those other cases.
Interestingly, most code paths that construct AV::Base "strangely" are
tests.

The AV::Base constructor was too complicated, and this commit tightens
up the parameters it will take.  At runtime, AV::Base is most commonly
constructed here:

  https://github.com/rails/rails/blob/94d54fa4ab641a0ddeb173409cb41cc5becc02a9/actionview/lib/action_view/rendering.rb#L72-L74

This provides an AV::Renderer instance, a hash of assignments, and a
controller instance.  Since this is the common case for construction, we
should remove logic from the constructor that handles other cases.  This
commit introduces special constructors for those other cases.
Interestingly, most code paths that construct AV::Base "strangely" are
tests.
@tenderlove tenderlove merged commit 535a8b9 into master Jan 30, 2019
@tenderlove tenderlove deleted the av-base-constructor branch January 30, 2019 19:57
@_config = ActiveSupport::InheritableOptions.new

if context.is_a?(ActionView::Renderer)
@view_renderer = context
unless formats == NULL
Copy link
Member

Choose a reason for hiding this comment

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

If formats is NULL, should change the value to nil?
If this is left as NULL(Object.new), it will be incorrectly judged where the value is nil or not.

For example, if using web-console, NoMethodError will be raise in lookup context.

DEPRECATION WARNING: ActionView::Base instances should be constructed with a view renderer,
assigments, and a controller.
 (called from new at /home/y-yagi/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/web-console-3.7.0/lib/web_console/template.rb:21)

NoMethodError: undefined method `delete' for #<Object:0x000055e2e6120880>
	from /home/y-yagi/src/rails/master_y_yagi/rails/actionview/lib/action_view/lookup_context.rb:258:in `formats='
	from /home/y-yagi/src/rails/master_y_yagi/rails/actionview/lib/action_view/base.rb:206:in `build_renderer'
	from /home/y-yagi/src/rails/master_y_yagi/rails/actionview/lib/action_view/base.rb:243:in `initialize'
	from /home/y-yagi/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/web-console-3.7.0/lib/web_console/template.rb:21:in `new'
	from /home/y-yagi/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/web-console-3.7.0/lib/web_console/template.rb:21:in `render'
	from /home/y-yagi/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:37:in `block in call'
	from /home/y-yagi/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
	from /home/y-yagi/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
	from /home/y-yagi/src/rails/master_y_yagi/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'

Copy link
Member

Choose a reason for hiding this comment

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

@y-yagi I think so. Can you commit the change?

Copy link
Member

Choose a reason for hiding this comment

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

Already fixed by eda0f57.

kamipo added a commit to kamipo/rails that referenced this pull request Jan 31, 2019
I deprecated two unused attr_writers `visitor` and `indexes` at 8056fe0
and f4bc364 conservatively, since those are accidentaly exposed in the
docs.

https://api.rubyonrails.org/v5.2/classes/ActiveRecord/ConnectionAdapters/AbstractAdapter.html
https://api.rubyonrails.org/v5.2/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html

But I've found that `view_renderer` attr_writer is removed without
deprecation at rails#35093, that is also exposed in the doc.

https://api.rubyonrails.org/v5.2/classes/ActionView/Base.html

I'd like to also remove the deprecated attr_writers since I think that
removing `visitor` and `indexes` attr_writers is as safe as removing
`view_renderer` attr_writer.
koic added a commit to koic/buoys that referenced this pull request Sep 7, 2019
Follow up of rails/rails#35093.

This PR suppresses the following warning when using Rails 6.0.

```console
% path/to/buoys
% bundle exec rake

(snip)

DEPRECATION WARNING: ActionView::Base instances should be constructed
with a lookup context, assignments, and a controller. (called from new
at /Users/koic/src/github.com/muryoimpl/buoys/test/buoys_buoy_test.rb:7)
```
koic added a commit to koic/buoys that referenced this pull request Sep 7, 2019
Follow up of rails/rails#35093.

This PR suppresses the following warning when using Rails 6.0.

```console
% path/to/buoys
% bundle exec rake

(snip)

DEPRECATION WARNING: ActionView::Base instances should be constructed
with a lookup context, assignments, and a controller. (called from new
at /Users/koic/src/github.com/muryoimpl/buoys/test/buoys_buoy_test.rb:7)
```
muryoimpl pushed a commit to muryoimpl/buoys that referenced this pull request Sep 8, 2019
Follow up of rails/rails#35093.

This PR suppresses the following warning when using Rails 6.0.

```console
% path/to/buoys
% bundle exec rake

(snip)

DEPRECATION WARNING: ActionView::Base instances should be constructed
with a lookup context, assignments, and a controller. (called from new
at /Users/koic/src/github.com/muryoimpl/buoys/test/buoys_buoy_test.rb:7)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants