Commit 4887d77f758ab92976b7ca09853da2b3ff1e0a00

Authored by Victor Costa
2 parents a995a51a 7db7ec2a

Merge branch 'rails3_stable' of gitlab.com:participa/noosfero into rails3_stable

@@ -17,6 +17,7 @@ gem 'nokogiri' @@ -17,6 +17,7 @@ gem 'nokogiri'
17 gem 'rake', :require => false 17 gem 'rake', :require => false
18 gem 'grape', '0.2.1' 18 gem 'grape', '0.2.1'
19 gem 'rest-client' 19 gem 'rest-client'
  20 +gem 'exception_notification'
20 21
21 # FIXME list here all actual dependencies (i.e. the ones in debian/control), 22 # FIXME list here all actual dependencies (i.e. the ones in debian/control),
22 # with their GEM names (not the Debian package names) 23 # with their GEM names (not the Debian package names)
@@ -62,6 +62,9 @@ GEM @@ -62,6 +62,9 @@ GEM
62 diff-lcs (1.1.3) 62 diff-lcs (1.1.3)
63 erubis (2.7.0) 63 erubis (2.7.0)
64 eventmachine (0.12.10) 64 eventmachine (0.12.10)
  65 + exception_notification (4.0.1)
  66 + actionmailer (>= 3.0.4)
  67 + activesupport (>= 3.0.4)
65 fast_gettext (0.6.8) 68 fast_gettext (0.6.8)
66 ffi (1.0.11) 69 ffi (1.0.11)
67 gherkin (2.4.21) 70 gherkin (2.4.21)
@@ -167,6 +170,7 @@ DEPENDENCIES @@ -167,6 +170,7 @@ DEPENDENCIES
167 daemons 170 daemons
168 dalli 171 dalli
169 database_cleaner 172 database_cleaner
  173 + exception_notification
170 fast_gettext 174 fast_gettext
171 hpricot 175 hpricot
172 mocha 176 mocha
app/controllers/admin/templates_controller.rb
@@ -40,8 +40,40 @@ class TemplatesController < AdminController @@ -40,8 +40,40 @@ class TemplatesController < AdminController
40 end 40 end
41 end 41 end
42 42
  43 + def set_community_as_default
  44 + set_as_default(Community.find(params[:template_id]))
  45 + redirect_to :action => 'index'
  46 + end
  47 +
  48 + def set_person_as_default
  49 + set_as_default(Person.find(params[:template_id]))
  50 + redirect_to :action => 'index'
  51 + end
  52 +
  53 + def set_enterprise_as_default
  54 + set_as_default(Enterprise.find(params[:template_id]))
  55 + redirect_to :action => 'index'
  56 + end
  57 +
43 private 58 private
44 59
  60 + def set_as_default(obj)
  61 + return nil if obj.nil?
  62 + case obj.class.name
  63 + when 'Community' then
  64 + environment.community_default_template = obj
  65 + environment.save!
  66 + when 'Person' then
  67 + environment.person_default_template = obj
  68 + environment.save!
  69 + when 'Enterprise' then
  70 + environment.enterprise_default_template = obj
  71 + environment.save!
  72 + else
  73 + nil
  74 + end
  75 + end
  76 +
45 def create_organization_template(klass) 77 def create_organization_template(klass)
46 identifier = params[:name].to_slug 78 identifier = params[:name].to_slug
47 template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true) 79 template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true)
app/helpers/application_helper.rb
@@ -1318,10 +1318,8 @@ module ApplicationHelper @@ -1318,10 +1318,8 @@ module ApplicationHelper
1318 return '' if templates.count == 0 1318 return '' if templates.count == 0
1319 return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 1319 return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1
1320 1320
1321 - counter = 0  
1322 radios = templates.map do |template| 1321 radios = templates.map do |template|
1323 - counter += 1  
1324 - content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, counter==1)) 1322 + content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, environment.is_default_template?(template)))
1325 end.join("\n") 1323 end.join("\n")
1326 1324
1327 content_tag('div', content_tag('label', _('Profile organization'), :for => 'template-options', :class => 'formlabel') + 1325 content_tag('div', content_tag('label', _('Profile organization'), :for => 'template-options', :class => 'formlabel') +
app/models/community.rb
@@ -78,7 +78,7 @@ class Community < Organization @@ -78,7 +78,7 @@ class Community < Organization
78 end 78 end
79 79
80 def default_template 80 def default_template
81 - environment.community_template 81 + environment.community_default_template
82 end 82 end
83 83
84 def news(limit = 30, highlight = false) 84 def news(limit = 30, highlight = false)
app/models/enterprise.rb
@@ -166,7 +166,7 @@ class Enterprise < Organization @@ -166,7 +166,7 @@ class Enterprise < Organization
166 end 166 end
167 167
168 def default_template 168 def default_template
169 - environment.enterprise_template 169 + environment.enterprise_default_template
170 end 170 end
171 171
172 def template_with_inactive_enterprise 172 def template_with_inactive_enterprise
app/models/environment.rb
@@ -735,31 +735,50 @@ class Environment < ActiveRecord::Base @@ -735,31 +735,50 @@ class Environment < ActiveRecord::Base
735 ] 735 ]
736 end 736 end
737 737
738 - def community_template 738 + def is_default_template?(template)
  739 + is_default = template == community_default_template
  740 + is_default = is_default || template == person_default_template
  741 + is_default = is_default || template == enterprise_default_template
  742 + is_default
  743 + end
  744 +
  745 + def community_templates
  746 + self.communities.templates
  747 + end
  748 +
  749 + def community_default_template
739 template = Community.find_by_id settings[:community_template_id] 750 template = Community.find_by_id settings[:community_template_id]
740 - template if template && template.is_template 751 + template if template && template.is_template?
741 end 752 end
742 753
743 - def community_template=(value)  
744 - settings[:community_template_id] = value.id 754 + def community_default_template=(value)
  755 + settings[:community_template_id] = value.kind_of?(Community) ? value.id : value
745 end 756 end
746 757
747 - def person_template 758 + def person_templates
  759 + self.people.templates
  760 + end
  761 +
  762 + def person_default_template
748 template = Person.find_by_id settings[:person_template_id] 763 template = Person.find_by_id settings[:person_template_id]
749 - template if template && template.is_template 764 + template if template && template.is_template?
750 end 765 end
751 766
752 - def person_template=(value)  
753 - settings[:person_template_id] = value.id 767 + def person_default_template=(value)
  768 + settings[:person_template_id] = value.kind_of?(Person) ? value.id : value
754 end 769 end
755 770
756 - def enterprise_template 771 + def enterprise_templates
  772 + self.enterprises.templates
  773 + end
  774 +
  775 + def enterprise_default_template
757 template = Enterprise.find_by_id settings[:enterprise_template_id] 776 template = Enterprise.find_by_id settings[:enterprise_template_id]
758 - template if template && template.is_template 777 + template if template && template.is_template?
759 end 778 end
760 779
761 - def enterprise_template=(value)  
762 - settings[:enterprise_template_id] = value.id 780 + def enterprise_default_template=(value)
  781 + settings[:enterprise_template_id] = value.kind_of?(Enterprise) ? value.id : value
763 end 782 end
764 783
765 def inactive_enterprise_template 784 def inactive_enterprise_template
@@ -857,10 +876,10 @@ class Environment < ActiveRecord::Base @@ -857,10 +876,10 @@ class Environment < ActiveRecord::Base
857 person_template.visible = false 876 person_template.visible = false
858 person_template.save! 877 person_template.save!
859 878
860 - self.enterprise_template = enterprise_template 879 + self.enterprise_default_template = enterprise_template
861 self.inactive_enterprise_template = inactive_enterprise_template 880 self.inactive_enterprise_template = inactive_enterprise_template
862 - self.community_template = community_template  
863 - self.person_template = person_template 881 + self.community_default_template = community_template
  882 + self.person_default_template = person_template
864 self.save! 883 self.save!
865 end 884 end
866 885
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>
@@ -15,6 +16,11 @@ @@ -15,6 +16,11 @@
15 <li> 16 <li>
16 <%= image_tag "icons-app/#{kind}-icon.png" %> 17 <%= image_tag "icons-app/#{kind}-icon.png" %>
17 <%= link_to(template.name, {:controller => 'profile_editor', :profile => template.identifier}, :title => _('Edit template "%s"') % template.name ) %> 18 <%= link_to(template.name, {:controller => 'profile_editor', :profile => template.identifier}, :title => _('Edit template "%s"') % template.name ) %>
  19 + <% if environment.is_default_template?(template) %>
  20 + <%= _('is the default template') %>
  21 + <% else %>
  22 + <%= link_to(_('Set as default'), {:action => "set_#{kind}_as_default", :template_id => template.id}, :title => _('Set %s template as default') % template.name ) %>
  23 + <% end %>
18 </li> 24 </li>
19 <% end %> 25 <% end %>
20 </ul> 26 </ul>
config/initializers/exception_notification.rb
1 unless NOOSFERO_CONF['exception_recipients'].blank? 1 unless NOOSFERO_CONF['exception_recipients'].blank?
2 - require 'noosfero.rb'  
3 - require 'exception_notification.rb'  
4 - ExceptionNotifier.sender_address = "noreply@#{Noosfero.default_hostname}"  
5 - ExceptionNotifier.email_prefix = "[Noosfero ERROR] "  
6 - ExceptionNotifier.exception_recipients = NOOSFERO_CONF['exception_recipients']  
7 - ActionController::Base.send :include, ExceptionNotifiable 2 + Noosfero::Application.config.middleware.use ExceptionNotification::Rack,
  3 + :email => {
  4 + :sender_address => "noreply@#{Noosfero.default_hostname}",
  5 + :email_prefix => "[Noosfero ERROR] ",
  6 + :exception_recipients => NOOSFERO_CONF['exception_recipients']
  7 + }
8 end 8 end
test/functional/templates_controller_test.rb
@@ -6,14 +6,17 @@ class TemplatesController; def rescue_action(e) raise e end; end @@ -6,14 +6,17 @@ class TemplatesController; def rescue_action(e) raise e end; end
6 6
7 class TemplatesControllerTest < ActionController::TestCase 7 class TemplatesControllerTest < ActionController::TestCase
8 8
9 - all_fixtures  
10 def setup 9 def setup
11 @controller = TemplatesController.new 10 @controller = TemplatesController.new
12 @request = ActionController::TestRequest.new 11 @request = ActionController::TestRequest.new
13 @response = ActionController::TestResponse.new 12 @response = ActionController::TestResponse.new
14 - login_as(create_admin_user(Environment.default)) 13 + Environment.destroy_all
  14 + @environment = fast_create(Environment, :is_default => true)
  15 + login_as(create_admin_user(@environment))
15 end 16 end
16 17
  18 + attr_accessor :environment
  19 +
17 should 'create person template' do 20 should 'create person template' do
18 post :create_person_template, :name => 'Developer' 21 post :create_person_template, :name => 'Developer'
19 assert Person['developer'].is_template 22 assert Person['developer'].is_template
@@ -28,5 +31,45 @@ class TemplatesControllerTest &lt; ActionController::TestCase @@ -28,5 +31,45 @@ class TemplatesControllerTest &lt; ActionController::TestCase
28 post :create_enterprise_template, :name => 'Free Software Foundation' 31 post :create_enterprise_template, :name => 'Free Software Foundation'
29 assert Enterprise['free-software-foundation'].is_template 32 assert Enterprise['free-software-foundation'].is_template
30 end 33 end
  34 +
  35 + should 'set a community as default template' do
  36 +
  37 + c1= fast_create(Community, :is_template => true, :environment_id => environment.id)
  38 + environment.community_default_template= c1
  39 + environment.save
  40 +
  41 + c3 = fast_create(Community, :is_template => true, :environment_id => environment.id)
  42 +
  43 + post :set_community_as_default, :template_id => c3.id
  44 + environment.reload
  45 + assert_equal c3, environment.community_default_template
  46 + end
  47 +
  48 + should 'set a person as default template' do
  49 +
  50 + p1= fast_create(Person, :is_template => true, :environment_id => environment.id)
  51 + environment.person_default_template= p1
  52 + environment.save
  53 +
  54 + p3 = fast_create(Person, :is_template => true, :environment_id => environment.id)
  55 +
  56 + post :set_person_as_default, :template_id => p3.id
  57 + environment.reload
  58 + assert_equal p3, environment.person_default_template
  59 + end
  60 +
  61 + should 'set a enterprise as default template' do
  62 +
  63 + e1= fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
  64 + environment.enterprise_default_template= e1
  65 + environment.save
  66 +
  67 + e3 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
  68 +
  69 + post :set_enterprise_as_default, :template_id => e3.id
  70 + environment.reload
  71 + assert_equal e3, environment.enterprise_default_template
  72 + end
  73 +
31 end 74 end
32 75
test/unit/enterprise_test.rb
@@ -169,7 +169,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -169,7 +169,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
169 169
170 e = Environment.default 170 e = Environment.default
171 e.replace_enterprise_template_when_enable = true 171 e.replace_enterprise_template_when_enable = true
172 - e.enterprise_template = template 172 + e.enterprise_default_template = template
173 e.save! 173 e.save!
174 174
175 ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) 175 ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
@@ -192,7 +192,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -192,7 +192,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
192 192
193 e = Environment.default 193 e = Environment.default
194 e.inactive_enterprise_template = inactive_template 194 e.inactive_enterprise_template = inactive_template
195 - e.enterprise_template = active_template 195 + e.enterprise_default_template = active_template
196 e.save! 196 e.save!
197 197
198 ent = create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) 198 ent = create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
test/unit/environment_test.rb
@@ -492,32 +492,235 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -492,32 +492,235 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
492 e.reload 492 e.reload
493 493
494 # the templates must be created 494 # the templates must be created
495 - assert_kind_of Enterprise, e.enterprise_template 495 + assert_kind_of Enterprise, e.enterprise_default_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  
498 - assert_kind_of Person, e.person_template 497 + assert_kind_of Community, e.community_default_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_default_template.visible?
502 assert !e.inactive_enterprise_template.visible? 502 assert !e.inactive_enterprise_template.visible?
503 - assert !e.community_template.visible?  
504 - assert !e.person_template.visible? 503 + assert !e.community_default_template.visible?
  504 + assert !e.person_default_template.visible?
505 end 505 end
506 506
507 - should 'set templates' do 507 + should 'person_templates return all templates of person' do
508 e = fast_create(Environment) 508 e = fast_create(Environment)
509 509
510 - comm = fast_create(Community, :is_template => true)  
511 - e.community_template = comm  
512 - assert_equal comm, e.community_template 510 + p1= fast_create(Person, :is_template => true, :environment_id => e.id)
  511 + p2 = fast_create(Person, :environment_id => e.id)
  512 + p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
  513 + assert_equivalent [p1,p3], e.person_templates
  514 + end
  515 +
  516 + should 'person_templates return an empty array if there is no templates of person' do
  517 + e = fast_create(Environment)
  518 +
  519 + fast_create(Person, :environment_id => e.id)
  520 + fast_create(Person, :environment_id => e.id)
  521 + assert_equivalent [], e.person_templates
  522 + end
  523 +
  524 + should 'person_default_template return the template defined as default' do
  525 + e = fast_create(Environment)
  526 +
  527 + p1= fast_create(Person, :is_template => true, :environment_id => e.id)
  528 + p2 = fast_create(Person, :environment_id => e.id)
  529 + p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
  530 +
  531 + e.settings[:person_template_id]= p3.id
  532 + assert_equal p3, e.person_default_template
  533 + end
  534 +
  535 + should 'person_default_template not return a person if its not a template' do
  536 + e = fast_create(Environment)
  537 +
  538 + p1= fast_create(Person, :is_template => true, :environment_id => e.id)
  539 + p2 = fast_create(Person, :environment_id => e.id)
  540 + p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
  541 +
  542 + e.settings[:person_template_id]= p2.id
  543 + assert_nil e.person_default_template
  544 + end
  545 +
  546 + should 'person_default_template= define a person model passed as paremeter as default template' do
  547 + e = fast_create(Environment)
  548 +
  549 + p1= fast_create(Person, :is_template => true, :environment_id => e.id)
  550 + p2 = fast_create(Person, :environment_id => e.id)
  551 + p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
  552 +
  553 + e.person_default_template= p3
  554 + assert_equal p3, e.person_default_template
  555 + end
  556 +
  557 + should 'person_default_template= define an id passed as paremeter as the default template' do
  558 + e = fast_create(Environment)
  559 +
  560 + p1= fast_create(Person, :is_template => true, :environment_id => e.id)
  561 + p2 = fast_create(Person, :environment_id => e.id)
  562 + p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
  563 +
  564 + e.person_default_template= p3.id
  565 + assert_equal p3, e.person_default_template
  566 + end
  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 +
  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
  689 +
  690 + should 'is_default_template? method identify a person default template as default' do
  691 + env = fast_create(Environment)
  692 +
  693 + p1 = fast_create(Person, :is_template => true, :environment_id => env.id)
  694 + env.person_default_template= p1.id
  695 + assert env.is_default_template?(p1)
  696 +
  697 + p2 = fast_create(Person, :is_template => true, :environment_id => env.id)
  698 + env.person_default_template= p2.id
  699 + assert !env.is_default_template?(p1)
  700 + end
  701 +
  702 + should 'is_default_template? method identify a community default template as default' do
  703 + env = fast_create(Environment)
  704 +
  705 + c1 = fast_create(Community, :is_template => true, :environment_id => env.id)
  706 + env.community_default_template= c1.id
  707 + assert env.is_default_template?(c1)
  708 +
  709 + c2 = fast_create(Community, :is_template => true, :environment_id => env.id)
  710 + env.community_default_template= c2.id
  711 + assert !env.is_default_template?(c1)
  712 + end
  713 +
  714 + should 'is_default_template? method identify a enterprise default template as default' do
  715 + env = fast_create(Environment)
513 716
514 - person = fast_create(Person, :is_template => true)  
515 - e.person_template = person  
516 - assert_equal person, e.person_template 717 + e1 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
  718 + env.enterprise_default_template= e1.id
  719 + assert env.is_default_template?(e1)
517 720
518 - enterprise = fast_create(Enterprise, :is_template => true)  
519 - e.enterprise_template = enterprise  
520 - assert_equal enterprise, e.enterprise_template 721 + e2 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
  722 + env.enterprise_default_template= e2.id
  723 + assert !env.is_default_template?(e1)
521 end 724 end
522 725
523 should 'have a layout template' do 726 should 'have a layout template' do
test/unit/profile_test.rb
@@ -883,7 +883,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -883,7 +883,7 @@ class ProfileTest &lt; 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 &lt; ActiveSupport::TestCase @@ -1336,7 +1336,7 @@ class ProfileTest &lt; 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