No release in over 3 years
Low commit activity in last 3 years
rails5_xhr_update is a program that can be used to help convert from the ``xhr :get, :action`` test syntax used in rails prior to Rails 5, to the Rails 5 syntax: ``get :action, xhr: true``.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.0
~> 12.0

Runtime

~> 0.2
 Project Readme

Gem Build Status

rails5_xhr_update

rails5_xhr_update is a program that can be used to help convert from the Rails 4 xhr test syntax, like the following:

xhr :get, images_path, limit: 10, sort: 'new'

to the equivalent Rails 5 syntax:

get images_path, params: { limit: 10, sort: 'new' }, xhr: true

Furthermore, xhr calls using session, or flash parameters are also supported. The following call:

xhr :get, images_path, { id: 1 }, { user_ud: 2 }, success: 'logged in'

is translated into:

get images_path, flash: { success: "logged in" }, params: { id: 1 }, session: { user_ud: 2 }, xhr: true

Installation

To install rails5_xhr_update run:

gem install rails5_xhr_update

Running

Execute this program via:

rails5_xhr_update --write FILE...

Omit --write if you don't want to write back to the files, and instead output to STDOUT.

Consider running the following to locate and run against files with potential issues:

git grep -l "xhr :" | rails5_xhr_update --write

See Also

Handling non-XHR cases

As part of the upgrade to Rails 5 one also needs to use keyword arguments for params and headers when calling these request test methods. Fortunately, rubocop can help handle that conversion:

rubocop -a --only Rails/HttpPositionalArguments PATH

Supporting Rails 5 syntax in Rails 4

Finally, with your project, it might be difficult to do all this conversion work at once. You might instead, prefer to remain on Rails 4, but be forward compatible with Rails 5. And you might want to output a DeprecationWarning, or even raise an exception when attempting to use the older syntax. To help with that please see our rails-forward_compatible_controller_tests gem.