Do not DELETE/INSERT enabled_modules when updating project modules.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2473 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-02-15 16:26:48 +00:00
parent 4601ed2f3a
commit b05ed594a0
2 changed files with 24 additions and 5 deletions

View File

@ -287,10 +287,14 @@ class Project < ActiveRecord::Base
end
def enabled_module_names=(module_names)
enabled_modules.clear
module_names = [] unless module_names && module_names.is_a?(Array)
module_names.each do |name|
enabled_modules << EnabledModule.new(:name => name.to_s)
if module_names && module_names.is_a?(Array)
module_names = module_names.collect(&:to_s)
# 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)}
else
enabled_modules.clear
end
end

View File

@ -18,7 +18,9 @@
require File.dirname(__FILE__) + '/../test_helper'
class ProjectTest < Test::Unit::TestCase
fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
fixtures :projects, :enabled_modules,
:issues, :issue_statuses, :journals, :journal_details,
:users, :members, :roles, :projects_trackers, :trackers, :boards
def setup
@ecookbook = Project.find(1)
@ -218,4 +220,17 @@ class ProjectTest < Test::Unit::TestCase
Project.delete_all
assert_nil Project.next_identifier
end
def test_enabled_module_names_should_not_recreate_enabled_modules
project = Project.find(1)
# Remove one module
modules = project.enabled_modules.slice(0..-2)
assert modules.any?
assert_difference 'EnabledModule.count', -1 do
project.enabled_module_names = modules.collect(&:name)
end
project.reload
# Ids should be preserved
assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
end
end