Sunday, September 18, 2016

This Week in Rails: šŸ« Your Golden Ticket to the Chocolate Factory šŸ«

Posted by jonatack

Jon here welcoming you to This Week in Rails!

Today weā€™ll be touring the wondrous Ruby on Rails chocolate factory to see how its marvelous candy, consumed by web apps and developers everywhere, is made and tested.

Golden tickets in hand? Letā€™s go!

Welcome! šŸŽ©

This Weekā€™s Rails Contributors

This week, 26 fabulous oompa-loompas concocted improvements to make your favorite candy even more delicious ā€“ including one for the first time!

Fix Bundler warnings about insecure github sources

If you upgrade to bundler 1.13 and use github options to specify gem sources in your Gemfile, youā€™ll see warnings when running bundle commands.

To fix, you can run bundle config github.https true on the command line.

Or if you donā€™t control the environment the Gemfile will execute in, you can add this to the Gemfile, like Rails now does:

git_source(:github) |repo_name| do
Ā  ā€œhttps://github.com/#{ā€‹repo_name}ā€‹.gitā€
end

Backported to 5-0-stable.

Improving the chocolate šŸ©šŸ«

Puma docs: Disconnect connections before preloading

This pull request added documentation for config/puma.rb to recommend closing database connections if preloading an application that uses Active Record. See the discussions in the pull request and in puma/puma#1001 for more.

Improve assert_response helper

To improve productivity when writing tests, if an assert_response test fails, Rails nows outputs the actual response body if itā€™s not too large (less than or equal to 500 chars).

Fixing bugs in the candy šŸ¬

Clear attribute changes after touching

Following-up on a very good bug report, this PR fixed a Rails 5 regression so that calling ActiveRecord#touch when using optimistic locking once again leaves the model in a non-dirty state with no attribute changes.

Prevent mutation of constants

Tests using ActionDispatch::IntegrationTest were failing when run after any controller test that modified request.session_options. It turned out thatĀ  ActionController::TestSession::DEFAULT_OPTIONS was being mutated, and as a result, Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS also, which made integration tests inherit that value and fail.

This pull request dupā€™ed the AC default options constant to prevent mutation, and a pull request to Rack was merged to freeze the Rack default options constant and avoid the issue in the future.

Force correct namespace with TransactionManager

This pull request fixed issue #26441: ā€œNameError: uninitialized constant AR::ConnectionAdapters::DatabaseStatements::TransactionManager when calling reset_transactionā€.

How to contribute? Some examples from this week šŸ°

Fix warnings in the test suite

Running the Rails test suite can be a great way to uncover minor issues to fix. This pull request addressed 2 warnings in the test suite that arose simply from not wrapping a method argument in parentheses.

Add missing tests

Noticing that there were no tests for when ActiveRecord::Enum#enum was called with a specific suffix, this contributor added some.

Improve the Rails Guides

Better documentation is always welcome. After seeing issue #26286, this contributor helpfully improved the documentation for the render partial ā€˜asā€™ option.

Add a bug report template

The commit message says it all: ā€œI created this for testing migrations in isolation and thought it would be helpful to others in the future to avoid having to dig through the Rails migration tests.ā€

Remove duplicate code

This elsif branch was a duplicate of the else branch just after it. Youā€™ll never believe what happened next šŸ˜®.

How to inherit a world of unlimited imagination šŸ­

Thatā€™s it for todayā€™s tour, but the true journey has only just begun.

Starting today, choose any file in the Rails codebase and read it.

Pick an open issue on the master branch, and try to reproduce the bug using the Rails bug report templates.

Go through the Contributing to Ruby on Rails Guide. Set up your Rails test environment.

Pick an open pull request and test it or review it.

Youā€™ll be surprised what baby steps like these can lead to!

Enjoy the wonderful chocolate ā€“ and see you next week.