noosfero | 15 new commits pushed to repository

Leandro Nunes gitlab at gitlab.com
Mon Jan 26 19:25:36 BRST 2015


Leandro Nunes pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/b2083dec369e86e6136522d8940e0975960ee2f6">b2083dec</a> by Leandro Nunes dos Santos
refactoring person template management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/72cfd5811d1beaa9fb874fd339d71e4bd3bf87cc">72cfd581</a> by Leandro Nunes dos Santos
Merge branches 'rails3' and 'ActionItem3268_template_management' into ActionItem3268_template_management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/ce1288aa6e4a42ebbc00a22dac96548ffc7525af">ce1288aa</a> by Leandro Nunes dos Santos
Merge branches 'rails3' and 'AI3268_template_management' into AI3268_template_management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/07e24499d212b00d38aa0a508f0e2d0136d6f72c">07e24499</a> by Leandro Nunes dos Santos
refactoring community template management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/600d8e0fa2f3f7528d6b7a0e8980e63a5ed2d9ab">600d8e0f</a> by Leandro Nunes dos Santos
refactoring enterprise template management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/3b569fa2ace22975284e68df02794cb03457dda2">3b569fa2</a> by Leandro Nunes dos Santos
Add set as default method for templates

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/e707aa99fb0a41ef8a4a38fcb78f64c38d9461f3">e707aa99</a> by Leandro Nunes dos Santos
Put the default template selected by default

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/c3b9486bdd915cefee7cc9813c142fdc6fe7e14a">c3b9486b</a> by Leandro Nunes dos Santos
Merge branches 'rails3' and 'AI3268_template_management' into AI3268_template_management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/953ad391f5eeb50f6ca7fe724e3df5bc7ea6c7e5">953ad391</a> by Leandro Nunes dos Santos
remove reference to enterprise_template= method

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/4f321345fb89ebdeb44e4bb879b426800bbdbc79">4f321345</a> by Leandro Nunes dos Santos
Merge branches 'master' and 'AI3268_template_management' into AI3268_template_management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/242318b0008c594d5fac0a97f20844c1aee8dffe">242318b0</a> by Leandro Nunes dos Santos
Avoid template definition of another environment

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/98ecbe010b5ca4aac811b93c32aab02f74fe14b5">98ecbe01</a> by Leandro Nunes dos Santos
Add functional tests to check if default option is cheched by default

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/d6f4caa49dcdc6949a28a1b7e2437f0978dd19be">d6f4caa4</a> by Leandro Nunes dos Santos
Add tests to check the presence of set_as_default link

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/b6d2e88c26a5a213eff18d6fd391e750e5acbee8">b6d2e88c</a> by Leandro Nunes dos Santos
Merge branch 'master' into AI3268_template_management

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/a7f0469c7337982e342f96a521ae60ba23d7319a">a7f0469c</a> by Leandro Nunes
Merge branch 'AI3268_template_management' into 'master'

Improve templates management

Actually the templates management is very strange.
You don't have how to define a template as default and when you create a community the first template is alwyas de default one.

More details in http://noosfero.org/Development/ActionItem3268

See merge request !298

- - - - -


Changes:

=====================================
app/controllers/admin/templates_controller.rb
=====================================
--- a/app/controllers/admin/templates_controller.rb
+++ b/app/controllers/admin/templates_controller.rb
@@ -40,8 +40,67 @@ class TemplatesController < AdminController
     end
   end
 
+  def set_community_as_default
+    begin
+      community = environment.communities.find(params[:template_id])
+    rescue ActiveRecord::RecordNotFound
+      message = _('Community not found. The template could no be changed.')
+      community = nil
+    end
+
+    message = _('%s defined as default') % community.name if set_as_default(community)
+    session[:notice] = message
+
+    redirect_to :action => 'index'
+  end
+
+  def set_person_as_default
+    begin
+      person = environment.people.find(params[:template_id])
+    rescue ActiveRecord::RecordNotFound
+      message = _('Person not found. The template could no be changed.')
+      person = nil
+    end
+
+    message = _('%s defined as default') % person.name if set_as_default(person)
+    session[:notice] = message
+
+    redirect_to :action => 'index'
+  end
+
+  def set_enterprise_as_default
+    begin
+      enterprise = environment.enterprises.find(params[:template_id])
+    rescue ActiveRecord::RecordNotFound
+      message = _('Enterprise not found. The template could no be changed.')
+      enterprise = nil
+    end
+
+    message = _('%s defined as default') % enterprise.name if set_as_default(enterprise)
+    session[:notice] = message
+
+    redirect_to :action => 'index'
+  end
+
   private
 
+  def set_as_default(obj)
+    return nil if obj.nil?
+    case obj.class.name
+      when 'Community' then
+        environment.community_default_template = obj
+        environment.save!
+      when 'Person' then
+        environment.person_default_template = obj
+        environment.save!
+      when 'Enterprise' then
+        environment.enterprise_default_template = obj
+        environment.save!
+      else
+        nil
+    end
+  end
+
   def create_organization_template(klass)
     identifier = params[:name].to_slug
     template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true)

=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1315,10 +1315,8 @@ module ApplicationHelper
     return '' if templates.count == 0
     return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1
 
-    counter = 0
     radios = templates.map do |template|
-      counter += 1
-      content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, counter==1))
+      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)))
     end.join("\n")
 
     content_tag('div', content_tag('label', _('Profile organization'), :for => 'template-options', :class => 'formlabel') +

=====================================
app/models/community.rb
=====================================
--- a/app/models/community.rb
+++ b/app/models/community.rb
@@ -68,7 +68,7 @@ class Community < Organization
   end
 
   def default_template
-    environment.community_template
+    environment.community_default_template
   end
 
   def news(limit = 30, highlight = false)

=====================================
app/models/enterprise.rb
=====================================
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -164,7 +164,7 @@ class Enterprise < Organization
   end
 
   def default_template
-    environment.enterprise_template
+    environment.enterprise_default_template
   end
 
   def template_with_inactive_enterprise

=====================================
app/models/environment.rb
=====================================
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -729,31 +729,50 @@ class Environment < ActiveRecord::Base
     ]
   end
 
-  def community_template
+  def is_default_template?(template)
+    is_default = template == community_default_template 
+    is_default = is_default || template == person_default_template 
+    is_default = is_default || template == enterprise_default_template
+    is_default
+  end
+
+  def community_templates
+    self.communities.templates
+  end
+
+  def community_default_template
     template = Community.find_by_id settings[:community_template_id]
-    template if template && template.is_template
+    template if template && template.is_template?
   end
 
-  def community_template=(value)
-    settings[:community_template_id] = value.id
+  def community_default_template=(value)
+    settings[:community_template_id] = value.kind_of?(Community) ? value.id : value
   end
 
-  def person_template
+  def person_templates
+    self.people.templates
+  end
+
+  def person_default_template
     template = Person.find_by_id settings[:person_template_id]
-    template if template && template.is_template
+    template if template && template.is_template?
   end
 
-  def person_template=(value)
-    settings[:person_template_id] = value.id
+  def person_default_template=(value)
+    settings[:person_template_id] = value.kind_of?(Person) ? value.id : value
   end
 
-  def enterprise_template
+  def enterprise_templates
+    self.enterprises.templates
+  end
+
+  def enterprise_default_template
     template = Enterprise.find_by_id settings[:enterprise_template_id]
-    template if template && template.is_template
+    template if template && template.is_template?
   end
 
-  def enterprise_template=(value)
-    settings[:enterprise_template_id] = value.id
+  def enterprise_default_template=(value)
+    settings[:enterprise_template_id] = value.kind_of?(Enterprise) ? value.id : value
   end
 
   def inactive_enterprise_template
@@ -851,10 +870,10 @@ class Environment < ActiveRecord::Base
     person_template.visible = false
     person_template.save!
 
-    self.enterprise_template = enterprise_template
+    self.enterprise_default_template = enterprise_template
     self.inactive_enterprise_template = inactive_enterprise_template
-    self.community_template = community_template
-    self.person_template = person_template
+    self.community_default_template = community_template
+    self.person_default_template = person_template
     self.save!
   end
 

=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -310,7 +310,7 @@ roles] }
   end
 
   def default_template
-    environment.person_template
+    environment.person_default_template
   end
 
   def apply_type_specific_template(template)

=====================================
app/views/templates/index.html.erb
=====================================
--- a/app/views/templates/index.html.erb
+++ b/app/views/templates/index.html.erb
@@ -2,10 +2,11 @@
 
 <%= _('Manage the templates used on creation of profiles') %>
 
-<% list_of_templates = [[_('Person')    , environment.people.templates     , 'person'    ],
+<% list_of_templates = [[_('Person')    , environment.person_templates     , 'person'    ],
                         [_('Community') , environment.communities.templates, 'community' ],
                         [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %>
 
+
 <% list_of_templates.each do |title, templates, kind|%>
   <div class='template-kind'>
     <h2><%= title %></h2>
@@ -15,6 +16,11 @@
         <li>
           <%= image_tag "icons-app/#{kind}-icon.png" %>
           <%= link_to(template.name, {:controller => 'profile_editor', :profile => template.identifier}, :title => _('Edit template "%s"') % template.name ) %>
+          <% if environment.is_default_template?(template) %>
+            <%= _('is the default template') %>
+          <% else %>
+            <%= link_to(_('Set as default'), {:action => "set_#{kind}_as_default", :template_id => template.id}, :title => _('Set %s template as default') % template.name ) %>
+          <% end %>
         </li>
       <% end %>
     </ul>

=====================================
test/functional/templates_controller_test.rb
=====================================
--- a/test/functional/templates_controller_test.rb
+++ b/test/functional/templates_controller_test.rb
@@ -6,14 +6,17 @@ class TemplatesController; def rescue_action(e) raise e end; end
 
 class TemplatesControllerTest < ActionController::TestCase
 
-  all_fixtures
   def setup
     @controller = TemplatesController.new
     @request    = ActionController::TestRequest.new
     @response   = ActionController::TestResponse.new
-    login_as(create_admin_user(Environment.default))
+    Environment.destroy_all
+    @environment = fast_create(Environment, :is_default => true)
+    login_as(create_admin_user(@environment))
   end
 
+  attr_accessor :environment
+
   should 'create person template' do
     post :create_person_template, :name => 'Developer'
     assert Person['developer'].is_template
@@ -28,5 +31,168 @@ class TemplatesControllerTest < ActionController::TestCase
     post :create_enterprise_template, :name => 'Free Software Foundation'
     assert Enterprise['free-software-foundation'].is_template
   end
+
+  should 'set a community as default template' do
+
+    c1= fast_create(Community, :is_template => true, :environment_id => environment.id)
+    environment.community_default_template= c1
+    environment.save
+ 
+    c3 = fast_create(Community, :is_template => true, :environment_id => environment.id)
+   
+    post :set_community_as_default, :template_id => c3.id
+    environment.reload
+    assert_equal c3, environment.community_default_template
+  end
+
+  should 'set a person as default template' do
+
+    p1= fast_create(Person, :is_template => true, :environment_id => environment.id)
+    environment.person_default_template= p1
+    environment.save
+ 
+    p3 = fast_create(Person, :is_template => true, :environment_id => environment.id)
+   
+    post :set_person_as_default, :template_id => p3.id
+    environment.reload
+    assert_equal p3, environment.person_default_template
+  end
+
+  should 'set a enterprise as default template' do
+
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+    environment.enterprise_default_template= e1
+    environment.save
+ 
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+   
+    post :set_enterprise_as_default, :template_id => e3.id
+    environment.reload
+    assert_equal e3, environment.enterprise_default_template
+  end
+
+  should 'not allow set_community_as_default define a community template of another environment as default' do
+    c1= fast_create(Community, :is_template => true, :environment_id => environment.id)
+    environment.community_default_template= c1
+    environment.save
+
+    env2 = fast_create(Environment)
+
+    c3 = fast_create(Community, :is_template => true, :environment_id => env2.id)
+
+    post :set_community_as_default, :template_id => c3.id
+    environment.reload
+    assert_not_equal c3, environment.community_default_template
+  end
+
+  should 'not allow set_person_as_default define a person template of another environment as default' do
+    p1= fast_create(Person, :is_template => true, :environment_id => environment.id)
+    environment.person_default_template= p1
+    environment.save
+ 
+    env2 = fast_create(Environment)
+    p3 = fast_create(Person, :is_template => true, :environment_id => env2.id)
+   
+    post :set_person_as_default, :template_id => p3.id
+    environment.reload
+    assert_not_equal p3, environment.person_default_template
+
+  end
+
+  should 'not allow set_enterprise_as_default define a enterprise of another environment as default' do
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+    environment.enterprise_default_template= e1
+    environment.save
+ 
+    env2 = fast_create(Environment)
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => env2.id)
+   
+    post :set_enterprise_as_default, :template_id => e3.id
+    environment.reload
+    assert_not_equal e3, environment.enterprise_default_template
+  end
+
+  should 'display successfully notice message after define a community template as default' do
+    c3 = fast_create(Community, :is_template => true, :environment_id => environment)
+
+    post :set_community_as_default, :template_id => c3.id
+    assert_equal "#{c3.name} defined as default", session[:notice]
+  end
+
+  should 'display successfully notice message after define a person template as default' do
+    p3 = fast_create(Person, :is_template => true, :environment_id => environment)
+
+    post :set_person_as_default, :template_id => p3.id
+    assert_equal "#{p3.name} defined as default", session[:notice]
+  end
+
+  should 'display successfully notice message after define a enterprise template as default' do
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => environment)
+
+    post :set_enterprise_as_default, :template_id => e3.id
+    assert_equal "#{e3.name} defined as default", session[:notice]
+  end
+
+  should 'display unsuccessfully notice message when a community template could not be defined as default' do
+    env2 = fast_create(Environment)
+    c3 = fast_create(Community, :is_template => true, :environment_id => env2.id)
+
+    post :set_community_as_default, :template_id => c3.id
+    assert_equal "Community not found. The template could no be changed.", session[:notice]
+  end
+
+  should 'display unsuccessfully notice message when a person template could not be defined as default' do
+    env2 = fast_create(Environment)
+    p3 = fast_create(Person, :is_template => true, :environment_id => env2.id)
+
+    post :set_person_as_default, :template_id => p3.id
+    assert_equal "Person not found. The template could no be changed.", session[:notice]
+  end
+
+  should 'display unsuccessfully notice message when a enterprise template could not be defined as default' do
+    env2 = fast_create(Environment)
+    e3 = fast_create(Community, :is_template => true, :environment_id => env2.id)
+
+    post :set_enterprise_as_default, :template_id => e3.id
+    assert_equal "Enterprise not found. The template could no be changed.", session[:notice]
+  end
+
+  should 'display set as default link for non default community templates' do
+    c1 = fast_create(Community, :is_template => true, :environment_id => environment.id)
+    c2 = fast_create(Community, :is_template => true, :environment_id => environment.id)
+
+    get :index
+    assert_tag :a, '', :attributes => {:href => "/admin/templates/set_community_as_default?template_id=#{c1.id}"}
+    assert_tag :a, '', :attributes => {:href => "/admin/templates/set_community_as_default?template_id=#{c2.id}"}
+  end
+
+  should 'display set as default link for non default person templates' do
+    p1 = fast_create(Person, :is_template => true, :environment_id => environment.id)
+    p2 = fast_create(Person, :is_template => true, :environment_id => environment.id)
+
+    get :index
+    assert_tag :a, '', :attributes => {:href => "/admin/templates/set_person_as_default?template_id=#{p1.id}"}
+    assert_tag :a, '', :attributes => {:href => "/admin/templates/set_person_as_default?template_id=#{p2.id}"}
+  end
+
+  should 'display set as default link for non default enterprise templates' do
+    e1 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+    e2 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+
+    get :index
+    assert_tag :a, '', :attributes => {:href => "/admin/templates/set_enterprise_as_default?template_id=#{e1.id}"}
+    assert_tag :a, '', :attributes => {:href => "/admin/templates/set_enterprise_as_default?template_id=#{e2.id}"}
+  end
+
+  should 'not display set as default link for default community template' do
+    c1 = fast_create(Community, :is_template => true, :environment_id => environment.id)
+    c2 = fast_create(Community, :is_template => true, :environment_id => environment.id)
+    environment.community_default_template= c1
+    environment.save
+
+    get :index
+    assert_no_tag :a, '', :attributes => {:href => "/admin/templates/set_community_as_default?template_id=#{c1.id}"}
+  end
+
 end
 

=====================================
test/unit/application_helper_test.rb
=====================================
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -254,6 +254,44 @@ class ApplicationHelperTest < ActionView::TestCase
     end
   end
 
+  should 'define the community default template as checked' do
+    environment = Environment.default
+    self.stubs(:environment).returns(environment)
+    community = fast_create(Community, :is_template => true, :environment_id => environment.id)
+    fast_create(Community, :is_template => true, :environment_id => environment.id)
+    environment.community_default_template= community
+    environment.save
+    
+    assert_tag_in_string template_options(:communities, 'community'), :tag => 'input',
+                                 :attributes => { :name => "community[template_id]", :value => community.id, :checked => true }
+  end
+
+  should 'define the person default template as checked' do
+    environment = Environment.default
+    self.stubs(:environment).returns(environment)
+    person = fast_create(Person, :is_template => true, :environment_id => environment.id)
+    fast_create(Person, :is_template => true, :environment_id => environment.id)
+    environment.person_default_template= person
+    environment.save
+    
+    assert_tag_in_string template_options(:people, 'profile_data'), :tag => 'input',
+                                 :attributes => { :name => "profile_data[template_id]", :value => person.id, :checked => true }
+  end
+
+  should 'define the enterprise default template as checked' do
+    environment = Environment.default
+    self.stubs(:environment).returns(environment)
+    enterprise = fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+    fast_create(Enterprise, :is_template => true, :environment_id => environment.id)
+
+    environment.enterprise_default_template= enterprise
+    environment.save
+    environment.reload
+    
+    assert_tag_in_string template_options(:enterprises, 'create_enterprise'), :tag => 'input',
+                                 :attributes => { :name => "create_enterprise[template_id]", :value => enterprise.id, :checked => true }
+  end
+
   should 'return nil if disable_categories is enabled' do
     env = fast_create(Environment, :name => 'env test')
     stubs(:environment).returns(env)

=====================================
test/unit/enterprise_test.rb
=====================================
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -169,7 +169,7 @@ class EnterpriseTest < ActiveSupport::TestCase
 
     e = Environment.default
     e.replace_enterprise_template_when_enable = true
-    e.enterprise_template = template
+    e.enterprise_default_template = template
     e.save!
 
     ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
@@ -192,7 +192,7 @@ class EnterpriseTest < ActiveSupport::TestCase
 
     e = Environment.default
     e.inactive_enterprise_template = inactive_template
-    e.enterprise_template = active_template
+    e.enterprise_default_template = active_template
     e.save!
 
     ent = create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false)

=====================================
test/unit/environment_test.rb
=====================================
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -506,32 +506,235 @@ class EnvironmentTest < ActiveSupport::TestCase
     e.reload
 
     # the templates must be created
-    assert_kind_of Enterprise, e.enterprise_template
+    assert_kind_of Enterprise, e.enterprise_default_template
     assert_kind_of Enterprise, e.inactive_enterprise_template
-    assert_kind_of Community, e.community_template
-    assert_kind_of Person, e.person_template
+    assert_kind_of Community, e.community_default_template
+    assert_kind_of Person, e.person_default_template
 
     # the templates must be private
-    assert !e.enterprise_template.visible?
+    assert !e.enterprise_default_template.visible?
     assert !e.inactive_enterprise_template.visible?
-    assert !e.community_template.visible?
-    assert !e.person_template.visible?
+    assert !e.community_default_template.visible?
+    assert !e.person_default_template.visible?
   end
 
-  should 'set templates' do
+  should 'person_templates return all templates of person' do
     e = fast_create(Environment)
 
-    comm = fast_create(Community, :is_template => true)
-    e.community_template = comm
-    assert_equal comm, e.community_template
+    p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+    p2 = fast_create(Person, :environment_id => e.id)
+    p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+    assert_equivalent [p1,p3], e.person_templates    
+  end
+
+  should 'person_templates return an empty array if there is no templates of person' do
+    e = fast_create(Environment)
+
+    fast_create(Person, :environment_id => e.id)
+    fast_create(Person, :environment_id => e.id)
+    assert_equivalent [], e.person_templates    
+  end
+
+  should 'person_default_template return the template defined as default' do
+    e = fast_create(Environment)
+
+    p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+    p2 = fast_create(Person, :environment_id => e.id)
+    p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+    e.settings[:person_template_id]= p3.id
+    assert_equal p3, e.person_default_template
+  end
+
+  should 'person_default_template not return a person if its not a template' do
+    e = fast_create(Environment)
+
+    p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+    p2 = fast_create(Person, :environment_id => e.id)
+    p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+    e.settings[:person_template_id]= p2.id
+    assert_nil e.person_default_template
+  end
+
+  should 'person_default_template= define a person model passed as paremeter as default template' do
+    e = fast_create(Environment)
+
+    p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+    p2 = fast_create(Person, :environment_id => e.id)
+    p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+    e.person_default_template= p3
+    assert_equal p3, e.person_default_template
+  end
+
+  should 'person_default_template= define an id passed as paremeter as the default template' do
+    e = fast_create(Environment)
+
+    p1= fast_create(Person, :is_template => true, :environment_id => e.id)
+    p2 = fast_create(Person, :environment_id => e.id)
+    p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
+
+    e.person_default_template= p3.id
+    assert_equal p3, e.person_default_template
+  end
+
+  should 'community_templates return all templates of community' do
+    e = fast_create(Environment)
+
+    c1= fast_create(Community, :is_template => true, :environment_id => e.id)
+    c2 = fast_create(Community, :environment_id => e.id)
+    c3 = fast_create(Community, :is_template => true, :environment_id => e.id)
+    assert_equivalent [c1,c3], e.community_templates    
+  end
+
+  should 'community_templates return an empty array if there is no templates of community' do
+    e = fast_create(Environment)
+
+    fast_create(Community, :environment_id => e.id)
+    fast_create(Community, :environment_id => e.id)
+    assert_equivalent [], e.community_templates
+  end
+
+  should 'community_default_template return the template defined as default' do
+    e = fast_create(Environment)
+
+    c1= fast_create(Community, :is_template => true, :environment_id => e.id)
+    c2 = fast_create(Community, :environment_id => e.id)
+    c3 = fast_create(Community, :is_template => true, :environment_id => e.id)
+
+    e.settings[:community_template_id]= c3.id
+    assert_equal c3, e.community_default_template
+  end
+
+  should 'community_default_template not return a community if its not a template' do
+    e = fast_create(Environment)
+
+    c1= fast_create(Community, :is_template => true, :environment_id => e.id)
+    c2 = fast_create(Community, :environment_id => e.id)
+    c3 = fast_create(Community, :is_template => true, :environment_id => e.id)
+
+    e.settings[:community_template_id]= c2.id
+    assert_nil e.community_default_template
+  end
+
+  should 'community_default_template= define a community model passed as paremeter as default template' do
+    e = fast_create(Environment)
+
+    c1= fast_create(Community, :is_template => true, :environment_id => e.id)
+    c2 = fast_create(Community, :environment_id => e.id)
+    c3 = fast_create(Community, :is_template => true, :environment_id => e.id)
+
+    e.community_default_template= c3
+    assert_equal c3, e.community_default_template
+  end
+
+  should 'community_default_template= define an id passed as paremeter as the default template' do
+    e = fast_create(Environment)
+
+    c1= fast_create(Community, :is_template => true, :environment_id => e.id)
+    c2 = fast_create(Community, :environment_id => e.id)
+    c3 = fast_create(Community, :is_template => true, :environment_id => e.id)
+
+    e.community_default_template= c3.id
+    assert_equal c3, e.community_default_template
+  end
+
+  should 'enterprise_templates return all templates of enterprise' do
+    env = fast_create(Environment)
+
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    e2 = fast_create(Enterprise, :environment_id => env.id)
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    assert_equivalent [e1,e3], env.enterprise_templates    
+  end
+
+  should 'enterprise_templates return an empty array if there is no templates of enterprise' do
+    env = fast_create(Environment)
+
+    fast_create(Enterprise, :environment_id => env.id)
+    fast_create(Enterprise, :environment_id => env.id)
+    assert_equivalent [], env.enterprise_templates    
+  end
+
+  should 'enterprise_default_template return the template defined as default' do
+    env = fast_create(Environment)
+
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    e2 = fast_create(Enterprise, :environment_id => env.id)
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+
+    env.settings[:enterprise_template_id]= e3.id
+    assert_equal e3, env.enterprise_default_template
+  end
+
+  should 'enterprise_default_template not return a enterprise if its not a template' do
+    env = fast_create(Environment)
+
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    e2 = fast_create(Enterprise, :environment_id => env.id)
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+
+    env.settings[:enterprise_template_id]= e2.id
+    assert_nil env.enterprise_default_template
+  end
+
+  should 'enterprise_default_template= define a enterprise model passed as paremeter as default template' do
+    env = fast_create(Environment)
+
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    e2 = fast_create(Enterprise, :environment_id => env.id)
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+
+    env.enterprise_default_template= e3
+    assert_equal e3, env.enterprise_default_template
+  end
+
+  should 'enterprise_default_template= define an id passed as paremeter as the default template' do
+    env = fast_create(Environment)
+
+    e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    e2 = fast_create(Enterprise, :environment_id => env.id)
+    e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+
+    env.enterprise_default_template= e3.id
+    assert_equal e3, env.enterprise_default_template
+  end
+
+  should 'is_default_template? method identify a person default template as default' do
+    env = fast_create(Environment)
+
+    p1 = fast_create(Person, :is_template => true, :environment_id => env.id)
+    env.person_default_template= p1.id
+    assert env.is_default_template?(p1)
+
+    p2 = fast_create(Person, :is_template => true, :environment_id => env.id)
+    env.person_default_template= p2.id
+    assert !env.is_default_template?(p1)
+  end
+
+  should 'is_default_template? method identify a community default template as default' do
+    env = fast_create(Environment)
+
+    c1 = fast_create(Community, :is_template => true, :environment_id => env.id)
+    env.community_default_template= c1.id
+    assert env.is_default_template?(c1)
+
+    c2 = fast_create(Community, :is_template => true, :environment_id => env.id)
+    env.community_default_template= c2.id
+    assert !env.is_default_template?(c1)
+  end
+
+  should 'is_default_template? method identify a enterprise default template as default' do
+    env = fast_create(Environment)
 
-    person = fast_create(Person, :is_template => true)
-    e.person_template = person
-    assert_equal person, e.person_template
+    e1 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    env.enterprise_default_template= e1.id
+    assert env.is_default_template?(e1)
 
-    enterprise = fast_create(Enterprise, :is_template => true)
-    e.enterprise_template = enterprise
-    assert_equal enterprise, e.enterprise_template
+    e2 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
+    env.enterprise_default_template= e2.id
+    assert !env.is_default_template?(e1)
   end
 
   should 'have a layout template' do

=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -883,7 +883,7 @@ class ProfileTest < ActiveSupport::TestCase
 
   should 'copy communities from person template' do
     template = create_user('test_template').person
-    Environment.any_instance.stubs(:person_template).returns(template)
+    Environment.any_instance.stubs(:person_default_template).returns(template)
 
     c1 = fast_create(Community)
     c2 = fast_create(Community)
@@ -1336,7 +1336,7 @@ class ProfileTest < ActiveSupport::TestCase
     template = create_user('test_template').person
     template.custom_footer = "footer customized"
     template.custom_header = "header customized"
-    Environment.any_instance.stubs(:person_template).returns(template)
+    Environment.any_instance.stubs(:person_default_template).returns(template)
 
     person = create_user_full('mytestuser').person
     assert_equal "footer customized", person.custom_footer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150126/604388c2/attachment-0001.html>


More information about the Noosfero-dev mailing list