Defect #4200
closed
enabled_module_names= does not test to see if a module is already enabled
Added by Robert Chady about 15 years ago.
Updated about 15 years ago.
Description
If you call enabled_module_names= with an array that contains an array of modules, enabled_module_names= does not test before trying to add them again -- yet it will delete them if you don't provide them.
The issue is from project.rb:330 where it does not test to see if the module is already enabled before it tries to re-enable it.
- Status changed from New to 7
Simple patch which should work:
# From: http://gist.github.com/232458
# remove disabled modules
enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)}
# add new modules
- module_names.each {|name| enabled_modules << EnabledModule.new(:name => name)}
+ module_names.each do |name|
+ enabled_modules << EnabledModule.new(:name => name) unless module_enabled? name
+ end
else
enabled_modules.clear
end
There is a test for it but I'm not sure if it's testing the right behavior. test_enabled_module_names_should_not_recreate_enabled_modules
The test do test the right bahaviour but it passes because of validates_uniqueness_of :name, :scope => :project_id
on EnabledModule model.
enabled_module_names= does not test before trying to add them again
Indeed, it should not try to add them again (even if they are not created).
yet it will delete them if you don't provide them
That's the expected behaviour. Otherwise this method would be named add_module_names
or something.
- Status changed from 7 to Closed
- Resolution set to Fixed
Also available in: Atom
PDF