From a2b549b8d1c5df2ed0b1baa9f48c060a7be864bb Mon Sep 17 00:00:00 2001
From: Pirun Seng <sengpirun.rain@gmail.com>
Date: Thu, 24 Dec 2020 10:47:17 +0700
Subject: [PATCH] updates CustomField model spec with Community

---
 spec/models/custom_field_spec.rb | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index 0bd03fff3e..5a24f631f9 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -5,6 +5,7 @@
   describe CustomField, 'associations' do
     it { is_expected.to have_many(:custom_field_properties).dependent(:restrict_with_error) }
     it { is_expected.to have_many(:clients).through(:custom_field_properties).source(:custom_formable) }
+    it { is_expected.to have_many(:communities).through(:custom_field_properties).source(:custom_formable) }
     it { is_expected.to have_many(:families).through(:custom_field_properties).source(:custom_formable) }
     it { is_expected.to have_many(:partners).through(:custom_field_properties).source(:custom_formable) }
     it { is_expected.to have_many(:users).through(:custom_field_properties).source(:custom_formable) }
@@ -99,6 +100,18 @@
         is_expected.not_to include(other_custom_field)
       end
     end
+
+    context 'community forms' do
+      let!(:custom_field) { create(:custom_field, form_title: 'Community Form', entity_type: 'Community') }
+      let!(:other_custom_field) { create(:custom_field, form_title: 'Prison Record', entity_type: 'Partner') }
+      subject { CustomField.community_forms }
+      it 'should include forms with community entity type' do
+        is_expected.to include(custom_field)
+      end
+      it 'should not include forms without community entity type' do
+        is_expected.not_to include(other_custom_field)
+      end
+    end
   end
 
   describe CustomField, 'CONSTANTS' do
@@ -106,7 +119,7 @@
       expect(CustomField::FREQUENCIES).to eq(['Daily', 'Weekly', 'Monthly', 'Yearly'])
     end
     it 'ENTITY_TYPES' do
-      expect(CustomField::ENTITY_TYPES).to eq(['Client', 'Family', 'Partner', 'User'])
+      expect(CustomField::ENTITY_TYPES).to eq(['Client', 'Community', 'Family', 'Partner', 'User'])
     end
   end
 
@@ -149,4 +162,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end