Last active
December 10, 2019 07:26
-
-
Save dapi/2abc14cd59e2e35f2cba71c2485731a2 to your computer and use it in GitHub Desktop.
Add request subdomain for rspec
This file contains hidden or 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
| # Это такой замысловатый спосбо добавить поддомен в запрос для 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