This entry is the 22nd day of iCARE Advent Calender 2020.
Nice to meet you. I'm yotuba, a server-side engineer of iCARE Co., Ltd. This time it's a company advent calendar, so I'd like to write a memorandum about the Rails version upgrade that I'm doing at work recently.
Currently, our service called Carely is running on Rails 5.0.7.2, and there was news that Rails released 6.1 recently, but the version has become a little old, so we are updating this time. I am working with technical advisor willnet. (It's wonderful to have a technical advisor ...)
I'm just getting started, but in this article I'd like to share some of the issues I encountered and the tests I failed while trying to upgrade to 5.1.7.
First of all, I cut a branch and turned CI. That reduced the number of tests, but a closer look narrowed down the causes.
When upgrading the version, first of all, it is written in the Release Notes of this Rails guide, so I think it is best to refer to that.
render text First is a simple notation. Changed the option passed to send plaintext text to the browser without markup when rendering to use the: plain option instead of: text. render text: "hoge" ↓ render plain: "hoge" Changed to.
Ruby's Strip method can remove whitespace before and after a string, but what should I do when trying Trim (double-byte space or BOM)?
If you google, the blog of here will appear. Code that gsubs ActiveSupport :: Multibyte :: Unicode :: LEADERS_PAT and ActiveSupport :: Multibyte :: Unicode :: TRAILERS_PAT to remove double-byte spaces and BOM.
Quote
str.gsub(ActiveSupport::Multibyte::Unicode::LEADERS_PAT, '').gsub(ActiveSupport::Multibyte::Unicode::TRAILERS_PAT, '')
However, since here that was up to 5.0 has disappeared from 5.1, it will not work in later versions of Rails.
In the case of code that uses the Rails API, the code itself may disappear with the version upgrade, so I would like to pay attention to the version that is also used in the information that came out in this area.
unable to convert unpermitted parameters to hash The error is that parameters that are not allowed cannot be hashed. Here
What kind of code this happened is the code that tried to pass the parameters to the URL.
There was a part that used a method called hoge. To_param to pass it to the URL, but it was an error that occurred because this hoge was not allowed. (This is the code that doesn't work from 5.1)
So, by permitting the inside of hoge, it came to work.
There should be a situation where you want to request the json format in the request spec and test the returned json.
get hoge_path(hoge_id: hoge.id, :format => :json)
I had code like this, but: format =>: json I can't understand how to write.
This is the official document that you should see when you are in trouble. Take a look at the official Rspec documentation for here. Requesting a JSON response! There was a place.
I changed it to the code with headers and solved it safely.
It was written in the code that I wanted to redirect to the previous page redirect_to :back Has stopped working. You should also check the Official Document.
I changed the writing style to "I made a sound to solve it.
By default the id column is created with an int, but since 5.1 this has been changed to a big int. Here
If the type is different, foreign key constraints cannot be pasted, so problems will occur if a new table is created in 5.1 or later and one created in 5.0 or earlier (int and bigint) are mixed. Our company is a BtoB service, and there is less concern about id depletion compared to high-load services, so there is a balance with development man-hours, etc., so we will keep making int type as it is (run migration file at 5.0) All you have to do is).
What did you think. This time, I wrote an article focusing on the problems that occurred in the product that is actually running, not all of the version upgrades.
Finally, we are looking for engineers! If you are interested, please apply from here!
Tomorrow 23rd is [Creating variable text tabs with Adobe XD components] by zouzei8to10. looking forward to.
Recommended Posts