Skip to content

Instantly share code, notes, and snippets.

@dapi
Last active December 10, 2019 07:26
Show Gist options
  • Select an option

  • Save dapi/2abc14cd59e2e35f2cba71c2485731a2 to your computer and use it in GitHub Desktop.

Select an option

Save dapi/2abc14cd59e2e35f2cba71c2485731a2 to your computer and use it in GitHub Desktop.
Add request subdomain for rspec
# Это такой замысловатый спосбо добавить поддомен в запрос для rspec
#
# Использовать:
#
# RSpec.configure do |config|
# config.include ProcessWithRequestSubdomain, type: :controller
#
module ProcessWithRequestSubdomain
extend ActiveSupport::Concern
module ClassMethods
module WithSubdomain
def process(action, *args)
if kwarg_request?(args)
args.first.deep_merge! params: { subdomain: request.subdomain } if request.subdomain.present?
super(action, *args)
elsif args.count == 1
args[0] = { method: args[0], params: { subdomain: request.subdomain } } if request.subdomain.present?
super(action, *args)
else
args[1] ||= {}
args[1][:subdomain] = request.subdomain if request.subdomain.present?
super(action, *args)
end
end
end
def new(*)
super.extend(WithSubdomain)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment