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
app/models/enterprise.rb
... | ... | @@ -59,7 +59,7 @@ class Enterprise < Organization |
59 | 59 | super + FIELDS |
60 | 60 | end |
61 | 61 | |
62 | - validate :presence_of_required_fieds | |
62 | + validate :presence_of_required_fieds, :unless => :is_template | |
63 | 63 | |
64 | 64 | def presence_of_required_fieds |
65 | 65 | self.required_fields.each do |field| | ... | ... |
app/models/person.rb
... | ... | @@ -161,7 +161,7 @@ class Person < Profile |
161 | 161 | FIELDS |
162 | 162 | end |
163 | 163 | |
164 | - validate :presence_of_required_fields | |
164 | + validate :presence_of_required_fields, :unless => :is_template | |
165 | 165 | |
166 | 166 | def presence_of_required_fields |
167 | 167 | self.required_fields.each do |field| | ... | ... |
test/unit/community_test.rb
... | ... | @@ -126,6 +126,18 @@ class CommunityTest < ActiveSupport::TestCase |
126 | 126 | assert ! community.errors[:contact_phone.to_s].present? |
127 | 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 | 141 | should 'return newest text articles as news' do |
130 | 142 | c = fast_create(Community, :name => 'test_com') |
131 | 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 | 310 | assert ! enterprise.errors[:contact_phone.to_s].present? |
311 | 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 | 325 | should 'enable contact' do |
314 | 326 | enterprise = build(Enterprise, :enable_contact_us => false) |
315 | 327 | assert !enterprise.enable_contact? | ... | ... |
test/unit/person_test.rb
... | ... | @@ -513,6 +513,18 @@ class PersonTest < ActiveSupport::TestCase |
513 | 513 | assert ! person.errors[:custom_formation.to_s].present? |
514 | 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 | 528 | should 'identify when person is a friend' do |
517 | 529 | p1 = create_user('testuser1').person |
518 | 530 | p2 = create_user('testuser2').person | ... | ... |