Commit b2083dec369e86e6136522d8940e0975960ee2f6
1 parent
5d182131
Exists in
master
and in
22 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,13 +726,17 @@ class Environment < ActiveRecord::Base | ||
| 726 | settings[:community_template_id] = value.id | 726 | settings[:community_template_id] = value.id |
| 727 | end | 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 | template = Person.find_by_id settings[:person_template_id] | 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 | end | 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 | end | 740 | end |
| 737 | 741 | ||
| 738 | def enterprise_template | 742 | def enterprise_template |
| @@ -842,7 +846,7 @@ class Environment < ActiveRecord::Base | @@ -842,7 +846,7 @@ class Environment < ActiveRecord::Base | ||
| 842 | self.enterprise_template = enterprise_template | 846 | self.enterprise_template = enterprise_template |
| 843 | self.inactive_enterprise_template = inactive_enterprise_template | 847 | self.inactive_enterprise_template = inactive_enterprise_template |
| 844 | self.community_template = community_template | 848 | self.community_template = community_template |
| 845 | - self.person_template = person_template | 849 | + self.person_default_template = person_template |
| 846 | self.save! | 850 | self.save! |
| 847 | end | 851 | end |
| 848 | 852 |
app/models/person.rb
| @@ -300,7 +300,7 @@ class Person < Profile | @@ -300,7 +300,7 @@ class Person < Profile | ||
| 300 | end | 300 | end |
| 301 | 301 | ||
| 302 | def default_template | 302 | def default_template |
| 303 | - environment.person_template | 303 | + environment.person_default_template |
| 304 | end | 304 | end |
| 305 | 305 | ||
| 306 | def apply_type_specific_template(template) | 306 | def apply_type_specific_template(template) |
app/views/templates/index.html.erb
| @@ -2,10 +2,11 @@ | @@ -2,10 +2,11 @@ | ||
| 2 | 2 | ||
| 3 | <%= _('Manage the templates used on creation of profiles') %> | 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 | [_('Community') , environment.communities.templates, 'community' ], | 6 | [_('Community') , environment.communities.templates, 'community' ], |
| 7 | [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %> | 7 | [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %> |
| 8 | 8 | ||
| 9 | + | ||
| 9 | <% list_of_templates.each do |title, templates, kind|%> | 10 | <% list_of_templates.each do |title, templates, kind|%> |
| 10 | <div class='template-kind'> | 11 | <div class='template-kind'> |
| 11 | <h2><%= title %></h2> | 12 | <h2><%= title %></h2> |
test/unit/environment_test.rb
| @@ -495,13 +495,13 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -495,13 +495,13 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 495 | assert_kind_of Enterprise, e.enterprise_template | 495 | assert_kind_of Enterprise, e.enterprise_template |
| 496 | assert_kind_of Enterprise, e.inactive_enterprise_template | 496 | assert_kind_of Enterprise, e.inactive_enterprise_template |
| 497 | assert_kind_of Community, e.community_template | 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 | # the templates must be private | 500 | # the templates must be private |
| 501 | assert !e.enterprise_template.visible? | 501 | assert !e.enterprise_template.visible? |
| 502 | assert !e.inactive_enterprise_template.visible? | 502 | assert !e.inactive_enterprise_template.visible? |
| 503 | assert !e.community_template.visible? | 503 | assert !e.community_template.visible? |
| 504 | - assert !e.person_template.visible? | 504 | + assert !e.person_default_template.visible? |
| 505 | end | 505 | end |
| 506 | 506 | ||
| 507 | should 'set templates' do | 507 | should 'set templates' do |
| @@ -512,14 +512,76 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -512,14 +512,76 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 512 | assert_equal comm, e.community_template | 512 | assert_equal comm, e.community_template |
| 513 | 513 | ||
| 514 | person = fast_create(Person, :is_template => true) | 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 | enterprise = fast_create(Enterprise, :is_template => true) | 518 | enterprise = fast_create(Enterprise, :is_template => true) |
| 519 | e.enterprise_template = enterprise | 519 | e.enterprise_template = enterprise |
| 520 | assert_equal enterprise, e.enterprise_template | 520 | assert_equal enterprise, e.enterprise_template |
| 521 | end | 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 | should 'have a layout template' do | 585 | should 'have a layout template' do |
| 524 | e = build(Environment, :layout_template => 'mytemplate') | 586 | e = build(Environment, :layout_template => 'mytemplate') |
| 525 | assert_equal 'mytemplate', e.layout_template | 587 | assert_equal 'mytemplate', e.layout_template |
test/unit/profile_test.rb
| @@ -883,7 +883,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -883,7 +883,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 883 | 883 | ||
| 884 | should 'copy communities from person template' do | 884 | should 'copy communities from person template' do |
| 885 | template = create_user('test_template').person | 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 | c1 = fast_create(Community) | 888 | c1 = fast_create(Community) |
| 889 | c2 = fast_create(Community) | 889 | c2 = fast_create(Community) |
| @@ -1336,7 +1336,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1336,7 +1336,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 1336 | template = create_user('test_template').person | 1336 | template = create_user('test_template').person |
| 1337 | template.custom_footer = "footer customized" | 1337 | template.custom_footer = "footer customized" |
| 1338 | template.custom_header = "header customized" | 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 | person = create_user_full('mytestuser').person | 1341 | person = create_user_full('mytestuser').person |
| 1342 | assert_equal "footer customized", person.custom_footer | 1342 | assert_equal "footer customized", person.custom_footer |