Skip to content

Commit

Permalink
Allow domains in tenants TODO: tests TODO could be mistaken for neste…
Browse files Browse the repository at this point in the history
…d subdomains
  • Loading branch information
javierm committed Oct 9, 2022
1 parent 32239bc commit 02ef781
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Tenant < ApplicationRecord
uniqueness: true,
exclusion: { in: ->(*) { excluded_subdomains }},
format: { with: URI::DEFAULT_PARSER.regexp[:HOST] }
validates :subdomain, format: { without: /\./ }
validates :name, presence: true

after_create :create_schema
Expand Down Expand Up @@ -45,6 +44,8 @@ def self.current_host
def self.host_for(schema)
if schema == "public"
default_host
elsif schema.include?(".")
schema
elsif default_host == "localhost"
"#{schema}.lvh.me"
else
Expand Down
6 changes: 3 additions & 3 deletions spec/models/tenant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@
end
end

it "is not valid with nested subdomains" do
tenant.subdomain = "multiple.sub.domains"
expect(tenant).not_to be_valid
it "is valid with domains" do
tenant.subdomain = "my.domain"
expect(tenant).to be_valid
end

it "is not valid with an invalid subdomain" do
Expand Down

0 comments on commit 02ef781

Please sign in to comment.