Included tests for ConferenceDomainsService
This commit is contained in:
parent
bc17f210a6
commit
33c5ab9938
2 changed files with 29 additions and 2 deletions
|
|
@ -12,11 +12,10 @@ class ConferenceDomainsService
|
|||
# * +false+ -> If the custom domain does not have a CNAME record for the hosted version
|
||||
def check_custom_domain
|
||||
require 'resolv'
|
||||
|
||||
unless ENV['OSEM_HOSTNAME'].nil?
|
||||
cname_record = Resolv::DNS.new.getresources(@conference.custom_domain, Resolv::DNS::Resource::IN::CNAME)
|
||||
if cname_record.present?
|
||||
return ENV['OSEM_HOSTNAME'] == Resolv::DNS.new.getresources(custom_domain, Resolv::DNS::Resource::IN::CNAME).first.name.to_s
|
||||
return ENV['OSEM_HOSTNAME'] == cname_record.first.name.to_s
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
|
|
|||
28
spec/services/conference_domains_service_spec.rb
Normal file
28
spec/services/conference_domains_service_spec.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ConferenceDomainsService do
|
||||
let!(:conference) { create(:conference, custom_domain: 'demo.osem.io') }
|
||||
subject { ConferenceDomainsService.new(conference: conference) }
|
||||
|
||||
describe 'return correct value' do
|
||||
before do
|
||||
ENV['OSEM_HOSTNAME'] = 'osem-demo.herokuapp.com'
|
||||
end
|
||||
|
||||
it 'returns true if cname record matches the domain name' do
|
||||
expect(subject.check_custom_domain).to eq true
|
||||
end
|
||||
|
||||
it 'returns feature disabled if OSEM_HOSTNAME is not present' do
|
||||
ENV['OSEM_HOSTNAME'] = nil
|
||||
|
||||
expect(subject.check_custom_domain).to eq '--feature disabled--'
|
||||
end
|
||||
|
||||
it 'returns false if cname record is not present' do
|
||||
conference.update_attribute(:custom_domain, 'osem-demo.herokuapp.com')
|
||||
|
||||
expect(subject.check_custom_domain).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue