Skip to content

Instantly share code, notes, and snippets.

@dapi
Created May 14, 2018 09:15
Show Gist options
  • Select an option

  • Save dapi/34388ffbf65bb784fd095b021d363ec0 to your computer and use it in GitHub Desktop.

Select an option

Save dapi/34388ffbf65bb784fd095b021d363ec0 to your computer and use it in GitHub Desktop.
# Это такой замысловатый спосбо добавить поддомен в запрос для 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