Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
97423a0b
Commit
97423a0b
authored
Aug 29, 2012
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more coverage for model validations and associations
parent
2bdea865
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
96 additions
and
50 deletions
+96
-50
spec/factories.rb
spec/factories.rb
+11
-2
spec/models/event_spec.rb
spec/models/event_spec.rb
+1
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+1
-11
spec/models/key_spec.rb
spec/models/key_spec.rb
+4
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+0
-14
spec/models/note_spec.rb
spec/models/note_spec.rb
+2
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+38
-7
spec/models/protected_branch_spec.rb
spec/models/protected_branch_spec.rb
+9
-11
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+9
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+15
-2
spec/models/users_project_spec.rb
spec/models/users_project_spec.rb
+4
-0
spec/models/wiki_spec.rb
spec/models/wiki_spec.rb
+2
-0
No files found.
spec/factories.rb
View file @
97423a0b
...
@@ -18,11 +18,15 @@ FactoryGirl.define do
...
@@ -18,11 +18,15 @@ FactoryGirl.define do
Faker
::
Lorem
.
sentence
Faker
::
Lorem
.
sentence
end
end
sequence
:name
,
aliases:
[
:file_name
]
do
Faker
::
Name
.
name
end
sequence
(
:url
)
{
Faker
::
Internet
.
uri
(
'http'
)
}
sequence
(
:url
)
{
Faker
::
Internet
.
uri
(
'http'
)
}
factory
:user
,
aliases:
[
:author
,
:assignee
,
:owner
]
do
factory
:user
,
aliases:
[
:author
,
:assignee
,
:owner
]
do
email
{
Faker
::
Internet
.
email
}
email
{
Faker
::
Internet
.
email
}
name
{
Faker
::
Name
.
name
}
name
password
"123456"
password
"123456"
password_confirmation
"123456"
password_confirmation
"123456"
...
@@ -116,6 +120,11 @@ FactoryGirl.define do
...
@@ -116,6 +120,11 @@ FactoryGirl.define do
author
author
title
title
content
content
file_name
{
Faker
::
Lorem
.
sentence
}
file_name
end
factory
:protected_branch
do
name
project
end
end
end
end
spec/models/event_spec.rb
View file @
97423a0b
...
@@ -3,6 +3,7 @@ require 'spec_helper'
...
@@ -3,6 +3,7 @@ require 'spec_helper'
describe
Event
do
describe
Event
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:target
)
}
end
end
describe
"Respond to"
do
describe
"Respond to"
do
...
...
spec/models/issue_spec.rb
View file @
97423a0b
...
@@ -2,21 +2,11 @@ require 'spec_helper'
...
@@ -2,21 +2,11 @@ require 'spec_helper'
describe
Issue
do
describe
Issue
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:author
)
}
it
{
should
belong_to
(
:assignee
)
}
it
{
should
belong_to
(
:milestone
)
}
it
{
should
belong_to
(
:milestone
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
ensure_length_of
(
:description
).
is_within
(
0
..
2000
)
}
it
{
should
validate_presence_of
(
:author_id
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
end
describe
"Scope"
do
it
{
Issue
.
should
respond_to
:closed
}
it
{
Issue
.
should
respond_to
:opened
}
end
end
describe
'modules'
do
describe
'modules'
do
...
...
spec/models/key_spec.rb
View file @
97423a0b
...
@@ -2,12 +2,15 @@ require 'spec_helper'
...
@@ -2,12 +2,15 @@ require 'spec_helper'
describe
Key
do
describe
Key
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:user
)
or
belong_to
(
:project
)
}
it
{
should
belong_to
(
:user
)
}
it
{
should
belong_to
(
:project
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:key
)
}
it
{
should
validate_presence_of
(
:key
)
}
it
{
should
ensure_length_of
(
:title
).
is_within
(
0
..
255
)
}
it
{
should
ensure_length_of
(
:key
).
is_within
(
0
..
5000
)
}
end
end
describe
"Methods"
do
describe
"Methods"
do
...
...
spec/models/merge_request_spec.rb
View file @
97423a0b
require
'spec_helper'
require
'spec_helper'
describe
MergeRequest
do
describe
MergeRequest
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:author
)
}
it
{
should
belong_to
(
:assignee
)
}
end
describe
"Validation"
do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:target_branch
)
}
it
{
should
validate_presence_of
(
:target_branch
)
}
it
{
should
validate_presence_of
(
:source_branch
)
}
it
{
should
validate_presence_of
(
:source_branch
)
}
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:author_id
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
end
describe
"Scope"
do
it
{
MergeRequest
.
should
respond_to
:closed
}
it
{
MergeRequest
.
should
respond_to
:opened
}
end
end
describe
'modules'
do
describe
'modules'
do
...
...
spec/models/note_spec.rb
View file @
97423a0b
...
@@ -3,6 +3,8 @@ require 'spec_helper'
...
@@ -3,6 +3,8 @@ require 'spec_helper'
describe
Note
do
describe
Note
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:noteable
)
}
it
{
should
belong_to
(
:author
).
class_name
(
'User'
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
...
...
spec/models/project_spec.rb
View file @
97423a0b
...
@@ -2,23 +2,52 @@ require 'spec_helper'
...
@@ -2,23 +2,52 @@ require 'spec_helper'
describe
Project
do
describe
Project
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:owner
).
class_name
(
'User'
)
}
it
{
should
have_many
(
:users
)
}
it
{
should
have_many
(
:users
)
}
it
{
should
have_many
(
:protected_branches
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:wikis
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:users_projects
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:milestones
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:users_projects
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:hooks
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:hooks
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:wikis
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:protected_branches
).
dependent
(
:destroy
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
let!
(
:project
)
{
create
(
:project
)
}
it
{
should
validate_presence_of
(
:name
)
}
it
{
should
validate_presence_of
(
:name
)
}
it
{
should
validate_uniqueness_of
(
:name
)
}
it
{
should
ensure_length_of
(
:name
).
is_within
(
0
..
255
)
}
it
{
should
validate_presence_of
(
:path
)
}
it
{
should
validate_presence_of
(
:path
)
}
it
{
should
validate_uniqueness_of
(
:path
)
}
it
{
should
ensure_length_of
(
:path
).
is_within
(
0
..
255
)
}
# TODO: Formats
it
{
should
ensure_length_of
(
:description
).
is_within
(
0
..
2000
)
}
it
{
should
validate_presence_of
(
:code
)
}
it
{
should
validate_presence_of
(
:code
)
}
it
{
should
validate_uniqueness_of
(
:code
)
}
it
{
should
ensure_length_of
(
:code
).
is_within
(
1
..
255
)
}
# TODO: Formats
it
{
should
validate_presence_of
(
:owner
)
}
it
"should not allow new projects beyond user limits"
do
project
.
stub
(
:owner
).
and_return
(
double
(
can_create_project?:
false
,
projects_limit:
1
))
project
.
should_not
be_valid
project
.
errors
[
:base
].
first
.
should
match
(
/Your own projects limit is 1/
)
end
it
"should not allow 'gitolite-admin' as repo name"
do
should
allow_value
(
"blah"
).
for
(
:path
)
should_not
allow_value
(
"gitolite-admin"
).
for
(
:path
)
end
end
end
describe
"Respond to"
do
describe
"Respond to"
do
...
@@ -73,9 +102,11 @@ describe Project do
...
@@ -73,9 +102,11 @@ describe Project do
it
{
should
respond_to
(
:trigger_post_receive
)
}
it
{
should
respond_to
(
:trigger_post_receive
)
}
end
end
it
"should not allow 'gitolite-admin' as repo name"
do
describe
'modules'
do
should
allow_value
(
"blah"
).
for
(
:path
)
it
{
should
include_module
(
Repository
)
}
should_not
allow_value
(
"gitolite-admin"
).
for
(
:path
)
it
{
should
include_module
(
PushObserver
)
}
it
{
should
include_module
(
Authority
)
}
it
{
should
include_module
(
Team
)
}
end
end
it
"should return valid url to repo"
do
it
"should return valid url to repo"
do
...
...
spec/models/protected_branch_spec.rb
View file @
97423a0b
require
'spec_helper'
require
'spec_helper'
describe
ProtectedBranch
do
describe
ProtectedBranch
do
let
(
:project
)
{
Factory
(
:project
)
}
describe
'Associations'
do
describe
'Associations'
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:project
)
}
end
end
...
@@ -13,26 +11,26 @@ describe ProtectedBranch do
...
@@ -13,26 +11,26 @@ describe ProtectedBranch do
end
end
describe
'Callbacks'
do
describe
'Callbacks'
do
subject
{
ProtectedBranch
.
new
(
project:
project
,
name:
'branch_name'
)
}
let
(
:branch
)
{
build
(
:protected_branch
)
}
it
'call update_repository after save'
do
it
'call update_repository after save'
do
subject
.
should_receive
(
:update_repository
)
branch
.
should_receive
(
:update_repository
)
subject
.
save
branch
.
save
end
end
it
'call update_repository after destroy'
do
it
'call update_repository after destroy'
do
subject
.
should_receive
(
:update_repository
)
branch
.
save
subject
.
destroy
branch
.
should_receive
(
:update_repository
)
branch
.
destroy
end
end
end
end
describe
'#commit'
do
describe
'#commit'
do
subject
{
ProtectedBranch
.
new
(
project:
project
,
name:
'cant_touch_this'
)
}
let
(
:branch
)
{
create
(
:protected_branch
)
}
it
'commits itself to its project'
do
it
'commits itself to its project'
do
project
.
should_receive
(
:commit
).
with
(
'cant_touch_this'
)
branch
.
project
.
should_receive
(
:commit
).
with
(
branch
.
name
)
branch
.
commit
subject
.
commit
end
end
end
end
end
end
spec/models/snippet_spec.rb
View file @
97423a0b
...
@@ -3,14 +3,21 @@ require 'spec_helper'
...
@@ -3,14 +3,21 @@ require 'spec_helper'
describe
Snippet
do
describe
Snippet
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:author
)
}
it
{
should
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:author_id
)
}
it
{
should
validate_presence_of
(
:author_id
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
ensure_length_of
(
:title
).
is_within
(
0
..
255
)
}
it
{
should
validate_presence_of
(
:file_name
)
}
it
{
should
validate_presence_of
(
:file_name
)
}
it
{
should
ensure_length_of
(
:title
).
is_within
(
0
..
255
)
}
it
{
should
validate_presence_of
(
:content
)
}
it
{
should
validate_presence_of
(
:content
)
}
it
{
should
ensure_length_of
(
:content
).
is_within
(
0
..
10_000
)
}
end
end
end
end
spec/models/user_spec.rb
View file @
97423a0b
...
@@ -2,13 +2,26 @@ require 'spec_helper'
...
@@ -2,13 +2,26 @@ require 'spec_helper'
describe
User
do
describe
User
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
have_many
(
:projects
)
}
it
{
should
have_many
(
:users_projects
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:users_projects
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:projects
)
}
it
{
should
have_many
(
:my_own_projects
).
class_name
(
'Project'
)
}
it
{
should
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:events
).
class_name
(
'Event'
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:recent_events
).
class_name
(
'Event'
)
}
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:assigned_issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:assigned_issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:assigned_merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:assigned_merge_requests
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
end
describe
'validations'
do
it
{
should
validate_presence_of
(
:projects_limit
)
}
it
{
should
validate_numericality_of
(
:projects_limit
)
}
it
{
should
allow_value
(
0
).
for
(
:projects_limit
)
}
it
{
should_not
allow_value
(
-
1
).
for
(
:projects_limit
)
}
it
{
should
ensure_length_of
(
:bio
).
is_within
(
0
..
255
)
}
end
end
describe
"Respond to"
do
describe
"Respond to"
do
...
...
spec/models/users_project_spec.rb
View file @
97423a0b
...
@@ -7,7 +7,11 @@ describe UsersProject do
...
@@ -7,7 +7,11 @@ describe UsersProject do
end
end
describe
"Validation"
do
describe
"Validation"
do
let!
(
:users_project
)
{
create
(
:users_project
)
}
it
{
should
validate_presence_of
(
:user_id
)
}
it
{
should
validate_presence_of
(
:user_id
)
}
it
{
should
validate_uniqueness_of
(
:user_id
).
scoped_to
(
:project_id
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
end
end
...
...
spec/models/wiki_spec.rb
View file @
97423a0b
...
@@ -4,10 +4,12 @@ describe Wiki do
...
@@ -4,10 +4,12 @@ describe Wiki do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:project
)
}
it
{
should
belong_to
(
:user
)
}
it
{
should
belong_to
(
:user
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
end
end
describe
"Validation"
do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
ensure_length_of
(
:title
).
is_within
(
1
..
250
)
}
it
{
should
validate_presence_of
(
:content
)
}
it
{
should
validate_presence_of
(
:content
)
}
it
{
should
validate_presence_of
(
:user_id
)
}
it
{
should
validate_presence_of
(
:user_id
)
}
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment