Skip to content

Commit

Permalink
Finalize tests for app settings, fix regex for vSphere root folder va…
Browse files Browse the repository at this point in the history
…lidation
  • Loading branch information
bdaase committed Mar 22, 2019
1 parent 1ce6a74 commit 8fc1a73
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/app_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AppSetting < ApplicationRecord
format: { with: %r{\A\/?(?:[0-9a-zA-Z_-]+\/?)*\z}, message: 'has to be a valid UNIX file path' }
validates :vsphere_root_folder,
length: { maximum: VSphere::Folder::VSPHERE_FOLDER_NAME_CHARACTER_LIMIT },
format: { without: %r{/%\/}, message: 'The vSphere root folder may not contain "/", "\" or "%"' }
format: { without: %r{.*[%\/\\].*}, message: 'The vSphere root folder may not contain "/", "\" or "%"' }

after_commit :apply_settings, on: :update

Expand Down
2 changes: 1 addition & 1 deletion spec/factories/app_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
vsphere_server_ip { '127.0.0.1' }
vsphere_server_user { 'user@domain.tld' }
vsphere_server_password { 'verySecure' }
vsphere_root_folder { '/' }
vsphere_root_folder { '' }
min_cpu_cores { 1 }
max_cpu_cores { 64 }
max_ram_size { 128 }
Expand Down
64 changes: 62 additions & 2 deletions spec/models/app_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,68 @@
let(:app_setting) {FactoryBot.build :app_setting}

context 'when settings are invalid' do
it 'is invalid with if it is not the first setting' do
app_setting.singleton_guard = 2
it 'is invalid if it is not the first setting' do
app_setting.singleton_guard = 1
expect(app_setting).to be_invalid
end

it 'is invalid if the github user email is not a valid mail address' do
app_setting.github_user_email = 'noEmailAddress'
expect(app_setting).to be_invalid
end

it 'is invalid if the github user name is empty' do
app_setting.github_user_name = ''
expect(app_setting).to be_invalid
end

it 'is invalid if the git repository name is empty' do
app_setting.git_repository_name = ''
expect(app_setting).to be_invalid
end

it 'is invalid if the git repository url is empty' do
app_setting.git_repository_url = ''
expect(app_setting).to be_invalid
end

it 'is invalid if the git branch is empty' do
app_setting.git_branch = ''
expect(app_setting).to be_invalid
end

it 'is invalid if the smtp port is too high' do
app_setting.email_notification_smtp_port = 65_536
expect(app_setting).to be_invalid
end

it 'is invalid if the archivation timeout is negative' do
app_setting.vm_archivation_timeout = -1
expect(app_setting).to be_invalid
end

it 'is invalid if the puppet init path is not a valid UNIX file path' do
app_setting.puppet_init_path = '/invalid/folder%'
expect(app_setting).to be_invalid
end

it 'is invalid if the puppet classes path is not a valid UNIX file path' do
app_setting.puppet_classes_path = '\invalid/folder'
expect(app_setting).to be_invalid
end

it 'is invalid if the puppet names path is not a valid UNIX file path' do
app_setting.puppet_nodes_path = 'invalid/folder#'
expect(app_setting).to be_invalid
end

it 'is invalid if vSphere root folder is too long' do
app_setting.vsphere_root_folder = '12345678902234567890323456789042345678905234567890623456789072345678908234567890'
expect(app_setting).to be_invalid
end

it 'is invalid if vSphere root folder contains special characters' do
app_setting.vsphere_root_folder = '/\\%'
expect(app_setting).to be_invalid
end
end
Expand Down

0 comments on commit 8fc1a73

Please sign in to comment.