diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-29 07:29:23 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-29 07:29:23 +0000 |
commit | 6153d5ab833cae3f0db4a6495d8916384ab2e31c (patch) | |
tree | bb8b0f7cf88cb4218770ae33d5385d6b1b2ed449 | |
parent | f49904569d917e4e2a8304fca98906bcecf31d2d (diff) | |
download | redmine-6153d5ab833cae3f0db4a6495d8916384ab2e31c.tar.gz redmine-6153d5ab833cae3f0db4a6495d8916384ab2e31c.zip |
Merged r5265 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.1-stable@5582 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | test/functional/projects_controller_test.rb | 16 | ||||
-rw-r--r-- | test/unit/project_test.rb | 8 |
3 files changed, 25 insertions, 4 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 8315a48a5..3dc700424 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -509,10 +509,7 @@ class Project < ActiveRecord::Base def enabled_module_names=(module_names) if module_names && module_names.is_a?(Array) module_names = module_names.collect(&:to_s).reject(&:blank?) - # remove disabled modules - enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)} - # add new modules - module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)} + self.enabled_modules = module_names.collect {|name| enabled_modules.detect {|mod| mod.name == name} || EnabledModule.new(:name => name)} else enabled_modules.clear end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index fefb8d53b..74912a764 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -288,6 +288,22 @@ class ProjectsControllerTest < ActionController::TestCase end end + def test_create_should_preserve_modules_on_validation_failure + with_settings :default_projects_modules => ['issue_tracking', 'repository'] do + @request.session[:user_id] = 1 + assert_no_difference 'Project.count' do + post :create, :project => { + :name => "blog", + :identifier => "", + :enabled_module_names => %w(issue_tracking news) + } + end + assert_response :success + project = assigns(:project) + assert_equal %w(issue_tracking news), project.enabled_module_names.sort + end + end + def test_create_should_not_accept_get @request.session[:user_id] = 1 get :create diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 8eb79fdaa..868641775 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -553,6 +553,14 @@ class ProjectTest < ActiveSupport::TestCase assert_nil Project.next_identifier end + def test_enabled_module_names + with_settings :default_projects_modules => ['issue_tracking', 'repository'] do + project = Project.new + + project.enabled_module_names = %w(issue_tracking news) + assert_equal %w(issue_tracking news), project.enabled_module_names.sort + end + end def test_enabled_module_names_should_not_recreate_enabled_modules project = Project.find(1) |