corrected tests for conference domains service
This commit is contained in:
parent
33c5ab9938
commit
686c0a41dc
3 changed files with 33 additions and 33 deletions
|
|
@ -1,6 +1,9 @@
|
|||
require 'resolv'
|
||||
|
||||
class ConferenceDomainsService
|
||||
def initialize(params)
|
||||
@conference = params[:conference]
|
||||
def initialize(conference, resolver = Resolv::DNS.new)
|
||||
@conference = conference
|
||||
@resolver = resolver
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -11,16 +14,7 @@ class ConferenceDomainsService
|
|||
# * +true+ -> If the custom domain has a CNAME record for the hosted version
|
||||
# * +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'] == cname_record.first.name.to_s
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
'--feature disabled--'
|
||||
cname_record = @resolver.getresources(@conference.custom_domain, Resolv::DNS::Resource::IN::CNAME)
|
||||
cname_record.present? ? ENV['OSEM_HOSTNAME'] == cname_record.name.to_s : false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,14 +17,15 @@
|
|||
%td
|
||||
= @conference.custom_domain
|
||||
%td
|
||||
- ck_domain = ConferenceDomainsService.new(conference: @conference).check_custom_domain
|
||||
- if ck_domain == true
|
||||
%span.glyphicon.glyphicon-ok
|
||||
- elsif ck_domain == false
|
||||
%span.glyphicon.glyphicon-remove
|
||||
- if ENV['OSEM_HOSTNAME'].present?
|
||||
- ck_domain = ConferenceDomainsService.new(@conference).check_custom_domain
|
||||
- if ck_domain
|
||||
%span.glyphicon.glyphicon-ok
|
||||
- else
|
||||
%span.glyphicon.glyphicon-remove
|
||||
- else
|
||||
%i
|
||||
= ck_domain
|
||||
feature disabled
|
||||
%td
|
||||
.btn-group
|
||||
= link_to 'Edit', admin_conference_conference_domains_edit_path(@conference.short_title),
|
||||
|
|
@ -67,7 +68,7 @@
|
|||
Pick a domain you want to host your conference on from a domain registrar or register it with a domain registrar.
|
||||
%li
|
||||
Add your own domain name to OSEM
|
||||
= link_to 'here', admin_conference_conference_domains_edit_path(id: @conference.short_title)
|
||||
= link_to 'here', admin_conference_conference_domains_edit_path(@conference.short_title)
|
||||
%li
|
||||
The last step is adding a CNAME record in your registrar’s DNS Settings.
|
||||
Different registrars have different ways of adding a CNAME record.
|
||||
|
|
|
|||
|
|
@ -1,28 +1,33 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ConferenceDomainsService do
|
||||
let!(:conference) { create(:conference, custom_domain: 'demo.osem.io') }
|
||||
subject { ConferenceDomainsService.new(conference: conference) }
|
||||
let(:conference) { create(:conference, custom_domain: 'demo.osem.io') }
|
||||
let(:resolver) { double('resolver') }
|
||||
let(:service) { ConferenceDomainsService.new(conference, resolver) }
|
||||
|
||||
describe '#check_custom_domain' do
|
||||
subject { service.check_custom_domain }
|
||||
let(:cname_record) { double(name: cname_domain) }
|
||||
|
||||
describe 'return correct value' do
|
||||
before do
|
||||
ENV['OSEM_HOSTNAME'] = 'osem-demo.herokuapp.com'
|
||||
allow(resolver).to receive(:getresource).with(conference.custom_domain, Resolv::DNS::Resource::IN::CNAME)
|
||||
.and_return(cname_record)
|
||||
end
|
||||
|
||||
it 'returns true if cname record matches the domain name' do
|
||||
expect(subject.check_custom_domain).to eq true
|
||||
context 'when the cname record matches the domain name' do
|
||||
let(:cname_domain) { ENV['OSEM_HOSTNAME'] }
|
||||
it { is_expected.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--'
|
||||
context 'when the cname record does not match the domain name' do
|
||||
let(:cname_domain) { 'random.domain.com' }
|
||||
it { is_expected.to eq false }
|
||||
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
|
||||
context 'when there is no cname record present' do
|
||||
let(:cname_record) { nil }
|
||||
it { is_expected.to eq false }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue