Skip to content

Commit 6f0434a

Browse files
author
root
committed
Add tests for Project, fix #230
1 parent 44d799f commit 6f0434a

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

Diff for: config/locales/active_record/en.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ en:
44

55
activerecord:
66
errors:
7+
8+
models:
9+
10+
repository:
11+
attributes:
12+
identifier:
13+
ident_cannot_equal_project: ": cannot match identifier of existing project"
14+
15+
project:
16+
attributes:
17+
identifier:
18+
ident_invalid: ": invalid identifier"
19+
ident_not_unique: ": matches existing repository identifier"
20+
721
messages:
8-
'may not be changed': 'may not be changed'
922
cannot_change: "cannot be changed"
10-
ident_not_unique: "matches existing repository identifier"
11-
ident_cannot_equal_project: "cannot match identifier of existing project"
1223
blank_default_exists: "Cannot make repository the default because current default has blank identifier."
13-
error_wrong_config_key_format: "Wrong key format (must contain at least one '.')."

Diff for: config/locales/active_record/fr.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ fr:
44

55
activerecord:
66
errors:
7+
8+
models:
9+
10+
repository:
11+
attributes:
12+
identifier:
13+
ident_cannot_equal_project: ": ne peut pas correspondre à l'identifiant d'un projet existant"
14+
15+
project:
16+
attributes:
17+
identifier:
18+
ident_invalid: ": identifiant invalide"
19+
ident_not_unique: ": correspond à un identifiant de dépôt existant"
20+
721
messages:
8-
'may not be changed': 'ne peut pas être changé'
922
cannot_change: "ne peut pas changer"
10-
ident_not_unique: "correspond à un identifiant de dépôt existant"
11-
ident_cannot_equal_project: "ne peut pas correspondre à l'identifiant d'un projet existant"
1223
blank_default_exists: "Ne peut pas mettre le dépôt par défaut, car le dépôt par défaut courant a un identifiant vide."
13-
error_wrong_config_key_format: "Mauvais format de clé (doit contenir au moin un '.')"

Diff for: lib/redmine_git_hosting/patches/project_patch.rb

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def additional_ident_constraints
3737
if new_record? && !identifier.blank? && Repository.find_by_identifier_and_type(identifier, "Repository::Git")
3838
errors.add(:identifier, :ident_not_unique)
3939
end
40+
41+
if new_record? && !identifier.blank? && identifier == 'gitolite-admin'
42+
errors.add(:identifier, :ident_invalid)
43+
end
4044
end
4145

4246
end

Diff for: spec/models/project_spec.rb

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2+
3+
describe Project do
4+
5+
before(:all) do
6+
@project = FactoryGirl.create(:project)
7+
8+
@git_repo_1 = FactoryGirl.create(:repository_git, :project_id => @project.id, :is_default => true)
9+
@git_repo_2 = FactoryGirl.create(:repository_git, :project_id => @project.id, :identifier => 'git-repo-test')
10+
11+
@svn_repo_1 = FactoryGirl.create(:repository_svn, :project_id => @project.id, :identifier => 'svn-repo-test', :url => 'http://svn-repo-test')
12+
end
13+
14+
subject { @project }
15+
16+
## Test relations
17+
it { should respond_to(:gitolite_repos) }
18+
it { should respond_to(:repo_blank_ident) }
19+
20+
it "should have 1 repository with blank ident" do
21+
expect(@project.repo_blank_ident).to eq @git_repo_1
22+
end
23+
24+
it "should have 2 Git repositories" do
25+
expect(@project.gitolite_repos).to eq [@git_repo_1, @git_repo_2 ]
26+
end
27+
28+
it "should not match existing repository identifier" do
29+
expect(FactoryGirl.build(:project, :identifier => 'git-repo-test')).to be_invalid
30+
end
31+
32+
it "should not match Gitolite Admin repository identifier" do
33+
expect(FactoryGirl.build(:project, :identifier => 'gitolite-admin')).to be_invalid
34+
end
35+
36+
end

0 commit comments

Comments
 (0)