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:
parent
4601ed2f3a
commit
b05ed594a0
|
@ -287,10 +287,14 @@ class Project < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled_module_names=(module_names)
|
def enabled_module_names=(module_names)
|
||||||
|
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
|
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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@
|
||||||
require File.dirname(__FILE__) + '/../test_helper'
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
class ProjectTest < Test::Unit::TestCase
|
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
|
def setup
|
||||||
@ecookbook = Project.find(1)
|
@ecookbook = Project.find(1)
|
||||||
|
@ -218,4 +220,17 @@ class ProjectTest < Test::Unit::TestCase
|
||||||
Project.delete_all
|
Project.delete_all
|
||||||
assert_nil Project.next_identifier
|
assert_nil Project.next_identifier
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue