Commit 50dcad3a9bbca972e19a205fac0102274d5f0623
Exists in
staging
and in
42 other branches
Merge branch 'fix_template_creation' into 'master'
Fix creation of profile templates when extra fields were setted as required See merge request !355
Showing
7 changed files
with
47 additions
and
21 deletions
Show diff stats
app/models/community.rb
| ... | ... | @@ -50,16 +50,6 @@ class Community < Organization |
| 50 | 50 | super + FIELDS |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | - validate :presence_of_required_fieds | |
| 54 | - | |
| 55 | - def presence_of_required_fieds | |
| 56 | - self.required_fields.each do |field| | |
| 57 | - if self.send(field).blank? | |
| 58 | - self.errors.add_on_blank(field) | |
| 59 | - end | |
| 60 | - end | |
| 61 | - end | |
| 62 | - | |
| 63 | 53 | def active_fields |
| 64 | 54 | environment ? environment.active_community_fields : [] |
| 65 | 55 | end | ... | ... |
app/models/enterprise.rb
| ... | ... | @@ -59,16 +59,6 @@ class Enterprise < Organization |
| 59 | 59 | super + FIELDS |
| 60 | 60 | end |
| 61 | 61 | |
| 62 | - validate :presence_of_required_fieds | |
| 63 | - | |
| 64 | - def presence_of_required_fieds | |
| 65 | - self.required_fields.each do |field| | |
| 66 | - if self.send(field).blank? | |
| 67 | - self.errors.add_on_blank(field) | |
| 68 | - end | |
| 69 | - end | |
| 70 | - end | |
| 71 | - | |
| 72 | 62 | def active_fields |
| 73 | 63 | environment ? environment.active_enterprise_fields : [] |
| 74 | 64 | end | ... | ... |
app/models/organization.rb
| ... | ... | @@ -30,6 +30,16 @@ class Organization < Profile |
| 30 | 30 | |
| 31 | 31 | scope :more_popular, :order => 'members_count DESC' |
| 32 | 32 | |
| 33 | + validate :presence_of_required_fieds, :unless => :is_template | |
| 34 | + | |
| 35 | + def presence_of_required_fieds | |
| 36 | + self.required_fields.each do |field| | |
| 37 | + if self.send(field).blank? | |
| 38 | + self.errors.add_on_blank(field) | |
| 39 | + end | |
| 40 | + end | |
| 41 | + end | |
| 42 | + | |
| 33 | 43 | def validation_methodology |
| 34 | 44 | self.validation_info ? self.validation_info.validation_methodology : nil |
| 35 | 45 | end | ... | ... |
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 | ... | ... |