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

Allow Rails 6.1 #2047

Merged
merged 12 commits into from Sep 12, 2021
Merged

Allow Rails 6.1 #2047

merged 12 commits into from Sep 12, 2021

Conversation

robinboening
Copy link
Contributor

@robinboening robinboening commented Mar 10, 2021

For now, this PR is supposed to be a draft for investigating the extend of supporting Rails 6.1 and eventually getting it ready to be merged into main.

@robinboening
Copy link
Contributor Author

robinboening commented Mar 11, 2021

Unfortunately there are some failing tests. I was looking into it focusing on the recurring undefined method prefix_locale? error and I went deep into a rabbit hole 🕳️ 🐇

Rails 6.1 includes changes related to controller helper methods which is causing the error. I opened an issue in the rspec-rails repo as they might need to adapt to the changes as well. Let's see if it can be solved easily.

@robinboening robinboening force-pushed the rails_6_1 branch 2 times, most recently from de53793 to 74f23b6 Compare March 13, 2021 10:56
@robinboening robinboening force-pushed the rails_6_1 branch 2 times, most recently from 8da0726 to 6b3eb00 Compare April 24, 2021 11:28
@robinboening robinboening force-pushed the rails_6_1 branch 2 times, most recently from 5496b17 to fdf8c31 Compare May 13, 2021 11:58
@tvdeyen tvdeyen marked this pull request as draft May 13, 2021 12:29
@tvdeyen
Copy link
Member

tvdeyen commented May 13, 2021

@robinboening used the GH Draft feature to note that this PR is still WIP. I hope you don't mind :)

@tvdeyen
Copy link
Member

tvdeyen commented Jul 11, 2021

Now that a shoulda-matchers version has been released and merged in #2161 that supports Rails 6.1 and Ruby 3 maybe some of the failing specs pass now? A rebase with latest main will tell

@afdev82
Copy link
Contributor

afdev82 commented Jul 22, 2021

Any news on that? I could rebase myself, but I don't want to "steal" others work :P

@robinboening robinboening force-pushed the rails_6_1 branch 2 times, most recently from 1162710 to a4c301e Compare August 7, 2021 19:59
@robinboening
Copy link
Contributor Author

@tvdeyen @afdev82 I keep rebasing this branch every here and then. I am currently using this branch on a project I am working on and it works well so far (not in production yet).

I just rebased again.

@robinboening
Copy link
Contributor Author

robinboening commented Aug 7, 2021

As far as I can tell almost all the tests are failing for the same reason. In some places in the specs we inject helper methods to the controller. This pattern doesn't seem to work any longer with Rails 6.1, very likely because the view context is already created at the time when the include is sent to the controller.

@robinboening robinboening force-pushed the rails_6_1 branch 3 times, most recently from 5bcd781 to 5fcf414 Compare August 9, 2021 07:41
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

What baffles me are that there are specs failing for Rails 6.0 as well that are passing in main, so there might be another issue?
Reagarding the view specs we might need to stub even more helper methods? Maybe Rails 6.1 stopped injecting any helpers into the view context? The same might be true with the helper specs.

spec/features/admin/tinymce_feature_spec.rb Show resolved Hide resolved
@robinboening robinboening force-pushed the rails_6_1 branch 2 times, most recently from 2536217 to 8477593 Compare August 17, 2021 12:01
@tvdeyen
Copy link
Member

tvdeyen commented Aug 28, 2021

@robinboening I pushed a fix for the picture ingredient editor spec. 0a485ff

@tvdeyen
Copy link
Member

tvdeyen commented Aug 28, 2021

UPDATE

Three failing specs for 6.1

  1. spec/models/alchemy/element_spec.rb:1015
    Fails because the hidden element that should be excluded from the collection is now included (even the SQL is correct, WAT?)
  2. spec/models/alchemy/page_version_spec.rb:78
    Fails because the record is not touched anymore. Even rewriting it to an expect {}.to change {} does not help.
  3. alchemy/admin/attachments/show.html.erb
    Works locally

One failing spec in Rails 6.0

  1. spec/views/admin/attachments/show_spec.rb:10
    Same as with Rails 6.1 it works locally

As always no clues in the change logs. And why is a 6.0 related spec failing.
Rails x.1 releases. Fun since v2.1. The tradition lives on. 🙄

@robinboening
Copy link
Contributor Author

FYI: I just rebased with current main branch.

@robinboening
Copy link
Contributor Author

A couple of weeks back I've added a commit just for testing if it fixes some helper tests. It did if I remember correctly, but it is considered a hacky approach and should be avoided as John Hawthorn states rails/rails#40204 (comment)

I haven't had the time to drill deeper into that so I haven't found a better solution.

@tvdeyen
Copy link
Member

tvdeyen commented Sep 2, 2021

A couple of weeks back I've added a commit just for testing if it fixes some helper tests. It did if I remember correctly, but it is considered a hacky approach and should be avoided as John Hawthorn states rails/rails#40204 (comment)

I haven't had the time to drill deeper into that so I haven't found a better solution.

@robinboening I added two commits 2acb952 and 0915db8

that made that not necessary anymore

@tvdeyen
Copy link
Member

tvdeyen commented Sep 2, 2021

I fixed a couple of specs, but there is one bug in Rails:

In spec/models/alchemy/element_spec.rb:1030 this is the SQL (postgres) generated

SELECT "alchemy_elements".* FROM "alchemy_elements" WHERE "alchemy_elements"."parent_element_id" = 91 AND "alchemy_elements"."public" = TRUE ORDER BY "alchemy_elements"."position" ASC;

This is the collection returned by Rails

[#<Alchemy::Element:0x00005621e3a0ae50
  id: 92,
  name: "article",
  position: 1,
  public: true,
  folded: false,
  unique: false,
  created_at: Thu, 02 Sep 2021 07:56:42.502623000 UTC +00:00,
  updated_at: Thu, 02 Sep 2021 07:56:42.502623000 UTC +00:00,
  creator_id: nil,
  updater_id: nil,
  parent_element_id: 91,
  fixed: false,
  page_version_id: 196,
  tag_names: nil>,
 #<Alchemy::Element:0x00005621e2cf3e60
  id: 93,
  name: "article",
  position: 2,
  public: false,
  folded: false,
  unique: false,
  created_at: Thu, 02 Sep 2021 07:56:42.507076556 UTC +00:00,
  updated_at: Thu, 02 Sep 2021 07:56:42.507076556 UTC +00:00,
  creator_id: nil,
  updater_id: nil,
  parent_element_id: 91,
  fixed: false,
  page_version_id: 196,
  tag_names: nil>]

You clearly can see that Rails is not respecting the public = TRUE from the SQL and returning a non public element.

Thank you, Rails!

@tvdeyen
Copy link
Member

tvdeyen commented Sep 12, 2021

Fixed all specs besides one. The spec/views/admin/attachments/show_spec.rb fails if we run all specs, but passes if we run it in isolation. Meaning we somehow mutate global state somewhere.

This feature spec failed with Rails 6.1 as it was defaulting to example.com instead of 127.0.0.1.

Setting `asset_host` inside the test is more explicit as it was before and reflects what an actual app does.
@tvdeyen tvdeyen marked this pull request as ready for review September 12, 2021 19:09
@tvdeyen tvdeyen force-pushed the rails_6_1 branch 2 times, most recently from 27024e0 to 6001d60 Compare September 12, 2021 19:18
robinboening and others added 10 commits September 12, 2021 21:27
Those helpers are not included by Rails anymore.
Since a view spec is a unit test we need to stub/include
everything we need on ourselves.
First create elements with the page_version (the direct relation)
and not a page (an indirect join via the page_version).

Also reload element in nested_elements spec.
Somehow this is now necessary in Rails 6.1.
Instead of globally including a module into the tet controller
we stub the one method the spec uses
It is not necessary. The specs pass without globally including
a module in the test controller
Instead of expecting that rails calls a method on the receiver
we expect that the updated_at time has changed.
Not everybody is using a db running on host but on a socket instead.
@tvdeyen
Copy link
Member

tvdeyen commented Sep 12, 2021

Wohooo. We got it. Thanks @robinboening for the initial work.

@tvdeyen tvdeyen merged commit f309703 into AlchemyCMS:main Sep 12, 2021
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