Просмотр исходного кода

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

Mantas 4 лет назад
Родитель
Сommit
cbf5359589
2 измененных файлов с 28 добавлено и 1 удалено
  1. 2 1
      app/models/organization.rb
  2. 26 0
      spec/models/organization_spec.rb

+ 2 - 1
app/models/organization.rb

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

+ 26 - 0
spec/models/organization_spec.rb

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