Commit b2083dec369e86e6136522d8940e0975960ee2f6
1 parent
5d182131
Exists in
master
and in
29 other branches
refactoring person template management
Showing
5 changed files
with
80 additions
and
13 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -726,13 +726,17 @@ class Environment < ActiveRecord::Base |
726 | 726 | settings[:community_template_id] = value.id |
727 | 727 | end |
728 | 728 | |
729 | - def person_template | |
729 | + def person_templates | |
730 | + self.people.templates | |
731 | + end | |
732 | + | |
733 | + def person_default_template | |
730 | 734 | template = Person.find_by_id settings[:person_template_id] |
731 | - template if template && template.is_template | |
735 | + template if template && template.is_template? | |
732 | 736 | end |
733 | 737 | |
734 | - def person_template=(value) | |
735 | - settings[:person_template_id] = value.id | |
738 | + def person_default_template=(value) | |
739 | + settings[:person_template_id] = value.kind_of?(Person) ? value.id : value | |
736 | 740 | end |
737 | 741 | |
738 | 742 | def enterprise_template |
... | ... | @@ -842,7 +846,7 @@ class Environment < ActiveRecord::Base |
842 | 846 | self.enterprise_template = enterprise_template |
843 | 847 | self.inactive_enterprise_template = inactive_enterprise_template |
844 | 848 | self.community_template = community_template |
845 | - self.person_template = person_template | |
849 | + self.person_default_template = person_template | |
846 | 850 | self.save! |
847 | 851 | end |
848 | 852 | ... | ... |
app/models/person.rb
app/views/templates/index.html.erb
... | ... | @@ -2,10 +2,11 @@ |
2 | 2 | |
3 | 3 | <%= _('Manage the templates used on creation of profiles') %> |
4 | 4 | |
5 | -<% list_of_templates = [[_('Person') , environment.people.templates , 'person' ], | |
5 | +<% list_of_templates = [[_('Person') , environment.person_templates , 'person' ], | |
6 | 6 | [_('Community') , environment.communities.templates, 'community' ], |
7 | 7 | [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %> |
8 | 8 | |
9 | + | |
9 | 10 | <% list_of_templates.each do |title, templates, kind|%> |
10 | 11 | <div class='template-kind'> |
11 | 12 | <h2><%= title %></h2> | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -495,13 +495,13 @@ class EnvironmentTest < ActiveSupport::TestCase |
495 | 495 | assert_kind_of Enterprise, e.enterprise_template |
496 | 496 | assert_kind_of Enterprise, e.inactive_enterprise_template |
497 | 497 | assert_kind_of Community, e.community_template |
498 | - assert_kind_of Person, e.person_template | |
498 | + assert_kind_of Person, e.person_default_template | |
499 | 499 | |
500 | 500 | # the templates must be private |
501 | 501 | assert !e.enterprise_template.visible? |
502 | 502 | assert !e.inactive_enterprise_template.visible? |
503 | 503 | assert !e.community_template.visible? |
504 | - assert !e.person_template.visible? | |
504 | + assert !e.person_default_template.visible? | |
505 | 505 | end |
506 | 506 | |
507 | 507 | should 'set templates' do |
... | ... | @@ -512,14 +512,76 @@ class EnvironmentTest < ActiveSupport::TestCase |
512 | 512 | assert_equal comm, e.community_template |
513 | 513 | |
514 | 514 | person = fast_create(Person, :is_template => true) |
515 | - e.person_template = person | |
516 | - assert_equal person, e.person_template | |
515 | + e.person_default_template = person | |
516 | + assert_equal person, e.person_default_template | |
517 | 517 | |
518 | 518 | enterprise = fast_create(Enterprise, :is_template => true) |
519 | 519 | e.enterprise_template = enterprise |
520 | 520 | assert_equal enterprise, e.enterprise_template |
521 | 521 | end |
522 | 522 | |
523 | + should 'person_templates return all templates of person' do | |
524 | + e = fast_create(Environment) | |
525 | + | |
526 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
527 | + p2 = fast_create(Person, :environment_id => e.id) | |
528 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
529 | + assert_equivalent [p1,p3], e.person_templates | |
530 | + end | |
531 | + | |
532 | + should 'person_templates return an empty array if there is no templates of person' do | |
533 | + e = fast_create(Environment) | |
534 | + | |
535 | + fast_create(Person, :environment_id => e.id) | |
536 | + fast_create(Person, :environment_id => e.id) | |
537 | + assert_equivalent [], e.person_templates | |
538 | + end | |
539 | + | |
540 | + should 'person_default_template return the template defined as default' do | |
541 | + e = fast_create(Environment) | |
542 | + | |
543 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
544 | + p2 = fast_create(Person, :environment_id => e.id) | |
545 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
546 | + | |
547 | + e.settings[:person_template_id]= p3.id | |
548 | + assert_equal p3, e.person_default_template | |
549 | + end | |
550 | + | |
551 | + should 'person_default_template not return a person if its not a template' do | |
552 | + e = fast_create(Environment) | |
553 | + | |
554 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
555 | + p2 = fast_create(Person, :environment_id => e.id) | |
556 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
557 | + | |
558 | + e.settings[:person_template_id]= p2.id | |
559 | + assert_nil e.person_default_template | |
560 | + end | |
561 | + | |
562 | + should 'person_default_template= define a person model passed as paremeter as default template' do | |
563 | + e = fast_create(Environment) | |
564 | + | |
565 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
566 | + p2 = fast_create(Person, :environment_id => e.id) | |
567 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
568 | + | |
569 | + e.person_default_template= p3 | |
570 | + assert_equal p3, e.person_default_template | |
571 | + end | |
572 | + | |
573 | + should 'person_default_template= define an id passed as paremeter as the default template' do | |
574 | + e = fast_create(Environment) | |
575 | + | |
576 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
577 | + p2 = fast_create(Person, :environment_id => e.id) | |
578 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
579 | + | |
580 | + e.person_default_template= p3.id | |
581 | + assert_equal p3, e.person_default_template | |
582 | + end | |
583 | + | |
584 | + | |
523 | 585 | should 'have a layout template' do |
524 | 586 | e = build(Environment, :layout_template => 'mytemplate') |
525 | 587 | assert_equal 'mytemplate', e.layout_template | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -883,7 +883,7 @@ class ProfileTest < ActiveSupport::TestCase |
883 | 883 | |
884 | 884 | should 'copy communities from person template' do |
885 | 885 | template = create_user('test_template').person |
886 | - Environment.any_instance.stubs(:person_template).returns(template) | |
886 | + Environment.any_instance.stubs(:person_default_template).returns(template) | |
887 | 887 | |
888 | 888 | c1 = fast_create(Community) |
889 | 889 | c2 = fast_create(Community) |
... | ... | @@ -1336,7 +1336,7 @@ class ProfileTest < ActiveSupport::TestCase |
1336 | 1336 | template = create_user('test_template').person |
1337 | 1337 | template.custom_footer = "footer customized" |
1338 | 1338 | template.custom_header = "header customized" |
1339 | - Environment.any_instance.stubs(:person_template).returns(template) | |
1339 | + Environment.any_instance.stubs(:person_default_template).returns(template) | |
1340 | 1340 | |
1341 | 1341 | person = create_user_full('mytestuser').person |
1342 | 1342 | assert_equal "footer customized", person.custom_footer | ... | ... |