Rails 5 ensures compatibility with Rack frameworks

Mohit Natoo

By Mohit Natoo

on June 30, 2016

This blog is part of our  Rails 5 series.

Before Rails 5, there were errors in running integration tests when a Rack framework like Sinatra, Grape etc. were mounted within Rails with a motive of using its session.

Problems were reported at many places including github gists and stackoverflow regarding an error which was of the following form.

2NoMethodError (undefined method `each' for #<ActionDispatch::Request::Session:0x7fb8dbe7f838 not yet loaded>): rack (1.5.2) lib/rack/session/abstract/id.rb:158:in `stringify_keys'
3rack (1.5.2) lib/rack/session/abstract/id.rb:95:in `update' rack (1.5.2) lib/rack/session/abstract/id.rb:258:in `prepare_session'
4rack (1.5.2) lib/rack/session/abstract/id.rb:224:in `context' rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'

As we can see, the error occurs due to absence of method each on an ActionDispatch::Request::Session object.

In Rails 5, each method was introduced to ActionDispatch::Request::Session class making it compatible with Rack frameworks mounted in Rails and hence avoiding the above mentioned errors in integration testing.

If you liked this blog, you might also like the other blogs we have written. Check out the full archive.

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, React.js, React Native, remote work,open source, engineering & design.