diff --git a/app/models/environment.rb b/app/models/environment.rb index cdbc132..154fb68 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -258,7 +258,7 @@ class Environment < ActiveRecord::Base end def enable_plugin(plugin) - self.enabled_plugins += [plugin] + self.enabled_plugins += [plugin.to_s] self.enabled_plugins.uniq! self.save! end @@ -269,7 +269,7 @@ class Environment < ActiveRecord::Base end def disable_plugin(plugin) - self.enabled_plugins.delete(plugin) + self.enabled_plugins.delete(plugin.to_s) self.save! end @@ -278,6 +278,10 @@ class Environment < ActiveRecord::Base self.settings["#{feature}_enabled".to_sym] == true end + def plugin_enabled?(plugin) + enabled_plugins.include?(plugin.to_s) + end + # enables the features identified by features, which is expected to # be an Enumarable object containing the identifiers of the desired features. # Passing nil is the same as passing an empty Array. diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 49fd607..ac84154 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -1187,17 +1187,18 @@ class EnvironmentTest < ActiveSupport::TestCase assert !environment.errors.invalid?(:reports_lower_bound) end - should 'be able to enable or disable a plugin' do + should 'be able to enable or disable a plugin with the class or class name' do + class Plugin + end environment = Environment.default - plugin = 'Plugin' - environment.enable_plugin(plugin) + environment.enable_plugin(Plugin) environment.reload - assert_includes environment.enabled_plugins, plugin + assert environment.plugin_enabled?(Plugin.to_s) - environment.disable_plugin(plugin) + environment.disable_plugin(Plugin.to_s) environment.reload - assert_not_includes environment.enabled_plugins, plugin + assert !environment.plugin_enabled?(Plugin) end should 'have production costs' do -- libgit2 0.21.2