Conversation
This is a first stepping stone to going up to rails 5. We've run `rake rails:update` to standardise config files and make sure we have all the new initializers too.
This avoids a deprecation warning from minitest about preferring to use assert_nil when comparing against nil. It also makes the users in test scenarios more like real users who will have emails.
13.0.0 is the version with rails 5 compatibliity, but the latest (13.2.0) doesn't have anything dangerous to us.
Latest is 1.x but that introduces many changes we don't want to deal with and v0.17 is enough for rails 5 compatibility. This does introduce a deprecation warning about mongoid functionality being extracted to a separate gem in the next release of kaminari, but it's a one-time message at startup so I think we can live with it for now. It'll serve as a pointer for future work when we do decide to upgrade to kaminari 1.x.
Mongoid 6.x brings rails 5 compatibility so we'll want to jump to that eventually, but we wanted to do it slowly.
We need to upgrade these in lockstep because mongoid 5 doesn't support rails 5 and mongoid 6 doesn't support rails 4. We've run `rake rails:update` to get new config file details and also compared with railsdiff to get details not handled by the update script.
We don't have any assets in this app because it's an API app. We don't include sprockets and in rails 5 this means we don't have the `config.assets` object to configure. Much like the default active_record configuration options, we comment these assets ones out instead of removing them entirely to make it easier to update in the future.
31a8139
to
fd9a6d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor suggestions. LGTM 👍
app/models/need.rb
Outdated
@during_record_revision_callback = 'yes' | ||
record_revision "update" | ||
@during_record_revision_callback = nil | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could wrap this behaviour?
prevent_additional_callbacks { record_revision "create" }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes; good call. Makes it more obvious, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a rebase.
app/models/need_revision.rb
Outdated
@@ -8,7 +8,7 @@ class NeedRevision | |||
|
|||
default_scope -> { order_by(:created_at.desc) } | |||
|
|||
belongs_to :need | |||
belongs_to :need, touch: false, inverse_of: :revisions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you take the touch: false
away, does that re-introduce the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I dunno. I'll try it and see (I was trying all the things in one go). It'll be better to introduce the smallest change that avoids the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a rebase - it all still worked without touch: false
so I dropped it.
Gemfile
Outdated
@@ -34,7 +34,7 @@ else | |||
gem 'gds-sso', '13.2.0' | |||
end | |||
|
|||
gem 'airbrake', '~> 4.3.4' | |||
gem 'airbrake', github: 'alphagov/airbrake', branch: 'silence-dep-warnings-for-rails-5' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if the intention is for this branch to stay around for a while? I wonder if we could wrap its silencing behaviour in something that checks if the Rails version is 5 and then merge it into master?
This is probably out of scope for this upgrade, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a stopgap until we move off errbit and onto something else entirely. Be totally worth having this discussion in a wider forum though.
FYI, I think you rebase-pushed so a couple of comments are showing as 'outdated' |
fd9a6d8
to
575fdd9
Compare
After upgrading to rails 5 and mongoid 6 saving a need caused an infinite callback loop. Saving a Need causes one of the after_create/after_update callbacks that build a new NeedRevision to run. Saving this object in turn causes the need itself to re-save (perhaps as part of a touch event?). This then triggers another after_update callback to run and build a new NeedRevision, which in turn ... To avoid this we make sure we set inverse_of arguments so we are always dealing with the same objects and then add guard clauses round the call to create the NeedRevision in Need. If we're alread inside a callback we won't run it again. Once we successfully create the NeedRevision we discard the guard and fall out of the callback.
This silences deprecation warnings for rails 5.
The `render :nothing` method is deprecated in favour of `head` in Rails 5. We also prefer to use names instead of http status codes to make it easier to understand what's going on.
This means we make sure we use the strong parameters API where we can, and also that we call `.to_h` on the outcome of using the API to convert from the rails 5 parameter object to the hash we used to get. We also have to deal with differences for how empty params are parsed. Before rails 5 a query string like `?foo=&bar=baz` would be parsed into `{ foo: nil, bar: 'baz' }`, but in rails 5 it is parsed into `{ foo: '', bar: 'baz' }`. Ultimately this means checking values with `.present?` instead of relying on nil checks.
Instead of `post :action, param_1: value_1, param_1: value_2` rails 5 prefers `post :action, params: { param_1: value_1, param_2: value_2 }` which is more explicit.
In Rails 5 belongs_to associations in activerecord have a default validation to make sure the object at the other end of the association is present. Mongoid 6 also introduces this functionality for parity with activerecord. We didn't have this validation before, and it's not clear to me if we should have it, but it's easy enough to disable the functionality in an intializer.
Nothing controversial, mostly spacing.
We can use the buildProject() script without specifying all our own things. Also we delete the scripts for the old jenkins infrastructure.
575fdd9
to
6052ad9
Compare
@tuzz fixed what you said in a rebase; if you want to re-look. |
Tested the branch on integration and checked that whitehall can still show needs in the admin. I can't test metadata-api as it's broken. |
Best reviewed commit-by-commit.
Still one dep warning at startup for kaminari, but doing the jump to 1.0 to avoid doesn't seem worth it.
For: https://trello.com/c/u8hJdr3O/161-migrate-to-rails-5-need-api