Commit 8b4f728977e5b09352dea722d70a8a7306948010
1 parent
24b37d9a
Exists in
staging
and in
42 other branches
Improving environment enable/disable plugins methods
* Allowing enable/disable to receive the class
Showing
2 changed files
with
13 additions
and
8 deletions
Show diff stats
app/models/environment.rb
@@ -258,7 +258,7 @@ class Environment < ActiveRecord::Base | @@ -258,7 +258,7 @@ class Environment < ActiveRecord::Base | ||
258 | end | 258 | end |
259 | 259 | ||
260 | def enable_plugin(plugin) | 260 | def enable_plugin(plugin) |
261 | - self.enabled_plugins += [plugin] | 261 | + self.enabled_plugins += [plugin.to_s] |
262 | self.enabled_plugins.uniq! | 262 | self.enabled_plugins.uniq! |
263 | self.save! | 263 | self.save! |
264 | end | 264 | end |
@@ -269,7 +269,7 @@ class Environment < ActiveRecord::Base | @@ -269,7 +269,7 @@ class Environment < ActiveRecord::Base | ||
269 | end | 269 | end |
270 | 270 | ||
271 | def disable_plugin(plugin) | 271 | def disable_plugin(plugin) |
272 | - self.enabled_plugins.delete(plugin) | 272 | + self.enabled_plugins.delete(plugin.to_s) |
273 | self.save! | 273 | self.save! |
274 | end | 274 | end |
275 | 275 | ||
@@ -278,6 +278,10 @@ class Environment < ActiveRecord::Base | @@ -278,6 +278,10 @@ class Environment < ActiveRecord::Base | ||
278 | self.settings["#{feature}_enabled".to_sym] == true | 278 | self.settings["#{feature}_enabled".to_sym] == true |
279 | end | 279 | end |
280 | 280 | ||
281 | + def plugin_enabled?(plugin) | ||
282 | + enabled_plugins.include?(plugin.to_s) | ||
283 | + end | ||
284 | + | ||
281 | # enables the features identified by <tt>features</tt>, which is expected to | 285 | # enables the features identified by <tt>features</tt>, which is expected to |
282 | # be an Enumarable object containing the identifiers of the desired features. | 286 | # be an Enumarable object containing the identifiers of the desired features. |
283 | # Passing <tt>nil</tt> is the same as passing an empty Array. | 287 | # Passing <tt>nil</tt> is the same as passing an empty Array. |
test/unit/environment_test.rb
@@ -1187,17 +1187,18 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1187,17 +1187,18 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
1187 | assert !environment.errors.invalid?(:reports_lower_bound) | 1187 | assert !environment.errors.invalid?(:reports_lower_bound) |
1188 | end | 1188 | end |
1189 | 1189 | ||
1190 | - should 'be able to enable or disable a plugin' do | 1190 | + should 'be able to enable or disable a plugin with the class or class name' do |
1191 | + class Plugin | ||
1192 | + end | ||
1191 | environment = Environment.default | 1193 | environment = Environment.default |
1192 | - plugin = 'Plugin' | ||
1193 | 1194 | ||
1194 | - environment.enable_plugin(plugin) | 1195 | + environment.enable_plugin(Plugin) |
1195 | environment.reload | 1196 | environment.reload |
1196 | - assert_includes environment.enabled_plugins, plugin | 1197 | + assert environment.plugin_enabled?(Plugin.to_s) |
1197 | 1198 | ||
1198 | - environment.disable_plugin(plugin) | 1199 | + environment.disable_plugin(Plugin.to_s) |
1199 | environment.reload | 1200 | environment.reload |
1200 | - assert_not_includes environment.enabled_plugins, plugin | 1201 | + assert !environment.plugin_enabled?(Plugin) |
1201 | end | 1202 | end |
1202 | 1203 | ||
1203 | should 'have production costs' do | 1204 | should 'have production costs' do |