summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-05-03 11:48:33 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-05-03 11:48:33 +0000
commit2c28d6b5d11d69b6e83517113aaa71c246391c16 (patch)
tree5458b66112a302b4ddfa58b88e721a491208f4f4
parent36ee2b24bdde652e5d6ae18a4f2ecbe997a939a6 (diff)
downloadredmine-2c28d6b5d11d69b6e83517113aaa71c246391c16.tar.gz
redmine-2c28d6b5d11d69b6e83517113aaa71c246391c16.zip
scm: git: fix creating and updating repository
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9616 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/repositories_controller.rb26
-rw-r--r--app/models/repository.rb22
-rw-r--r--test/functional/repositories_git_controller_test.rb29
3 files changed, 53 insertions, 24 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index f02bd8b70..1fb708355 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -46,7 +46,11 @@ class RepositoriesController < ApplicationController
end
def create
- @repository = Repository.factory(params[:repository_scm], params[:repository])
+ attrs = pickup_extra_info
+ @repository = Repository.factory(params[:repository_scm], attrs[:attrs])
+ if attrs[:attrs_extra].keys.any?
+ @repository.merge_extra_info(attrs[:attrs_extra])
+ end
@repository.project = @project
if request.post? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
@@ -59,7 +63,11 @@ class RepositoriesController < ApplicationController
end
def update
- @repository.attributes = params[:repository]
+ attrs = pickup_extra_info
+ @repository.attributes = attrs[:attrs]
+ if attrs[:attrs_extra].keys.any?
+ @repository.merge_extra_info(attrs[:attrs_extra])
+ end
@repository.project = @project
if request.put? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
@@ -68,6 +76,20 @@ class RepositoriesController < ApplicationController
end
end
+ def pickup_extra_info
+ p = {}
+ p_extra = {}
+ params[:repository].each do |k, v|
+ if k =~ /^extra_/
+ p_extra[k] = v
+ else
+ p[k] = v
+ end
+ end
+ {:attrs => p, :attrs_extra => p_extra}
+ end
+ private :pickup_extra_info
+
def committers
@committers = @repository.committers
@users = @project.users
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 7efbc0c26..b0bf0d2a7 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -56,28 +56,6 @@ class Repository < ActiveRecord::Base
super(attr_name, *args)
end
- alias :attributes_without_extra_info= :attributes=
- def attributes=(new_attributes)
- return if new_attributes.nil?
- attributes = new_attributes.dup
- attributes.stringify_keys!
-
- p = {}
- p_extra = {}
- attributes.each do |k, v|
- if k =~ /^extra_/
- p_extra[k] = v
- else
- p[k] = v
- end
- end
-
- send :attributes_without_extra_info=, p
- if p_extra.keys.any?
- merge_extra_info(p_extra)
- end
- end
-
# Removes leading and trailing whitespace
def url=(arg)
write_attribute(:url, arg ? arg.to_s.strip : nil)
diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb
index da82f9026..860d436fe 100644
--- a/test/functional/repositories_git_controller_test.rb
+++ b/test/functional/repositories_git_controller_test.rb
@@ -57,6 +57,35 @@ class RepositoriesGitControllerTest < ActionController::TestCase
Setting.default_language = 'en'
end
+ def test_create_and_update
+ @request.session[:user_id] = 1
+ assert_difference 'Repository.count' do
+ post :create, :project_id => 'subproject1',
+ :repository_scm => 'Git',
+ :repository => {
+ :url => '/test',
+ :is_default => '0',
+ :identifier => 'test-create',
+ :extra_report_last_commit => '1',
+ }
+ end
+ assert_response 302
+ repository = Repository.first(:order => 'id DESC')
+ assert_kind_of Repository::Git, repository
+ assert_equal '/test', repository.url
+ assert_equal true, repository.extra_report_last_commit
+
+ put :update, :id => repository.id,
+ :repository => {
+ :extra_report_last_commit => '0',
+ :identifier => 'test-update',
+ }
+ assert_response 302
+ repo2 = Repository.find(repository.id)
+ assert_equal 'test-update', repo2.identifier
+ assert_equal false, repo2.extra_report_last_commit
+ end
+
if File.directory?(REPOSITORY_PATH)
def test_get_new
@request.session[:user_id] = 1