diff --git a/app/models/environment.rb b/app/models/environment.rb
index 50061c8..5f42b26 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -726,13 +726,17 @@ class Environment < ActiveRecord::Base
settings[:community_template_id] = value.id
end
- def person_template
+ def person_templates
+ self.people.templates
+ end
+
+ def person_default_template
template = Person.find_by_id settings[:person_template_id]
- template if template && template.is_template
+ template if template && template.is_template?
end
- def person_template=(value)
- settings[:person_template_id] = value.id
+ def person_default_template=(value)
+ settings[:person_template_id] = value.kind_of?(Person) ? value.id : value
end
def enterprise_template
@@ -842,7 +846,7 @@ class Environment < ActiveRecord::Base
self.enterprise_template = enterprise_template
self.inactive_enterprise_template = inactive_enterprise_template
self.community_template = community_template
- self.person_template = person_template
+ self.person_default_template = person_template
self.save!
end
diff --git a/app/models/person.rb b/app/models/person.rb
index d0d0521..8eaff25 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -300,7 +300,7 @@ class Person < Profile
end
def default_template
- environment.person_template
+ environment.person_default_template
end
def apply_type_specific_template(template)
diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb
index 2556c74..003fb32 100644
--- a/app/views/templates/index.html.erb
+++ b/app/views/templates/index.html.erb
@@ -2,10 +2,11 @@
<%= _('Manage the templates used on creation of profiles') %>
-<% list_of_templates = [[_('Person') , environment.people.templates , 'person' ],
+<% list_of_templates = [[_('Person') , environment.person_templates , 'person' ],
[_('Community') , environment.communities.templates, 'community' ],
[_('Enterprise'), environment.enterprises.templates, 'enterprise']] %>
+
<% list_of_templates.each do |title, templates, kind|%>
<%= title %>
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index eaa3911..40e83e7 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -495,13 +495,13 @@ class EnvironmentTest < ActiveSupport::TestCase
assert_kind_of Enterprise, e.enterprise_template
assert_kind_of Enterprise, e.inactive_enterprise_template
assert_kind_of Community, e.community_template
- assert_kind_of Person, e.person_template
+ assert_kind_of Person, e.person_default_template
# the templates must be private
assert !e.enterprise_template.visible?
assert !e.inactive_enterprise_template.visible?
assert !e.community_template.visible?
- assert !e.person_template.visible?
+ assert !e.person_default_template.visible?
end
should 'set templates' do
@@ -512,14 +512,76 @@ class EnvironmentTest < ActiveSupport::TestCase
assert_equal comm, e.community_template
person = fast_create(Person, :is_template => true)
- e.person_template = person
- assert_equal person, e.person_template
+ e.person_default_template = person
+ assert_equal person, e.person_default_template
enterprise = fast_create(Enterprise, :is_template => true)
e.enterprise_template = enterprise
assert_equal enterprise, e.enterprise_template
end
+ should 'person_templates return all templates of person' do
+ e = fast_create(Environment)
+
+ p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+ p2 = fast_create(Person, :environment_id => e.id)
+ p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+ assert_equivalent [p1,p3], e.person_templates
+ end
+
+ should 'person_templates return an empty array if there is no templates of person' do
+ e = fast_create(Environment)
+
+ fast_create(Person, :environment_id => e.id)
+ fast_create(Person, :environment_id => e.id)
+ assert_equivalent [], e.person_templates
+ end
+
+ should 'person_default_template return the template defined as default' do
+ e = fast_create(Environment)
+
+ p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+ p2 = fast_create(Person, :environment_id => e.id)
+ p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+ e.settings[:person_template_id]= p3.id
+ assert_equal p3, e.person_default_template
+ end
+
+ should 'person_default_template not return a person if its not a template' do
+ e = fast_create(Environment)
+
+ p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+ p2 = fast_create(Person, :environment_id => e.id)
+ p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+ e.settings[:person_template_id]= p2.id
+ assert_nil e.person_default_template
+ end
+
+ should 'person_default_template= define a person model passed as paremeter as default template' do
+ e = fast_create(Environment)
+
+ p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+ p2 = fast_create(Person, :environment_id => e.id)
+ p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+ e.person_default_template= p3
+ assert_equal p3, e.person_default_template
+ end
+
+ should 'person_default_template= define an id passed as paremeter as the default template' do
+ e = fast_create(Environment)
+
+ p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+ p2 = fast_create(Person, :environment_id => e.id)
+ p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+ e.person_default_template= p3.id
+ assert_equal p3, e.person_default_template
+ end
+
+
should 'have a layout template' do
e = build(Environment, :layout_template => 'mytemplate')
assert_equal 'mytemplate', e.layout_template
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index adedccc..6a1f28e 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -883,7 +883,7 @@ class ProfileTest < ActiveSupport::TestCase
should 'copy communities from person template' do
template = create_user('test_template').person
- Environment.any_instance.stubs(:person_template).returns(template)
+ Environment.any_instance.stubs(:person_default_template).returns(template)
c1 = fast_create(Community)
c2 = fast_create(Community)
@@ -1336,7 +1336,7 @@ class ProfileTest < ActiveSupport::TestCase
template = create_user('test_template').person
template.custom_footer = "footer customized"
template.custom_header = "header customized"
- Environment.any_instance.stubs(:person_template).returns(template)
+ Environment.any_instance.stubs(:person_default_template).returns(template)
person = create_user_full('mytestuser').person
assert_equal "footer customized", person.custom_footer
--
libgit2 0.21.2