Skip to content

Instantly share code, notes, and snippets.

@PikachuEXE
Last active January 1, 2016 07:09
Show Gist options
  • Save PikachuEXE/8110084 to your computer and use it in GitHub Desktop.
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)
# 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