@@ -30,6 +30,7 class Repository < ActiveRecord::Base | |||||
30 |
|
30 | |||
31 | serialize :extra_info |
|
31 | serialize :extra_info | |
32 |
|
32 | |||
|
33 | before_validation :normalize_identifier | |||
33 | before_save :check_default |
|
34 | before_save :check_default | |
34 |
|
35 | |||
35 | # Raw SQL to delete changesets and changes in the database |
|
36 | # Raw SQL to delete changesets and changes in the database | |
@@ -469,6 +470,10 class Repository < ActiveRecord::Base | |||||
469 | end |
|
470 | end | |
470 | end |
|
471 | end | |
471 |
|
472 | |||
|
473 | def normalize_identifier | |||
|
474 | self.identifier = identifier.to_s.strip | |||
|
475 | end | |||
|
476 | ||||
472 | def check_default |
|
477 | def check_default | |
473 | if !is_default? && set_as_default? |
|
478 | if !is_default? && set_as_default? | |
474 | self.is_default = true |
|
479 | self.is_default = true |
@@ -251,7 +251,7 class RepositoriesGitControllerTest < ActionController::TestCase | |||||
251 |
|
251 | |||
252 | def test_diff |
|
252 | def test_diff | |
253 | assert_equal true, @repository.is_default |
|
253 | assert_equal true, @repository.is_default | |
254 |
assert |
|
254 | assert @repository.identifier.blank? | |
255 | assert_equal 0, @repository.changesets.count |
|
255 | assert_equal 0, @repository.changesets.count | |
256 | @repository.fetch_changesets |
|
256 | @repository.fetch_changesets | |
257 | @project.reload |
|
257 | @project.reload |
@@ -50,6 +50,8 class RepositoryGitTest < ActiveSupport::TestCase | |||||
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_nondefault_repo_with_blank_identifier_destruction |
|
52 | def test_nondefault_repo_with_blank_identifier_destruction | |
|
53 | Repository.delete_all | |||
|
54 | ||||
53 | repo1 = Repository::Git.new( |
|
55 | repo1 = Repository::Git.new( | |
54 | :project => @project, |
|
56 | :project => @project, | |
55 | :url => REPOSITORY_PATH, |
|
57 | :url => REPOSITORY_PATH, |
@@ -94,6 +94,18 class RepositoryTest < ActiveSupport::TestCase | |||||
94 | assert !r.save |
|
94 | assert !r.save | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
|
97 | def test_2_repositories_with_blank_identifier_and_one_as_default_should_not_be_valid | |||
|
98 | Repository::Subversion.create!(:project_id => 3, :identifier => '', :url => 'file:///foo', :is_default => true) | |||
|
99 | r = Repository::Subversion.new(:project_id => 3, :identifier => '', :url => 'file:///bar') | |||
|
100 | assert !r.save | |||
|
101 | end | |||
|
102 | ||||
|
103 | def test_2_repositories_with_blank_and_nil_identifier_should_not_be_valid | |||
|
104 | Repository::Subversion.create!(:project_id => 3, :identifier => nil, :url => 'file:///foo') | |||
|
105 | r = Repository::Subversion.new(:project_id => 3, :identifier => '', :url => 'file:///bar') | |||
|
106 | assert !r.save | |||
|
107 | end | |||
|
108 | ||||
97 | def test_first_repository_should_be_set_as_default |
|
109 | def test_first_repository_should_be_set_as_default | |
98 | repository1 = Repository::Subversion.new( |
|
110 | repository1 = Repository::Subversion.new( | |
99 | :project => Project.find(3), |
|
111 | :project => Project.find(3), |
General Comments 0
You need to be logged in to leave comments.
Login now