Commit edf755b5a64899c32dd3af2756ef9b3996fc14e2
1 parent
3917022f
Exists in
activate_plugin
Add tests for environment method and update rake task for enable_plugins
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
3 changed files
with
41 additions
and
10 deletions
Show diff stats
app/models/environment.rb
@@ -341,10 +341,9 @@ class Environment < ActiveRecord::Base | @@ -341,10 +341,9 @@ class Environment < ActiveRecord::Base | ||
341 | 341 | ||
342 | def enable_all_plugins | 342 | def enable_all_plugins |
343 | Noosfero::Plugin.available_plugin_names.each do |plugin| | 343 | Noosfero::Plugin.available_plugin_names.each do |plugin| |
344 | - plugin_name = plugin.to_s + 'Plugin' | 344 | + plugin_name = plugin.to_s + "Plugin" |
345 | unless self.enabled_plugins.include?(plugin_name) | 345 | unless self.enabled_plugins.include?(plugin_name) |
346 | - self.enabled_plugins << plugin_name | ||
347 | - puts plugin_name + " activated!" | 346 | + self.enabled_plugins += [plugin_name] |
348 | end | 347 | end |
349 | end | 348 | end |
350 | self.save! | 349 | self.save! |
lib/tasks/enable_plugins.rake
1 | namespace :noosfero do | 1 | namespace :noosfero do |
2 | namespace :plugins do | 2 | namespace :plugins do |
3 | - task :enable_all_plugins => :environment do | ||
4 | - Environment.all.each(&:enable_all_plugins) | 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 | ||
5 | end | 7 | end |
6 | end | 8 | end |
7 | 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 |