Fixes #3089 - Domain based assignment can be enabled without domain being filled in

This commit is contained in:
Mantas 2020-06-27 15:02:20 +03:00 committed by Thorsten Eckel
parent 37a6a748c9
commit cbf5359589
2 changed files with 28 additions and 1 deletions

View file

@ -19,7 +19,8 @@ class Organization < ApplicationModel
before_create :domain_cleanup
before_update :domain_cleanup
validates :name, presence: true
validates :name, presence: true
validates :domain, presence: { message: 'required when Domain Based Assignment is enabled' }, if: :domain_assignment
activity_stream_permission 'admin.role'

View file

@ -41,4 +41,30 @@ RSpec.describe Organization, type: :model do
end
end
end
describe '#domain_assignment' do
it 'fails if enabled and domain is missing' do
organization.domain_assignment = true
organization.domain = nil
organization.valid?
expect(organization.errors[:domain]).to be_present
end
it 'succeeds if enabled and domain is present' do
organization.domain_assignment = true
organization.domain = 'example.org'
organization.valid?
expect(organization.errors[:domain]).to be_empty
end
it 'succeeds if disabled and domain is missing' do
organization.domain_assignment = false
organization.domain = nil
organization.valid?
expect(organization.errors[:domain]).to be_empty
end
end
end