diff --git a/app/controllers/admin/zonefiles_controller.rb b/app/controllers/admin/zonefiles_controller.rb index 7d3b68ec6..1c0fed936 100644 --- a/app/controllers/admin/zonefiles_controller.rb +++ b/app/controllers/admin/zonefiles_controller.rb @@ -3,7 +3,7 @@ class Admin::ZonefilesController < ApplicationController # TODO: Refactor this def create - if ZonefileSetting.pluck(:origin).include?(params[:origin]) + if ZonefileSetting.origins.include?(params[:origin]) @zonefile = ActiveRecord::Base.connection.execute( "select generate_zonefile('#{params[:origin]}')" diff --git a/app/models/zonefile_setting.rb b/app/models/zonefile_setting.rb index 4a9656b7a..9f2b2b862 100644 --- a/app/models/zonefile_setting.rb +++ b/app/models/zonefile_setting.rb @@ -32,6 +32,10 @@ class ZonefileSetting < ActiveRecord::Base STDOUT << "#{Time.zone.now.utc} - Successfully generated zonefile #{filename}\n" end + def self.origins + pluck(:origin) + end + def to_s origin end diff --git a/app/validators/domain_name_validator.rb b/app/validators/domain_name_validator.rb index be83f0835..427a330f3 100644 --- a/app/validators/domain_name_validator.rb +++ b/app/validators/domain_name_validator.rb @@ -12,9 +12,9 @@ class DomainNameValidator < ActiveModel::EachValidator return true unless value value = value.mb_chars.downcase.strip - origins = ZonefileSetting.pluck(:origin) + origins = ZonefileSetting.origins # if someone tries to register an origin domain, let this validation pass - # the error will be catched in blocked domains validator + # the error will be caught in blocked domains validator return true if origins.include?(value) general_domains = /(#{origins.join('|')})/ diff --git a/spec/models/zonefile_setting_spec.rb b/spec/models/zonefile_setting_spec.rb new file mode 100644 index 000000000..d1cd61119 --- /dev/null +++ b/spec/models/zonefile_setting_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.describe ZonefileSetting, db: false do + it 'has versions' do + expect(described_class.new.versions).to eq([]) + end + + describe '::origins' do + before :example do + expect(described_class).to receive(:pluck).with(:origin).and_return('origins') + end + + it 'returns origins' do + expect(described_class.origins).to eq('origins') + end + end +end