diff --git a/app/models/community.rb b/app/models/community.rb index e36ddf0..82bbd3b 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -50,7 +50,7 @@ class Community < Organization super + FIELDS end - validate :presence_of_required_fieds + validate :presence_of_required_fieds, :unless => :is_template def presence_of_required_fieds self.required_fields.each do |field| diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 7abfec7..8b28ffe 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -59,7 +59,7 @@ class Enterprise < Organization super + FIELDS end - validate :presence_of_required_fieds + validate :presence_of_required_fieds, :unless => :is_template def presence_of_required_fieds self.required_fields.each do |field| diff --git a/app/models/person.rb b/app/models/person.rb index d0d0521..df39448 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -161,7 +161,7 @@ class Person < Profile FIELDS end - validate :presence_of_required_fields + validate :presence_of_required_fields, :unless => :is_template def presence_of_required_fields self.required_fields.each do |field| diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index ac68fbe..6bbd078 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -126,6 +126,18 @@ class CommunityTest < ActiveSupport::TestCase assert ! community.errors[:contact_phone.to_s].present? end + should 'not require fields if community is a template' do + e = Environment.default + e.expects(:required_community_fields).returns(['contact_phone']).at_least_once + community = build(Community, :name => 'My community', :environment => e) + assert ! community.valid? + assert community.errors[:contact_phone.to_s].present? + + community.is_template = true + community.valid? + assert ! community.errors[:contact_phone.to_s].present? + end + should 'return newest text articles as news' do c = fast_create(Community, :name => 'test_com') f = fast_create(Folder, :name => 'folder', :profile_id => c.id) diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index e8ddea4..d258b8c 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -310,6 +310,18 @@ class EnterpriseTest < ActiveSupport::TestCase assert ! enterprise.errors[:contact_phone.to_s].present? end + should 'not require fields if enterprise is a template' do + e = Environment.default + e.expects(:required_enterprise_fields).returns(['contact_phone']).at_least_once + enterprise = build(Enterprise, :environment => e) + assert ! enterprise.valid? + assert enterprise.errors[:contact_phone.to_s].present? + + enterprise.is_template = true + enterprise.valid? + assert ! enterprise.errors[:contact_phone.to_s].present? + end + should 'enable contact' do enterprise = build(Enterprise, :enable_contact_us => false) assert !enterprise.enable_contact? diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 4100798..b93f9db 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -513,6 +513,18 @@ class PersonTest < ActiveSupport::TestCase assert ! person.errors[:custom_formation.to_s].present? end + should 'not require fields if person is a template' do + e = Environment.default + e.expects(:required_person_fields).returns(['cell_phone']).at_least_once + person = build(Person, :environment => e) + assert ! person.valid? + assert person.errors[:cell_phone.to_s].present? + + person.is_template = true + person.valid? + assert ! person.errors[:cell_phone.to_s].present? + end + should 'identify when person is a friend' do p1 = create_user('testuser1').person p2 = create_user('testuser2').person -- libgit2 0.21.2