Commit 600d8e0fa2f3f7528d6b7a0e8980e63a5ed2d9ab
1 parent
07e24499
Exists in
master
and in
27 other branches
refactoring enterprise template management
Showing
3 changed files
with
72 additions
and
8 deletions
Show diff stats
app/models/enterprise.rb
app/models/environment.rb
... | ... | @@ -743,13 +743,17 @@ class Environment < ActiveRecord::Base |
743 | 743 | settings[:person_template_id] = value.kind_of?(Person) ? value.id : value |
744 | 744 | end |
745 | 745 | |
746 | - def enterprise_template | |
746 | + def enterprise_templates | |
747 | + self.enterprises.templates | |
748 | + end | |
749 | + | |
750 | + def enterprise_default_template | |
747 | 751 | template = Enterprise.find_by_id settings[:enterprise_template_id] |
748 | - template if template && template.is_template | |
752 | + template if template && template.is_template? | |
749 | 753 | end |
750 | 754 | |
751 | - def enterprise_template=(value) | |
752 | - settings[:enterprise_template_id] = value.id | |
755 | + def enterprise_default_template=(value) | |
756 | + settings[:enterprise_template_id] = value.kind_of?(Enterprise) ? value.id : value | |
753 | 757 | end |
754 | 758 | |
755 | 759 | def inactive_enterprise_template |
... | ... | @@ -847,7 +851,7 @@ class Environment < ActiveRecord::Base |
847 | 851 | person_template.visible = false |
848 | 852 | person_template.save! |
849 | 853 | |
850 | - self.enterprise_template = enterprise_template | |
854 | + self.enterprise_default_template = enterprise_template | |
851 | 855 | self.inactive_enterprise_template = inactive_enterprise_template |
852 | 856 | self.community_default_template = community_template |
853 | 857 | self.person_default_template = person_template | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -492,13 +492,13 @@ class EnvironmentTest < ActiveSupport::TestCase |
492 | 492 | e.reload |
493 | 493 | |
494 | 494 | # the templates must be created |
495 | - assert_kind_of Enterprise, e.enterprise_template | |
495 | + assert_kind_of Enterprise, e.enterprise_default_template | |
496 | 496 | assert_kind_of Enterprise, e.inactive_enterprise_template |
497 | 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 | - assert !e.enterprise_template.visible? | |
501 | + assert !e.enterprise_default_template.visible? | |
502 | 502 | assert !e.inactive_enterprise_template.visible? |
503 | 503 | assert !e.community_default_template.visible? |
504 | 504 | assert !e.person_default_template.visible? |
... | ... | @@ -626,6 +626,66 @@ class EnvironmentTest < ActiveSupport::TestCase |
626 | 626 | assert_equal c3, e.community_default_template |
627 | 627 | end |
628 | 628 | |
629 | + should 'enterprise_templates return all templates of enterprise' do | |
630 | + env = fast_create(Environment) | |
631 | + | |
632 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
633 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
634 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
635 | + assert_equivalent [e1,e3], env.enterprise_templates | |
636 | + end | |
637 | + | |
638 | + should 'enterprise_templates return an empty array if there is no templates of enterprise' do | |
639 | + env = fast_create(Environment) | |
640 | + | |
641 | + fast_create(Enterprise, :environment_id => env.id) | |
642 | + fast_create(Enterprise, :environment_id => env.id) | |
643 | + assert_equivalent [], env.enterprise_templates | |
644 | + end | |
645 | + | |
646 | + should 'enterprise_default_template return the template defined as default' do | |
647 | + env = fast_create(Environment) | |
648 | + | |
649 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
650 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
651 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
652 | + | |
653 | + env.settings[:enterprise_template_id]= e3.id | |
654 | + assert_equal e3, env.enterprise_default_template | |
655 | + end | |
656 | + | |
657 | + should 'enterprise_default_template not return a enterprise if its not a template' do | |
658 | + env = fast_create(Environment) | |
659 | + | |
660 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
661 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
662 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
663 | + | |
664 | + env.settings[:enterprise_template_id]= e2.id | |
665 | + assert_nil env.enterprise_default_template | |
666 | + end | |
667 | + | |
668 | + should 'enterprise_default_template= define a enterprise model passed as paremeter as default template' do | |
669 | + env = fast_create(Environment) | |
670 | + | |
671 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
672 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
673 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
674 | + | |
675 | + env.enterprise_default_template= e3 | |
676 | + assert_equal e3, env.enterprise_default_template | |
677 | + end | |
678 | + | |
679 | + should 'enterprise_default_template= define an id passed as paremeter as the default template' do | |
680 | + env = fast_create(Environment) | |
681 | + | |
682 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
683 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
684 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
685 | + | |
686 | + env.enterprise_default_template= e3.id | |
687 | + assert_equal e3, env.enterprise_default_template | |
688 | + end | |
629 | 689 | |
630 | 690 | should 'have a layout template' do |
631 | 691 | e = build(Environment, :layout_template => 'mytemplate') | ... | ... |