Skip to content

Refactor Request.closed#312

Draft
tom93 wants to merge 12 commits intomasterfrom
rails-5-scope-closed-where
Draft

Refactor Request.closed#312
tom93 wants to merge 12 commits intomasterfrom
rails-5-scope-closed-where

Conversation

@tom93
Copy link
Contributor

@tom93 tom93 commented Jul 3, 2025

@bagedevimo I saw your "TODO(Rails5)" and tried to make the change but got errors; I'm creating this PR as a reminder (feel free to close if it's not useful).

bagedevimo and others added 12 commits July 3, 2025 23:23
Rails 5 removed these features from core, instead using a seperate gem.

rails/rails#21161
assert_template has been removed (extracted?) to a new gem,
rails-controller-test. We use this all over the place, so this should
just work.

> Failure/Error: expect(response).to render_template("pages/forum")
> NoMethodError:
> assert_template has been extracted to a gem. To continue using it,
>		add `gem 'rails-controller-testing'` to your Gemfile.
Simple form added support for Rails 5 in 3.2.1, but only actually fixed
bugs introduced by Rails 5 in 3.3.1:

https://github.com/heartcombo/simple_form/blob/main/CHANGELOG.md#331
This presumably used to work in the prior versions of Rails or
rails-controller-test, but no longer does.
The environment configuration in config/environments/*.rb hasn't been
updated to the rails defaults with out modifications, as there are a lot
of individual changes and this is best left for future discussions and
changes.

Especially in the context of another ~8 rails versions to
upgrade to get anywhere near the latest, there will be a lot of churn in
those files and minimising that where possible is the goal here.
Rails 5 changes the ruby schema format to exclude the indexes from the
table creates, and a few other minor changes. This final is completely
generated, so it's not really something we need to review, which is why
I put it in a separate commit.
The default will change to :debug in Rails 5, and then back to :info
in Rails 6.1. Set it to :info explicitly to get stable behaviour.

(The comment mentioning personally-identifiable information is copied
from the Rails 8 template.)

References:

https://guides.rubyonrails.org/v5.0.0/upgrading_ruby_on_rails.html#production-log-level
https://www.github.com/rails/rails/pull/39707
@bagedevimo
Copy link
Contributor

Most likely I got the syntax wrong or the version that supports .or() wrong. Good stuff.

@Holmes98
Copy link
Member

Holmes98 commented Jul 5, 2025

https://stackoverflow.com/questions/7054188/is-it-possible-to-negate-a-scope-in-rails

Seems that you can't negate a scope with where.not, so might have to be something like this:

  scope :status_not_pending, -> { where.not(status: STATUS[:pending]) }
  scope :closed, -> { status_not_pending.or(past_expiry) }

(also I think the comment should've used status_pending rather than pending)

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