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