Last active
January 1, 2016 07:09
-
-
Save PikachuEXE/8110084 to your computer and use it in GitHub Desktop.
The monkey patch to apply default parameters/default_url_options in RSpec (Rails 4 only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/rspec/rspec-rails/issues/255 | |
require 'active_support/concern' | |
module DefaultParams | |
extend ActiveSupport::Concern | |
included do | |
let(:default_params) { {locale: I18n.locale} } | |
def process_with_default_params(action, http_method = 'GET', *args) | |
parameters = args.shift | |
parameters = default_params.merge(parameters || {}) | |
args.unshift(parameters) | |
process_without_default_params(action, http_method, *args) | |
end | |
alias_method_chain :process, :default_params | |
end | |
end | |
RSpec.configure do |config| | |
config.include(DefaultParams, :type => :controller) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment