Commit b464989afb12e24c1a22d30c5d097e9555ed5494

Authored by Gabriela Navarro
Committed by Rodrigo Souto
1 parent 8578b1c9

Add rake task to activate all available plugins

app/models/environment.rb
@@ -339,6 +339,16 @@ class Environment < ActiveRecord::Base @@ -339,6 +339,16 @@ class Environment < ActiveRecord::Base
339 self.save! 339 self.save!
340 end 340 end
341 341
  342 + def enable_all_plugins
  343 + Noosfero::Plugin.available_plugin_names.each do |plugin|
  344 + plugin_name = plugin.to_s + "Plugin"
  345 + unless self.enabled_plugins.include?(plugin_name)
  346 + self.enabled_plugins += [plugin_name]
  347 + end
  348 + end
  349 + self.save!
  350 + end
  351 +
342 # Disables a feature identified by its name 352 # Disables a feature identified by its name
343 def disable(feature, must_save=true) 353 def disable(feature, must_save=true)
344 self.settings["#{feature}_enabled".to_sym] = false 354 self.settings["#{feature}_enabled".to_sym] = false
lib/tasks/enable_plugins.rake 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +namespace :noosfero do
  2 + namespace :plugins do
  3 + task :enable_all => :environment do
  4 + Environment.all.each do |env|
  5 + puts "Plugins Activated on #{env.name}" if env.enable_all_plugins
  6 + end
  7 + end
  8 + end
  9 +end
test/unit/environment_test.rb
@@ -524,7 +524,7 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -524,7 +524,7 @@ class EnvironmentTest < ActiveSupport::TestCase
524 p1= fast_create(Person, :is_template => true, :environment_id => e.id) 524 p1= fast_create(Person, :is_template => true, :environment_id => e.id)
525 p2 = fast_create(Person, :environment_id => e.id) 525 p2 = fast_create(Person, :environment_id => e.id)
526 p3 = fast_create(Person, :is_template => true, :environment_id => e.id) 526 p3 = fast_create(Person, :is_template => true, :environment_id => e.id)
527 - assert_equivalent [p1,p3], e.person_templates 527 + assert_equivalent [p1,p3], e.person_templates
528 end 528 end
529 529
530 should 'person_templates return an empty array if there is no templates of person' do 530 should 'person_templates return an empty array if there is no templates of person' do
@@ -532,7 +532,7 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -532,7 +532,7 @@ class EnvironmentTest < ActiveSupport::TestCase
532 532
533 fast_create(Person, :environment_id => e.id) 533 fast_create(Person, :environment_id => e.id)
534 fast_create(Person, :environment_id => e.id) 534 fast_create(Person, :environment_id => e.id)
535 - assert_equivalent [], e.person_templates 535 + assert_equivalent [], e.person_templates
536 end 536 end
537 537
538 should 'person_default_template return the template defined as default' do 538 should 'person_default_template return the template defined as default' do
@@ -585,7 +585,7 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -585,7 +585,7 @@ class EnvironmentTest < ActiveSupport::TestCase
585 c1= fast_create(Community, :is_template => true, :environment_id => e.id) 585 c1= fast_create(Community, :is_template => true, :environment_id => e.id)
586 c2 = fast_create(Community, :environment_id => e.id) 586 c2 = fast_create(Community, :environment_id => e.id)
587 c3 = fast_create(Community, :is_template => true, :environment_id => e.id) 587 c3 = fast_create(Community, :is_template => true, :environment_id => e.id)
588 - assert_equivalent [c1,c3], e.community_templates 588 + assert_equivalent [c1,c3], e.community_templates
589 end 589 end
590 590
591 should 'community_templates return an empty array if there is no templates of community' do 591 should 'community_templates return an empty array if there is no templates of community' do
@@ -646,7 +646,7 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -646,7 +646,7 @@ class EnvironmentTest < ActiveSupport::TestCase
646 e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) 646 e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id)
647 e2 = fast_create(Enterprise, :environment_id => env.id) 647 e2 = fast_create(Enterprise, :environment_id => env.id)
648 e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) 648 e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id)
649 - assert_equivalent [e1,e3], env.enterprise_templates 649 + assert_equivalent [e1,e3], env.enterprise_templates
650 end 650 end
651 651
652 should 'enterprise_templates return an empty array if there is no templates of enterprise' do 652 should 'enterprise_templates return an empty array if there is no templates of enterprise' do
@@ -654,7 +654,7 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -654,7 +654,7 @@ class EnvironmentTest < ActiveSupport::TestCase
654 654
655 fast_create(Enterprise, :environment_id => env.id) 655 fast_create(Enterprise, :environment_id => env.id)
656 fast_create(Enterprise, :environment_id => env.id) 656 fast_create(Enterprise, :environment_id => env.id)
657 - assert_equivalent [], env.enterprise_templates 657 + assert_equivalent [], env.enterprise_templates
658 end 658 end
659 659
660 should 'enterprise_default_template return the template defined as default' do 660 should 'enterprise_default_template return the template defined as default' do
@@ -1428,6 +1428,36 @@ class EnvironmentTest < ActiveSupport::TestCase @@ -1428,6 +1428,36 @@ class EnvironmentTest < ActiveSupport::TestCase
1428 assert !environment.plugin_enabled?(Plugin) 1428 assert !environment.plugin_enabled?(Plugin)
1429 end 1429 end
1430 1430
  1431 + should 'activate on database all available plugins' do
  1432 + plugins_enable = ["Statistics", "Foo", "PeopleBlock"]
  1433 + Noosfero::Plugins.stubs(:available_plugin_names).returns(plugins_enable)
  1434 + env1 = Environment.create(:name => "Test")
  1435 + env2 = Environment.create(:name => "Test 2")
  1436 +
  1437 + env1.enable_all_plugins
  1438 + env2.enable_all_plugins
  1439 +
  1440 + plugins = ["PeopleBlockPlugin", "StatisticsPlugin", "FooPlugin"]
  1441 + plugins.each do |plugin|
  1442 + assert env1.enabled_plugins.include?(plugin)
  1443 + assert env2.enabled_plugins.include?(plugin)
  1444 + end
  1445 + end
  1446 +
  1447 + should 'dont activate plugins that are not available' do
  1448 + env1 = Environment.create(:name => "Test")
  1449 + env2 = Environment.create(:name => "Test 2")
  1450 +
  1451 + env1.enable_all_plugins
  1452 + env2.enable_all_plugins
  1453 +
  1454 + plugins = ["SomePlugin", "OtherPlugin", "ThirdPlugin"]
  1455 + plugins.each do |plugin|
  1456 + assert_equal false, env1.enabled_plugins.include?(plugin)
  1457 + assert_equal false, env2.enabled_plugins.include?(plugin)
  1458 + end
  1459 + end
  1460 +
1431 should 'have production costs' do 1461 should 'have production costs' do
1432 assert_respond_to Environment.default, :production_costs 1462 assert_respond_to Environment.default, :production_costs
1433 end 1463 end