GitLab wird am Donnerstag, den 27. Januar, zwischen 08:00 und 12:00 Uhr wegen wichtigen Wartungsarbeiten nicht zur Verfügung stehen.

Commit a667607e authored by jplang's avatar jplang
Browse files

Do not DELETE/INSERT enabled_modules when updating project modules.

git-svn-id: https://svn.redmine.org/redmine/trunk@2473 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 299754ae
......@@ -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
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment