Page MenuHomeGRNET

host_spec.rb
No OneTemporary

File Metadata

Created
Sun, May 18, 10:29 PM

host_spec.rb

require 'spec_helper'
describe Host do
context 'validates' do
it "presence of Password" do
expect(Host.new).to have(1).errors_on(:password)
end
it 'numericality of :port' do
expect(Host.new(port: :lala)).to have(2).errors_on(:port)
end
[:file_retention, :job_retention, :name].each do |field|
it "#{field} is set automatically" do
host = Host.new(fqdn: 'test')
host.valid?
expect(host.send(field)).to be_present
end
end
end
context 'when fqdn is invalid' do
let(:host) { FactoryGirl.build(:host, fqdn: :lala) }
it 'has errors' do
expect(host).to have(1).errors_on(:fqdn)
end
end
context 'name field' do
let(:host) { FactoryGirl.create(:host, name: nil) }
it 'is generated by the system' do
expect(host.name).to be
end
end
describe '#to_bacula_config_array' do
let(:host) { FactoryGirl.create(:host) }
it "is a valid client directive" do
expect(host.to_bacula_config_array).to include('Client {')
expect(host.to_bacula_config_array).to include('}')
end
it "contains Address directive" do
expect(host.to_bacula_config_array).to include(" Address = #{host.fqdn}")
end
it "contains FDPort directive" do
expect(host.to_bacula_config_array).to include(" FDPort = #{host.port}")
end
it "contains Catalog directive" do
expect(host.to_bacula_config_array).to include(" Catalog = #{Host::CATALOG}")
end
it "contains Password directive" do
expect(host.to_bacula_config_array).to include(" Password = \"#{host.password}\"")
end
it "contains File Retention directive" do
expect(host.to_bacula_config_array).
to include(" File Retention = #{host.file_retention} days")
end
it "contains Job Retention directive" do
expect(host.to_bacula_config_array).
to include(" Job Retention = #{host.job_retention} days")
end
it "contains AutoPrune directive" do
expect(host.to_bacula_config_array).to include(" AutoPrune = yes")
end
end
describe '#baculize_config' do
let!(:host) { FactoryGirl.create(:host) }
let!(:fileset) { FactoryGirl.create(:fileset, host: host) }
let!(:other_fileset) { FactoryGirl.create(:fileset, host: host) }
let!(:schedule) { FactoryGirl.create(:schedule) }
let!(:other_schedule) { FactoryGirl.create(:schedule) }
let!(:enabled_job) do
FactoryGirl.create(:job_template, host: host, schedule: schedule,
fileset: fileset, enabled: true)
end
let!(:disabled_job) do
FactoryGirl.create(:job_template, host: host, schedule: other_schedule,
fileset: other_fileset, enabled: false)
end
subject { host.baculize_config }
it 'includes the client\'s config' do
expect(subject).to include(host.to_bacula_config_array)
end
it 'includes the enabled job template\'s configs' do
expect(subject).to include(enabled_job.to_bacula_config_array)
expect(subject).to_not include(disabled_job.to_bacula_config_array)
end
it 'includes the used schedules\'s configs' do
expect(subject).to include(schedule.to_bacula_config_array)
expect(subject).to_not include(other_schedule.to_bacula_config_array)
end
it 'includes the used filesets\'s configs' do
expect(subject).to include(fileset.to_bacula_config_array)
expect(subject).to_not include(other_fileset.to_bacula_config_array)
end
end
end

Event Timeline