diff --git a/app/models/environment.rb b/app/models/environment.rb
index 61a623f..3587499 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -673,13 +673,14 @@ class Environment < ActiveRecord::Base
def create_templates
pre = self.name.to_slug + '_'
ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false).id
+ inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false)
com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false).id
pass = Digest::MD5.hexdigest rand.to_s
user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person
- user.visible = false
- user.save!
+ user.update_attributes(:visible => false, :name => "Person template")
usr_id = user.id
self.settings[:enterprise_template_id] = ent_id
+ self.inactive_enterprise_template = inactive_enterprise_tmpl
self.settings[:community_template_id] = com_id
self.settings[:person_template_id] = usr_id
self.save!
@@ -687,7 +688,7 @@ class Environment < ActiveRecord::Base
after_destroy :destroy_templates
def destroy_templates
- [enterprise_template, community_template, person_template].compact.each do |template|
+ [enterprise_template, inactive_enterprise_template, community_template, person_template].compact.each do |template|
template.destroy
end
end
diff --git a/app/views/admin_panel/edit_templates.rhtml b/app/views/admin_panel/edit_templates.rhtml
index e17f259..7e91399 100644
--- a/app/views/admin_panel/edit_templates.rhtml
+++ b/app/views/admin_panel/edit_templates.rhtml
@@ -1,7 +1,10 @@
<%= _('Edit Templates') %>
-- <%= link_to _('Edit Person Template'), :controller => 'profile_editor', :profile => environment.person_template.identifier %>
-- <%= link_to _('Edit Community Template'), :controller => 'profile_editor', :profile => environment.community_template.identifier %>
-- <%= link_to __('Edit Enterprise Template'), :controller => 'profile_editor', :profile => environment.enterprise_template.identifier %>
+<% [[_('Edit Person Template'), environment.person_template],
+ [_('Edit Community Template'), environment.community_template],
+ [__('Edit Enterprise Template'), environment.enterprise_template],
+ [__('Edit Inactive Enterprise Template'), environment.inactive_enterprise_template]].select{|i| i[1]}.each do |row| %>
+- <%= link_to row[0], :controller => 'profile_editor', :profile => row[1].identifier %>
+<% end %>
diff --git a/features/edit_environment_templates.feature b/features/edit_environment_templates.feature
new file mode 100644
index 0000000..8ccde4b
--- /dev/null
+++ b/features/edit_environment_templates.feature
@@ -0,0 +1,53 @@
+Feature: edit environment templates
+ As an administrator
+ I want edit templates
+
+ Background:
+ Given that the default environment have all profile templates
+
+ Scenario: See links to edit all templates
+ Given I am logged in as admin
+ When I follow "Administration"
+ And I follow "Edit Templates"
+ Then I should see "Edit Person Template" link
+ And I should see "Edit Community Template" link
+ And I should see "Edit Enterprise Template" link
+ And I should see "Edit Inactive Enterprise Template" link
+
+ Scenario: Go to control panel of person template
+ Given I am logged in as admin
+ When I follow "Administration"
+ And I follow "Edit Templates"
+ And I follow "Edit Person Template"
+ Then I should be on Person template's control panel
+
+ Scenario: Go to control panel of enterprise template
+ Given I am logged in as admin
+ When I follow "Administration"
+ And I follow "Edit Templates"
+ And I follow "Edit Enterprise Template"
+ Then I should be on Enterprise template's control panel
+
+ Scenario: Go to control panel of inactive enterprise template
+ Given I am logged in as admin
+ When I follow "Administration"
+ And I follow "Edit Templates"
+ And I follow "Edit Inactive Enterprise Template"
+ Then I should be on Inactive Enterprise template's control panel
+
+ Scenario: Go to control panel of community template
+ Given I am logged in as admin
+ When I follow "Administration"
+ And I follow "Edit Templates"
+ And I follow "Edit Community Template"
+ Then I should be on Community template's control panel
+
+ Scenario: Not see link to edit an unexistent template
+ Given that the default environment have no Inactive Enterprise template
+ And I am logged in as admin
+ When I follow "Administration"
+ And I follow "Edit Templates"
+ Then I should see "Edit Person Template" link
+ And I should see "Edit Community Template" link
+ And I should see "Edit Enterprise Template" link
+ And I should not see "Edit Inactive Enterprise Template" link
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index 282baf4..ae9f5ec 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -411,3 +411,13 @@ end
And /^I want to add "([^\"]*)" as cost$/ do |string|
selenium.answer_on_next_prompt(string)
end
+
+Given /^that the default environment have (.+) templates?$/ do |option|
+ env = Environment.default
+ case option
+ when 'all profile'
+ env.create_templates
+ when 'no Inactive Enterprise'
+ env.inactive_enterprise_template && env.inactive_enterprise_template.destroy
+ end
+end
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 6545df3..c472ff6 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -303,7 +303,7 @@ class EnvironmentTest < Test::Unit::TestCase
should 'destroy templates' do
env = fast_create(Environment)
- templates = [mock, mock, mock]
+ templates = [mock, mock, mock, mock]
templates.each do |item|
item.expects(:destroy)
end
@@ -311,6 +311,7 @@ class EnvironmentTest < Test::Unit::TestCase
env.stubs(:person_template).returns(templates[0])
env.stubs(:community_template).returns(templates[1])
env.stubs(:enterprise_template).returns(templates[2])
+ env.stubs(:inactive_enterprise_template).returns(templates[3])
env.destroy
end
@@ -507,11 +508,13 @@ class EnvironmentTest < Test::Unit::TestCase
# the templates must be created
assert_kind_of Enterprise, e.enterprise_template
+ assert_kind_of Enterprise, e.inactive_enterprise_template
assert_kind_of Community, e.community_template
assert_kind_of Person, e.person_template
# the templates must be private
assert !e.enterprise_template.visible?
+ assert !e.inactive_enterprise_template.visible?
assert !e.community_template.visible?
assert !e.person_template.visible?
end
--
libgit2 0.21.2