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

Various fixes for Rails 6 #2100

Merged
merged 1 commit into from Mar 18, 2019
Merged

Conversation

sebjacobs
Copy link
Contributor

@sebjacobs sebjacobs commented Mar 15, 2019

Whilst investigating a Rails 6 upgrade (6.0.0.beta3) I discovered the following issues:

  • The ActionView::Template#formats method has been deprecated [1]
  • The Template handler API has changed [2] (already fixed on 4-0-dev)

This branch attempts to fix these issues whilst retaining support for Rails <= 5.2.

[1] https://www.github.com/rails/rails/commit/ca5e23ed4d8
[2] https://www.github.com/rails/rails/commit/28f88e0074

@JonRowe
Copy link
Member

JonRowe commented Mar 15, 2019

Hi, thanks for this, Rails 6 support work is on going in 4-0-dev so you need to target that, your second commit isn't necessary as that fix has already been done, although I don't think we've seen the formats issue before.

@JonRowe JonRowe changed the base branch from master to 4-0-dev March 15, 2019 18:54
@JonRowe
Copy link
Member

JonRowe commented Mar 15, 2019

I suggest you rebase if you can!

@sebjacobs
Copy link
Contributor Author

Argh ok sorry about that I hadn't spotted that branch. I have rebased as requested.

Thanks for taking a look!

@@ -56,7 +56,7 @@ def self.nullify_template_rendering(templates)
template.identifier,
EmptyTemplateHandler,
:virtual_path => template.virtual_path,
:format => template.formats
:format => template.respond_to?(:format) ? template.format : template.formats
Copy link
Member

Choose a reason for hiding this comment

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

Great, is this a Rails specific or object specific? e.g. will we encounter both methods in one version of Rails? If so we prefer conditionally defining a method to extract this to save runtime conditionals.

Copy link
Contributor Author

@sebjacobs sebjacobs Mar 15, 2019

Choose a reason for hiding this comment

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

template.formats is deprecated in Rails 6, so we could rely on the Rails version instead, perhaps something like this?:

def self.template_format(template)
  if Rails::VERSION::STRING >= '6'
    template.format
  else
    template.formats
  end
end

Copy link
Member

Choose a reason for hiding this comment

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

Right so if this is Rails 6 only we'd typically do:

if Rails::VERSION::STRING >= '6'
  def self.template_format(format)
    template.format
  end
else
  def self.template_format(format)
    template.formats
  end
end

Copy link
Contributor Author

@sebjacobs sebjacobs Mar 15, 2019

Choose a reason for hiding this comment

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

That makes sense, thanks @JonRowe!

@sebjacobs
Copy link
Contributor Author

sebjacobs commented Mar 18, 2019

I have fixed up the suggested changes in (
81fdc8a)

In Rails 6 the `ActionView::Template#formats` method has been deprecated
[1] and replaced with `ActionView::Template#format` method.

I have attempted to retain support for Rails <= 5.2.

[1] https://www.github.com/rails/rails/commit/ca5e23ed4d8
@JonRowe JonRowe merged commit ddc2938 into rspec:4-0-dev Mar 18, 2019
@JonRowe
Copy link
Member

JonRowe commented Mar 18, 2019

Thanks!

@benoittgt
Copy link
Member

Thanks a lot @sebjacobs

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.

None yet

3 participants