Commit 5ea7ef38 authored by jplang's avatar jplang

Adds accessors for report_last_commit.

git-svn-id: https://svn.redmine.org/redmine/trunk@15885 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent f239033c
......@@ -45,12 +45,8 @@ class RepositoriesController < ApplicationController
end
def create
attrs = pickup_extra_info
@repository = Repository.factory(params[:repository_scm])
@repository.safe_attributes = params[:repository]
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')
......@@ -63,11 +59,7 @@ class RepositoriesController < ApplicationController
end
def update
attrs = pickup_extra_info
@repository.safe_attributes = attrs[:attrs]
if attrs[:attrs_extra].keys.any?
@repository.merge_extra_info(attrs[:attrs_extra])
end
@repository.safe_attributes = params[:repository]
@repository.project = @project
if @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
......@@ -76,20 +68,6 @@ 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.to_a
......
......@@ -185,7 +185,7 @@ module RepositoriesHelper
scm_path_info_tag(repository)) +
scm_path_encoding_tag(form, repository) +
content_tag('p', form.check_box(
:extra_report_last_commit,
:report_last_commit,
:label => l(:label_git_report_last_commit)
))
end
......
......@@ -22,6 +22,8 @@ class Repository::Git < Repository
attr_protected :root_url
validates_presence_of :url
safe_attributes 'report_last_commit'
def self.human_attribute_name(attribute_key_name, *args)
attr_name = attribute_key_name.to_s
if attr_name == "url"
......@@ -39,15 +41,15 @@ class Repository::Git < Repository
end
def report_last_commit
extra_report_last_commit
end
def extra_report_last_commit
return false if extra_info.nil?
v = extra_info["extra_report_last_commit"]
return false if v.nil?
v.to_s != '0'
end
def report_last_commit=(arg)
merge_extra_info "extra_report_last_commit" => arg
end
def supports_directory_revisions?
true
......@@ -94,7 +96,7 @@ class Repository::Git < Repository
end
def scm_entries(path=nil, identifier=nil)
scm.entries(path, identifier, :report_last_commit => extra_report_last_commit)
scm.entries(path, identifier, :report_last_commit => report_last_commit)
end
protected :scm_entries
......
......@@ -49,6 +49,16 @@ class RepositoriesControllerTest < Redmine::ControllerTest
assert_select 'option[value=Git]:not([selected])'
end
end
def test_get_new_with_type
@request.session[:user_id] = 1
get :new, :project_id => 'subproject1', :repository_scm => 'Git'
assert_response :success
assert_select 'select[name=?]', 'repository_scm' do
assert_select 'option[value=?][selected=selected]', 'Git'
end
end
def test_create
@request.session[:user_id] = 1
......
......@@ -60,22 +60,22 @@ class RepositoriesGitControllerTest < Redmine::ControllerTest
:url => '/test',
:is_default => '0',
:identifier => 'test-create',
:extra_report_last_commit => '1',
:report_last_commit => '1',
}
end
assert_response 302
repository = Repository.order('id DESC').first
assert_kind_of Repository::Git, repository
assert_equal '/test', repository.url
assert_equal true, repository.extra_report_last_commit
assert_equal true, repository.report_last_commit
put :update, :id => repository.id,
:repository => {
:extra_report_last_commit => '0'
:report_last_commit => '0'
}
assert_response 302
repo2 = Repository.find(repository.id)
assert_equal false, repo2.extra_report_last_commit
assert_equal false, repo2.report_last_commit
end
if File.directory?(REPOSITORY_PATH)
......
......@@ -243,22 +243,13 @@ class RepositoryGitTest < ActiveSupport::TestCase
assert_equal h1, h2
end
def test_keep_extra_report_last_commit_in_clear_changesets
def test_clear_changesets_should_keep_report_last_commit
assert_nil @repository.extra_info
h = {}
h["extra_report_last_commit"] = "1"
@repository.merge_extra_info(h)
@repository.report_last_commit = "1"
@repository.save
@project.reload
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
@repository.send(:clear_changesets)
assert_equal 1, @repository.extra_info.size
assert_equal "1", @repository.extra_info["extra_report_last_commit"]
assert_equal true, @repository.report_last_commit
end
def test_refetch_after_clear_changesets
......
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