Refactor zonefile_setting's origin list

#186
This commit is contained in:
Artur Beljajev 2016-10-28 00:29:47 +03:00
parent 469312d7ee
commit 39d7c6ad1d
4 changed files with 24 additions and 3 deletions

View file

@ -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]}')"

View file

@ -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

View file

@ -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('|')})/

View file

@ -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