Skip to content

Commit 6a0df15

Browse files
author
root
committed
Rework tests to be more accurate and isolated with various small fixes
1 parent de0bb32 commit 6a0df15

17 files changed

+597
-785
lines changed

Diff for: app/models/git_cache.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class GitCache < ActiveRecord::Base
22
unloadable
33

4+
## Attributes
45
attr_accessible :repo_identifier, :command, :command_output
56
end

Diff for: app/models/github_comment.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
class GithubComment < ActiveRecord::Base
22
unloadable
33

4+
## Relations
45
belongs_to :journal
56

7+
## Validations
68
validates :github_id, :presence => true
79
validates :journal_id, :presence => true, :uniqueness => { :scope => :github_id }
810
end

Diff for: app/models/github_issue.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
class GithubIssue < ActiveRecord::Base
22
unloadable
33

4+
## Relations
45
belongs_to :issue
56

7+
## Validations
68
validates :github_id, :presence => true
79
validates :issue_id, :presence => true, :uniqueness => { :scope => :github_id }
810
end

Diff for: app/models/gitolite_public_key.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
class GitolitePublicKey < ActiveRecord::Base
22
unloadable
33

4-
TITLE_LENGTH_LIMIT = 255
4+
TITLE_LENGTH_LIMIT = 60
55

66
KEY_TYPE_USER = 0
77
KEY_TYPE_DEPLOY = 1
88

99
DEPLOY_PSEUDO_USER = "deploy_key"
1010

11+
## Attributes
1112
attr_accessible :title, :key, :key_type, :delete_when_unused
1213

1314
## Relations
@@ -21,8 +22,12 @@ class GitolitePublicKey < ActiveRecord::Base
2122
:length => { :maximum => TITLE_LENGTH_LIMIT }, :format => /\A[a-z0-9_\-]*\z/i
2223

2324
validates :identifier, :presence => true, :uniqueness => { :case_sensitive => false, :scope => :user_id }
25+
2426
validates :key, :presence => true
25-
validates :key_type, :presence => true, :inclusion => { :in => [KEY_TYPE_USER, KEY_TYPE_DEPLOY] }
27+
28+
validates :key_type, :presence => true,
29+
:numericality => { :only_integer => true },
30+
:inclusion => { :in => [KEY_TYPE_USER, KEY_TYPE_DEPLOY] }
2631

2732
validate :has_not_been_changed
2833
validate :key_correctness
@@ -145,11 +150,11 @@ def destroy_ssh_key
145150

146151
# Strip leading and trailing whitespace
147152
def strip_whitespace
148-
self.title = title.strip
153+
self.title = title.strip rescue ''
149154

150155
# Don't mess with existing keys (since cannot change key text anyway)
151156
if new_record?
152-
self.key = key.strip
157+
self.key = key.strip rescue ''
153158
end
154159
end
155160

@@ -231,9 +236,10 @@ def has_not_been_changed
231236

232237

233238
def key_correctness
239+
return false if self.key.nil?
234240
# Test correctness of fingerprint from output
235241
# and general ssh-(r|d|ecd)sa <key> <id> structure
236-
(self.fingerprint =~ /^(\w{2}:?)+$/i) && (self.key.match(/^(\S+)\s+(\S+)/))
242+
(self.key.match(/^(\S+)\s+(\S+)/)) && (self.fingerprint =~ /^(\w{2}:?)+$/i)
237243
end
238244

239245

Diff for: app/models/repository_deployment_credential.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class RepositoryDeploymentCredential < ActiveRecord::Base
77
VALID_PERMS = [ "R", "RW+" ]
88
DEFAULT_PERM = "RW+"
99

10+
## Attributes
1011
attr_accessible :perm, :active
1112

1213
## Relations

Diff for: app/models/repository_git_config_key.rb

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class RepositoryGitConfigKey < ActiveRecord::Base
22
unloadable
33

4+
## Attributes
45
attr_accessible :key, :value
56

67
## Relations
@@ -9,13 +10,12 @@ class RepositoryGitConfigKey < ActiveRecord::Base
910
## Validations
1011
validates :repository_id, :presence => true
1112

12-
validates :key, :presence => true,
13-
:uniqueness => { :case_sensitive => false, :scope => :repository_id }
13+
validates :key, :presence => true,
14+
:uniqueness => { :case_sensitive => false, :scope => :repository_id },
15+
:format => { :with => /^\A[a-zA-Z0-9]+\.[a-zA-Z0-9.]+\z/ }
1416

1517
validates :value, :presence => true
1618

17-
validate :check_key_format
18-
1919
## Callbacks
2020
after_commit ->(obj) { obj.create_or_update_config_key }, :on => :create
2121
after_commit ->(obj) { obj.create_or_update_config_key }, :on => :update
@@ -41,14 +41,6 @@ def delete_config_key
4141
private
4242

4343

44-
def check_key_format
45-
if !self.key.include?('.')
46-
errors.add(:key, :error_wrong_config_key_format)
47-
return false
48-
end
49-
end
50-
51-
5244
def update_repository(options)
5345
RedmineGitolite::GitHosting.logger.info { "Rebuild Git config keys respository : '#{repository.gitolite_repository_name}'" }
5446
RedmineGitolite::GitHosting.resync_gitolite(:update_repository, repository.id, options)

Diff for: app/models/repository_git_extra.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class RepositoryGitExtra < ActiveRecord::Base
66
HTTPS = 2
77
BOTH = 3
88

9+
## Attributes
910
attr_accessible :git_http, :git_daemon, :git_notify, :default_branch, :protected_branch
1011

1112
## Relations

Diff for: app/models/repository_git_notification.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ class RepositoryGitNotification < ActiveRecord::Base
33

44
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
55

6+
## Attributes
67
attr_accessible :prefix, :sender_address, :include_list, :exclude_list
78

89
## Relations
910
belongs_to :repository
1011

1112
## Validations
12-
validates :repository_id, :presence => true
13+
validates :repository_id, :presence => true,
14+
:uniqueness => true
15+
1316
validates :sender_address, :format => { :with => VALID_EMAIL_REGEX, :allow_blank => true }
1417

1518
validate :validate_mailing_list

Diff for: app/models/repository_mirror.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class RepositoryMirror < ActiveRecord::Base
88
PUSHMODE_FORCE = 1
99
PUSHMODE_FAST_FORWARD = 2
1010

11+
## Attributes
1112
attr_accessible :url, :push_mode, :include_all_branches, :include_all_tags, :explicit_refspec, :active
1213

1314
## Relations
@@ -21,7 +22,7 @@ class RepositoryMirror < ActiveRecord::Base
2122
## ssh://[email protected]:2222/project1/project2/project3/project4.git
2223
validates :url, :presence => true,
2324
:uniqueness => { :case_sensitive => false, :scope => :repository_id },
24-
:format => { :with => /^(ssh:\/\/)([\w\.@]+)(\:[\d]+)?([\w\/\-~]+)(\.git)?$/i }
25+
:format => { :with => /\A(ssh:\/\/)([\w\.@]+)(\:[\d]+)?([\w\/\-~]+)(\.git)?\z/i }
2526

2627
validates :push_mode, :presence => true,
2728
:numericality => { :only_integer => true },
@@ -101,8 +102,8 @@ def push_args
101102

102103
# Strip leading and trailing whitespace
103104
def strip_whitespace
104-
self.url = url.strip
105-
self.explicit_refspec = explicit_refspec.strip
105+
self.url = url.strip rescue ''
106+
self.explicit_refspec = explicit_refspec.strip rescue ''
106107
end
107108

108109

Diff for: app/models/repository_post_receive_url.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class RepositoryPostReceiveUrl < ActiveRecord::Base
66
STATUS_ACTIVE = true
77
STATUS_INACTIVE = false
88

9+
## Attributes
910
attr_accessible :url, :mode, :active, :use_triggers, :triggers, :split_payloads
1011

1112
## Relations
@@ -14,7 +15,7 @@ class RepositoryPostReceiveUrl < ActiveRecord::Base
1415
## Validations
1516
validates :repository_id, :presence => true
1617

17-
## Only allow HTTP(s) format
18+
# Only allow HTTP(s) format
1819
validates :url, :presence => true,
1920
:uniqueness => { :case_sensitive => false, :scope => :repository_id },
2021
:format => { :with => URI::regexp(%w(http https)) }
@@ -73,7 +74,7 @@ def needs_push(payloads)
7374

7475
# Strip leading and trailing whitespace
7576
def strip_whitespace
76-
self.url = url.strip
77+
self.url = url.strip rescue ''
7778
end
7879

7980
end

Diff for: app/models/repository_protected_branche.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ class RepositoryProtectedBranche < ActiveRecord::Base
44
VALID_PERMS = [ "RW+", "RW" ]
55
DEFAULT_PERM = "RW+"
66

7-
attr_accessible :path, :permissions, :position, :user_list
8-
97
acts_as_list
108

9+
## Attributes
10+
attr_accessible :path, :permissions, :position, :user_list
11+
1112
## Relations
1213
belongs_to :repository
1314

@@ -64,7 +65,7 @@ def update_permissions
6465

6566

6667
def remove_blank_items
67-
self.user_list = user_list.select{ |user| !user.blank? }
68+
self.user_list = user_list.select{ |user| !user.blank? } rescue []
6869
end
6970

7071
end

0 commit comments

Comments
 (0)