This commit is contained in:
Zachary Crockett 2024-01-02 12:52:07 -08:00 committed by GitHub
commit 76deaac3c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -37,9 +37,10 @@ class Config
hostname = `hostname`.chomp
hostname = 'localhost' if hostname.empty?
return @hostname = hostname if hostname == 'localhost'
components = hostname.split('.')
return @hostname = hostname if components.length == 1
@hostname = hostname.split('.')[-2..-1].compact.join('.')
@hostname = components[-2..-1].compact.join('.')
end
def self.author

View File

@ -44,6 +44,12 @@ describe Config do
_(Config.hostname).must_equal 'localhost'
end
it 'correctly interprets a single word' do
Config.instance_variable_set(:@hostname, nil)
Config.expects(:`).with('hostname').returns('example')
_(Config.hostname).must_equal 'example'
end
it 'correctly interprets a subdomain' do
Config.instance_variable_set(:@hostname, nil)
Config.expects(:`).with('hostname').returns('example.com')