Commit 07e24499d212b00d38aa0a508f0e2d0136d6f72c
1 parent
ce1288aa
Exists in
master
and in
21 other branches
refactoring community template management
Showing
3 changed files
with
73 additions
and
24 deletions
Show diff stats
app/models/community.rb
app/models/environment.rb
| ... | ... | @@ -717,13 +717,17 @@ class Environment < ActiveRecord::Base |
| 717 | 717 | ] |
| 718 | 718 | end |
| 719 | 719 | |
| 720 | - def community_template | |
| 720 | + def community_templates | |
| 721 | + self.communities.templates | |
| 722 | + end | |
| 723 | + | |
| 724 | + def community_default_template | |
| 721 | 725 | template = Community.find_by_id settings[:community_template_id] |
| 722 | - template if template && template.is_template | |
| 726 | + template if template && template.is_template? | |
| 723 | 727 | end |
| 724 | 728 | |
| 725 | - def community_template=(value) | |
| 726 | - settings[:community_template_id] = value.id | |
| 729 | + def community_default_template=(value) | |
| 730 | + settings[:community_template_id] = value.kind_of?(Community) ? value.id : value | |
| 727 | 731 | end |
| 728 | 732 | |
| 729 | 733 | def person_templates |
| ... | ... | @@ -845,7 +849,7 @@ class Environment < ActiveRecord::Base |
| 845 | 849 | |
| 846 | 850 | self.enterprise_template = enterprise_template |
| 847 | 851 | self.inactive_enterprise_template = inactive_enterprise_template |
| 848 | - self.community_template = community_template | |
| 852 | + self.community_default_template = community_template | |
| 849 | 853 | self.person_default_template = person_template |
| 850 | 854 | self.save! |
| 851 | 855 | end | ... | ... |
test/unit/environment_test.rb
| ... | ... | @@ -494,32 +494,16 @@ class EnvironmentTest < ActiveSupport::TestCase |
| 494 | 494 | # the templates must be created |
| 495 | 495 | assert_kind_of Enterprise, e.enterprise_template |
| 496 | 496 | assert_kind_of Enterprise, e.inactive_enterprise_template |
| 497 | - assert_kind_of Community, e.community_template | |
| 497 | + assert_kind_of Community, e.community_default_template | |
| 498 | 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 | - assert !e.community_template.visible? | |
| 503 | + assert !e.community_default_template.visible? | |
| 504 | 504 | assert !e.person_default_template.visible? |
| 505 | 505 | end |
| 506 | 506 | |
| 507 | - should 'set templates' do | |
| 508 | - e = fast_create(Environment) | |
| 509 | - | |
| 510 | - comm = fast_create(Community, :is_template => true) | |
| 511 | - e.community_template = comm | |
| 512 | - assert_equal comm, e.community_template | |
| 513 | - | |
| 514 | - person = fast_create(Person, :is_template => true) | |
| 515 | - e.person_default_template = person | |
| 516 | - assert_equal person, e.person_default_template | |
| 517 | - | |
| 518 | - enterprise = fast_create(Enterprise, :is_template => true) | |
| 519 | - e.enterprise_template = enterprise | |
| 520 | - assert_equal enterprise, e.enterprise_template | |
| 521 | - end | |
| 522 | - | |
| 523 | 507 | should 'person_templates return all templates of person' do |
| 524 | 508 | e = fast_create(Environment) |
| 525 | 509 | |
| ... | ... | @@ -581,6 +565,67 @@ class EnvironmentTest < ActiveSupport::TestCase |
| 581 | 565 | assert_equal p3, e.person_default_template |
| 582 | 566 | end |
| 583 | 567 | |
| 568 | + should 'community_templates return all templates of community' do | |
| 569 | + e = fast_create(Environment) | |
| 570 | + | |
| 571 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 572 | + c2 = fast_create(Community, :environment_id => e.id) | |
| 573 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 574 | + assert_equivalent [c1,c3], e.community_templates | |
| 575 | + end | |
| 576 | + | |
| 577 | + should 'community_templates return an empty array if there is no templates of community' do | |
| 578 | + e = fast_create(Environment) | |
| 579 | + | |
| 580 | + fast_create(Community, :environment_id => e.id) | |
| 581 | + fast_create(Community, :environment_id => e.id) | |
| 582 | + assert_equivalent [], e.community_templates | |
| 583 | + end | |
| 584 | + | |
| 585 | + should 'community_default_template return the template defined as default' do | |
| 586 | + e = fast_create(Environment) | |
| 587 | + | |
| 588 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 589 | + c2 = fast_create(Community, :environment_id => e.id) | |
| 590 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 591 | + | |
| 592 | + e.settings[:community_template_id]= c3.id | |
| 593 | + assert_equal c3, e.community_default_template | |
| 594 | + end | |
| 595 | + | |
| 596 | + should 'community_default_template not return a community if its not a template' do | |
| 597 | + e = fast_create(Environment) | |
| 598 | + | |
| 599 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 600 | + c2 = fast_create(Community, :environment_id => e.id) | |
| 601 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 602 | + | |
| 603 | + e.settings[:community_template_id]= c2.id | |
| 604 | + assert_nil e.community_default_template | |
| 605 | + end | |
| 606 | + | |
| 607 | + should 'community_default_template= define a community model passed as paremeter as default template' do | |
| 608 | + e = fast_create(Environment) | |
| 609 | + | |
| 610 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 611 | + c2 = fast_create(Community, :environment_id => e.id) | |
| 612 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 613 | + | |
| 614 | + e.community_default_template= c3 | |
| 615 | + assert_equal c3, e.community_default_template | |
| 616 | + end | |
| 617 | + | |
| 618 | + should 'community_default_template= define an id passed as paremeter as the default template' do | |
| 619 | + e = fast_create(Environment) | |
| 620 | + | |
| 621 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 622 | + c2 = fast_create(Community, :environment_id => e.id) | |
| 623 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
| 624 | + | |
| 625 | + e.community_default_template= c3.id | |
| 626 | + assert_equal c3, e.community_default_template | |
| 627 | + end | |
| 628 | + | |
| 584 | 629 | |
| 585 | 630 | should 'have a layout template' do |
| 586 | 631 | e = build(Environment, :layout_template => 'mytemplate') | ... | ... |