@@ -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 |
@@ -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