Strip repository urls (closes #852).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1248 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b8b991a7dc
commit
4957752d12
|
@ -20,6 +20,16 @@ class Repository < ActiveRecord::Base
|
||||||
has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
||||||
has_many :changes, :through => :changesets
|
has_many :changes, :through => :changesets
|
||||||
|
|
||||||
|
# Removes leading and trailing whitespace
|
||||||
|
def url=(arg)
|
||||||
|
write_attribute(:url, arg ? arg.to_s.strip : nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Removes leading and trailing whitespace
|
||||||
|
def root_url=(arg)
|
||||||
|
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
|
||||||
|
end
|
||||||
|
|
||||||
def scm
|
def scm
|
||||||
@scm ||= self.scm_adapter.new url, root_url, login, password
|
@scm ||= self.scm_adapter.new url, root_url, login, password
|
||||||
update_attribute(:root_url, @scm.root_url) if root_url.blank?
|
update_attribute(:root_url, @scm.root_url) if root_url.blank?
|
||||||
|
@ -88,4 +98,13 @@ class Repository < ActiveRecord::Base
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def before_save
|
||||||
|
# Strips url and root_url
|
||||||
|
url.strip!
|
||||||
|
root_url.strip!
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,4 +98,13 @@ class RepositoryTest < Test::Unit::TestCase
|
||||||
assert_not_equal( comment, changeset.comments )
|
assert_not_equal( comment, changeset.comments )
|
||||||
assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
|
assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_for_urls_strip
|
||||||
|
repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository',
|
||||||
|
:root_url => 'foo ')
|
||||||
|
assert repository.save
|
||||||
|
repository.reload
|
||||||
|
assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
|
||||||
|
assert_equal 'foo', repository.root_url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue