Project

General

Profile

Actions

Defect #4200

closed

enabled_module_names= does not test to see if a module is already enabled

Added by Robert Chady over 14 years ago. Updated over 14 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Projects
Target version:
-
Start date:
2009-11-12
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

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.

Actions #1

Updated by Eric Davis over 14 years ago

  • 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

Actions #2

Updated by Jean-Philippe Lang over 14 years ago

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.

Actions #3

Updated by Jean-Philippe Lang over 14 years ago

  • Status changed from 7 to Closed
  • Resolution set to Fixed

Fixed in r3036.

Actions

Also available in: Atom PDF