Last active
October 31, 2021 02:36
-
-
Save Lordnibbler/7539651 to your computer and use it in GitHub Desktop.
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
| class DomainConstraint | |
| def initialize(domain) | |
| @domains = [domain].flatten | |
| end | |
| def matches?(request) | |
| request.subdomain.present? ? domain_to_match = request.subdomain + "." + request.domain : domain_to_match = request.domain | |
| @domains.include? domain_to_match | |
| end | |
| end |
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
| require 'spec_helper' | |
| describe "Something", js: true do | |
| it "is a fake spec" do | |
| visit foo_path(subdomain: 'another') | |
| end | |
| end |
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
| MyApp::Application.routes.draw do | |
| constraints DomainConstraint.new(['subdomain.domain.com', 'another.domain.com']) do | |
| resources :foo | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment