RefugeRestrooms / refugerestrooms

REFUGE restrooms indexes and maps safe restroom locations for trans, intersex, and gender nonconforming individuals.
http://www.refugerestrooms.org
GNU Affero General Public License v3.0
894 stars 261 forks source link

[Gemfile] Update to (at least) Rails 5.1.6 #497

Closed DeeDeeG closed 5 years ago

DeeDeeG commented 6 years ago

(Note for Hacktoberfest participants: Upgrading Rails is usually a complex, multi-stage process. But it is important to keep a web app up-to-date with recent software that has received security updates and other improvements. Here, the process of updating Rails is laid out into all of the individual stages, so anyone can try to complete the upgrade. I am not expecting this to be easy, but hopefully it will be somewhat educational to go through this process. Don't worry about it if you get stuck. We can help you out if you have any questions. Or feel free to skip this and look at our other issues!)

Getting started:

Updating the Gemfile

As a warming-up exercise, update Gemfile so that the line for the rails gem ("gem 'rails', '5.1.4'") is updated to say 5.1.6 instead of 5.1.4.

This is the basic first step. To really complete the upgrade, we will have to start over, but it's impossible to complete this upgrade without being comfortable updating the Gemfile.

Moderate Completion:

Obtaining an updated Gemfile.lock using a Docker container

Start over with a Gemfile where Rails has not been updated.

Set up a Docker container running the Refuge Restrooms web app, by following along with CONTRIBUTING.md

Then, start an interactive terminal/shell session on the Docker container, by running docker-compose run web bash.

Next, update Gemfile as described above in the "Getting started" section.

Then, in the interactive terminal/shell session, install the updated Rails version (and update Gemfile.lock) by running this command: bundle update rails.

One step further:

Solving dependency conflicts in Gemfile / Gemfile.lock

When you run bundle update rails, there may be error messages about conflicts between different required versions of the same gems. To solve these, you will need to update Gemfile so that it has a set of gems where none of the version, or their requirements, are in conflict. The specific error messages will tell you what gems, including dependencies, are in conflict; The error messages will also tell you what range of version numbers are acceptable for those gems.

(Bonus tip: Instead of updating the Gemfile, sometimes you can list all gems that need updating in a bundle update command, like so: bundle update rails grape active-admin [more gems here]. You may still need to edit the Gemfile in a place or two, but this way can result in a much smaller set of changes to the Gemfile.)

To find the latest version numbers for all gems in the Gemfile, you can run bundle outdated. (See this documentation for more info on the bundle outdated command.)

As an alternative to running bundle outdated, you can look at all past version numbers of a given gem by visiting its page at rubygems.org. For example: https://rubygems.org/gems/rails

Other issues when updating rails

Sometimes there are updated or deprecated features in a new release of Rails. We are only updating to a "patch" level update in this case, so there shouldn't be any issues besides conflicts in the Gemfile. However, there might be other changes needed in our app, such as changes to our configuration files, or updates to the code we use. If you need help with any of these things, maintainers are here and glad to help. Just let us know with a comment on this issue, on your Pull Request, or on Slack.

Total completion (testing):

To truly finish this upgrade, we need to test that everything still works after the update.

With the Docker container up and running, run this command to execute our automated testing process: docker-compose run -e "RAILS_ENV=test" web rake db:test:prepare spec.

If there are errors, we usually have to go back and edit some configuration files, some code, or the Gemfile again.

Manual testing and finishing up

Sometimes automated testing doesn't give a full enough picture of what is working and what isn't. Ideally, when making a large update like moving to a new version of rails, we would also test manually. Here is how to test the site manually:

With the Docker container running our web app, visit 127.0.0.1:3000 in your web browser. You should see our home page.

(If you are using Docker Toolbox, for older Windows or Mac computers, try visiting 192.168.99.100:3000 instead.)

Then you can visit some pages (or ideally all of them) and click on the main functions of those pages to see if they work. You can submit a new restroom or rate restroom entries within the Docker container without issues, as this is totally separate from our live, "production" restrooms database at Refugerestrooms.org.

btyy77c commented 6 years ago

Just checking: is there a reason you want to upgrade to 5.1.6 and not 5.2.0 or 5.2.1?

DeeDeeG commented 6 years ago

Hi @btyy77c, thanks for stopping by this issue.

If you (or anyone else) wanted to target a new minor version of rails, that would be great! :+1:


Here was my reasoning for targeting the patch-level upgrade: My instinct was to try to make this a more bite-sized issue, so as to keep it within reach for more potential contributors.

(I think minor version upgrades are usually a bit more involved than patch version upgrades. We are a small team, and we often don't get a lot of time to devote to user-invisible back-end component upgrades. So any level of update that keeps us current and in security-patched, actively supported releases is genuinely helpful.)

(Also, I had remembered trying to upgrade to rails 5.2.x some time ago when some packages we rely on had dependency conflicts with Rails 5.2.x... Though now that you mention it, I think they must be compatible by now.)

Best Regards,

- DeeDeeG