Commit 41834a8e7fd7ac487cf380e0f498efd9dd25f83f
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'fix_template_creation' into stable
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,16 +50,6 @@ class Community < Organization | ||
50 | super + FIELDS | 50 | super + FIELDS |
51 | end | 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 | def active_fields | 53 | def active_fields |
64 | environment ? environment.active_community_fields : [] | 54 | environment ? environment.active_community_fields : [] |
65 | end | 55 | end |
app/models/enterprise.rb
@@ -59,16 +59,6 @@ class Enterprise < Organization | @@ -59,16 +59,6 @@ class Enterprise < Organization | ||
59 | super + FIELDS | 59 | super + FIELDS |
60 | end | 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 | def active_fields | 62 | def active_fields |
73 | environment ? environment.active_enterprise_fields : [] | 63 | environment ? environment.active_enterprise_fields : [] |
74 | end | 64 | end |
app/models/organization.rb
@@ -30,6 +30,16 @@ class Organization < Profile | @@ -30,6 +30,16 @@ class Organization < Profile | ||
30 | 30 | ||
31 | scope :more_popular, :order => 'members_count DESC' | 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 | def validation_methodology | 43 | def validation_methodology |
34 | self.validation_info ? self.validation_info.validation_methodology : nil | 44 | self.validation_info ? self.validation_info.validation_methodology : nil |
35 | end | 45 | end |
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 |