Commit 65ea86e71782ba5853a37b2ddc2952acdc9724ce
1 parent
7db6046a
Exists in
master
and in
29 other branches
Fix creation of profile templates when extra fields are required
Showing
6 changed files
with
39 additions
and
3 deletions
Show diff stats
app/models/community.rb
@@ -50,7 +50,7 @@ class Community < Organization | @@ -50,7 +50,7 @@ class Community < Organization | ||
50 | super + FIELDS | 50 | super + FIELDS |
51 | end | 51 | end |
52 | 52 | ||
53 | - validate :presence_of_required_fieds | 53 | + validate :presence_of_required_fieds, :unless => :is_template |
54 | 54 | ||
55 | def presence_of_required_fieds | 55 | def presence_of_required_fieds |
56 | self.required_fields.each do |field| | 56 | self.required_fields.each do |field| |
app/models/enterprise.rb
@@ -59,7 +59,7 @@ class Enterprise < Organization | @@ -59,7 +59,7 @@ class Enterprise < Organization | ||
59 | super + FIELDS | 59 | super + FIELDS |
60 | end | 60 | end |
61 | 61 | ||
62 | - validate :presence_of_required_fieds | 62 | + validate :presence_of_required_fieds, :unless => :is_template |
63 | 63 | ||
64 | def presence_of_required_fieds | 64 | def presence_of_required_fieds |
65 | self.required_fields.each do |field| | 65 | self.required_fields.each do |field| |
app/models/person.rb
@@ -161,7 +161,7 @@ class Person < Profile | @@ -161,7 +161,7 @@ class Person < Profile | ||
161 | FIELDS | 161 | FIELDS |
162 | end | 162 | end |
163 | 163 | ||
164 | - validate :presence_of_required_fields | 164 | + validate :presence_of_required_fields, :unless => :is_template |
165 | 165 | ||
166 | def presence_of_required_fields | 166 | def presence_of_required_fields |
167 | self.required_fields.each do |field| | 167 | self.required_fields.each do |field| |
test/unit/community_test.rb
@@ -126,6 +126,18 @@ class CommunityTest < ActiveSupport::TestCase | @@ -126,6 +126,18 @@ class CommunityTest < ActiveSupport::TestCase | ||
126 | assert ! community.errors[:contact_phone.to_s].present? | 126 | assert ! community.errors[:contact_phone.to_s].present? |
127 | end | 127 | end |
128 | 128 | ||
129 | + should 'not require fields if community is a template' do | ||
130 | + e = Environment.default | ||
131 | + e.expects(:required_community_fields).returns(['contact_phone']).at_least_once | ||
132 | + community = build(Community, :name => 'My community', :environment => e) | ||
133 | + assert ! community.valid? | ||
134 | + assert community.errors[:contact_phone.to_s].present? | ||
135 | + | ||
136 | + community.is_template = true | ||
137 | + community.valid? | ||
138 | + assert ! community.errors[:contact_phone.to_s].present? | ||
139 | + end | ||
140 | + | ||
129 | should 'return newest text articles as news' do | 141 | should 'return newest text articles as news' do |
130 | c = fast_create(Community, :name => 'test_com') | 142 | c = fast_create(Community, :name => 'test_com') |
131 | f = fast_create(Folder, :name => 'folder', :profile_id => c.id) | 143 | f = fast_create(Folder, :name => 'folder', :profile_id => c.id) |
test/unit/enterprise_test.rb
@@ -310,6 +310,18 @@ class EnterpriseTest < ActiveSupport::TestCase | @@ -310,6 +310,18 @@ class EnterpriseTest < ActiveSupport::TestCase | ||
310 | assert ! enterprise.errors[:contact_phone.to_s].present? | 310 | assert ! enterprise.errors[:contact_phone.to_s].present? |
311 | end | 311 | end |
312 | 312 | ||
313 | + should 'not require fields if enterprise is a template' do | ||
314 | + e = Environment.default | ||
315 | + e.expects(:required_enterprise_fields).returns(['contact_phone']).at_least_once | ||
316 | + enterprise = build(Enterprise, :environment => e) | ||
317 | + assert ! enterprise.valid? | ||
318 | + assert enterprise.errors[:contact_phone.to_s].present? | ||
319 | + | ||
320 | + enterprise.is_template = true | ||
321 | + enterprise.valid? | ||
322 | + assert ! enterprise.errors[:contact_phone.to_s].present? | ||
323 | + end | ||
324 | + | ||
313 | should 'enable contact' do | 325 | should 'enable contact' do |
314 | enterprise = build(Enterprise, :enable_contact_us => false) | 326 | enterprise = build(Enterprise, :enable_contact_us => false) |
315 | assert !enterprise.enable_contact? | 327 | assert !enterprise.enable_contact? |
test/unit/person_test.rb
@@ -513,6 +513,18 @@ class PersonTest < ActiveSupport::TestCase | @@ -513,6 +513,18 @@ class PersonTest < ActiveSupport::TestCase | ||
513 | assert ! person.errors[:custom_formation.to_s].present? | 513 | assert ! person.errors[:custom_formation.to_s].present? |
514 | end | 514 | end |
515 | 515 | ||
516 | + should 'not require fields if person is a template' do | ||
517 | + e = Environment.default | ||
518 | + e.expects(:required_person_fields).returns(['cell_phone']).at_least_once | ||
519 | + person = build(Person, :environment => e) | ||
520 | + assert ! person.valid? | ||
521 | + assert person.errors[:cell_phone.to_s].present? | ||
522 | + | ||
523 | + person.is_template = true | ||
524 | + person.valid? | ||
525 | + assert ! person.errors[:cell_phone.to_s].present? | ||
526 | + end | ||
527 | + | ||
516 | should 'identify when person is a friend' do | 528 | should 'identify when person is a friend' do |
517 | p1 = create_user('testuser1').person | 529 | p1 = create_user('testuser1').person |
518 | p2 = create_user('testuser2').person | 530 | p2 = create_user('testuser2').person |