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 | 258 | end |
259 | 259 | |
260 | 260 | def enable_plugin(plugin) |
261 | - self.enabled_plugins += [plugin] | |
261 | + self.enabled_plugins += [plugin.to_s] | |
262 | 262 | self.enabled_plugins.uniq! |
263 | 263 | self.save! |
264 | 264 | end |
... | ... | @@ -269,7 +269,7 @@ class Environment < ActiveRecord::Base |
269 | 269 | end |
270 | 270 | |
271 | 271 | def disable_plugin(plugin) |
272 | - self.enabled_plugins.delete(plugin) | |
272 | + self.enabled_plugins.delete(plugin.to_s) | |
273 | 273 | self.save! |
274 | 274 | end |
275 | 275 | |
... | ... | @@ -278,6 +278,10 @@ class Environment < ActiveRecord::Base |
278 | 278 | self.settings["#{feature}_enabled".to_sym] == true |
279 | 279 | end |
280 | 280 | |
281 | + def plugin_enabled?(plugin) | |
282 | + enabled_plugins.include?(plugin.to_s) | |
283 | + end | |
284 | + | |
281 | 285 | # enables the features identified by <tt>features</tt>, which is expected to |
282 | 286 | # be an Enumarable object containing the identifiers of the desired features. |
283 | 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 | 1187 | assert !environment.errors.invalid?(:reports_lower_bound) |
1188 | 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 | 1193 | environment = Environment.default |
1192 | - plugin = 'Plugin' | |
1193 | 1194 | |
1194 | - environment.enable_plugin(plugin) | |
1195 | + environment.enable_plugin(Plugin) | |
1195 | 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 | 1200 | environment.reload |
1200 | - assert_not_includes environment.enabled_plugins, plugin | |
1201 | + assert !environment.plugin_enabled?(Plugin) | |
1201 | 1202 | end |
1202 | 1203 | |
1203 | 1204 | should 'have production costs' do | ... | ... |