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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a82977c6
Commit
a82977c6
authored
Sep 15, 2012
by
randx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A bit of test refactoring
parent
0d66cf2a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
75 deletions
+49
-75
Guardfile
Guardfile
+1
-1
app/observers/users_project_observer.rb
app/observers/users_project_observer.rb
+2
-3
spec/models/event_spec.rb
spec/models/event_spec.rb
+20
-21
spec/observers/users_project_observer_spec.rb
spec/observers/users_project_observer_spec.rb
+21
-20
spec/requests/gitlab_flavored_markdown_spec.rb
spec/requests/gitlab_flavored_markdown_spec.rb
+1
-0
spec/support/gitolite_stub.rb
spec/support/gitolite_stub.rb
+4
-30
No files found.
Guardfile
View file @
a82977c6
# A sample Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
# More info at https://github.com/guard/guard#readme
guard
'rspec'
,
:version
=>
2
,
:all_on_start
=>
false
do
guard
'rspec'
,
:version
=>
2
,
:all_on_start
=>
false
,
:all_after_pass
=>
false
do
watch
(
%r{^spec/.+_spec
\.
rb$}
)
watch
(
%r{^spec/.+_spec
\.
rb$}
)
watch
(
%r{^lib/(.+)
\.
rb$}
)
{
|
m
|
"spec/lib/
#{
m
[
1
]
}
_spec.rb"
}
watch
(
%r{^lib/(.+)
\.
rb$}
)
{
|
m
|
"spec/lib/
#{
m
[
1
]
}
_spec.rb"
}
watch
(
'spec/spec_helper.rb'
)
{
"spec"
}
watch
(
'spec/spec_helper.rb'
)
{
"spec"
}
...
...
app/observers/users_project_observer.rb
View file @
a82977c6
...
@@ -15,10 +15,9 @@ class UsersProjectObserver < ActiveRecord::Observer
...
@@ -15,10 +15,9 @@ class UsersProjectObserver < ActiveRecord::Observer
def
after_destroy
(
users_project
)
def
after_destroy
(
users_project
)
Event
.
create
(
Event
.
create
(
project_id:
users_project
.
project
.
id
,
project_id:
users_project
.
project
.
id
,
action:
Event
::
Left
,
action:
Event
::
Left
,
author_id:
users_project
.
user
.
id
author_id:
users_project
.
user
.
id
)
)
end
end
end
end
spec/models/event_spec.rb
View file @
a82977c6
...
@@ -14,12 +14,12 @@ describe Event do
...
@@ -14,12 +14,12 @@ describe Event do
it
{
should
respond_to
(
:commits
)
}
it
{
should
respond_to
(
:commits
)
}
end
end
describe
"Push event"
do
describe
"Push event"
do
before
do
before
do
project
=
Factory
:project
project
=
Factory
:project
@user
=
project
.
owner
@user
=
project
.
owner
data
=
{
data
=
{
before:
"0000000000000000000000000000000000000000"
,
before:
"0000000000000000000000000000000000000000"
,
after:
"0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e"
,
after:
"0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e"
,
ref:
"refs/heads/master"
,
ref:
"refs/heads/master"
,
...
@@ -50,25 +50,24 @@ describe Event do
...
@@ -50,25 +50,24 @@ describe Event do
it
{
@event
.
author
.
should
==
@user
}
it
{
@event
.
author
.
should
==
@user
}
end
end
describe
"Joined project team"
do
describe
'Team events'
do
let
(
:project
)
{
Factory
.
create
:project
}
let
(
:user_project
)
{
stub
.
as_null_object
}
let
(
:new_user
)
{
Factory
.
create
:user
}
let
(
:observer
)
{
UsersProjectObserver
.
instance
}
it
"should create event"
do
UsersProject
.
observers
.
enable
:users_project_observer
before
{
expect
{
Event
.
should_receive
:create
UsersProject
.
bulk_import
(
project
,
[
new_user
.
id
],
UsersProject
::
DEVELOPER
)
}
}.
to
change
{
Event
.
count
}.
by
(
1
)
describe
"Joined project team"
do
it
"should create event"
do
observer
.
after_create
user_project
end
end
end
end
describe
"Left project team"
do
describe
"Left project team"
do
let
(
:project
)
{
Factory
.
create
:project
}
it
"should create event"
do
let
(
:new_user
)
{
Factory
.
create
:user
}
observer
.
after_destroy
user_project
it
"should create event"
do
end
UsersProject
.
bulk_import
(
project
,
[
new_user
.
id
],
UsersProject
::
DEVELOPER
)
UsersProject
.
observers
.
enable
:users_project_observer
expect
{
UsersProject
.
bulk_delete
(
project
,
[
new_user
.
id
])
}.
to
change
{
Event
.
count
}.
by
(
1
)
end
end
end
end
end
end
spec/observers/users_project_observer_spec.rb
View file @
a82977c6
require
'spec_helper'
require
'spec_helper'
describe
UsersProjectObserver
do
describe
UsersProjectObserver
do
let
(
:user
)
{
Factory
.
create
:user
}
let
(
:users_project
)
{
stub
.
as_null_object
}
let
(
:project
)
{
Factory
.
create
(
:project
,
code:
"Fuu"
,
path:
"Fuu"
)
}
let
(
:users_project
)
{
Factory
.
create
(
:users_project
,
project:
project
,
user:
user
)}
subject
{
UsersProjectObserver
.
instance
}
subject
{
UsersProjectObserver
.
instance
}
describe
"#after_create"
do
describe
"#after_create"
do
it
"should called when UsersProject created"
do
it
"should called when UsersProject created"
do
subject
.
should_receive
(
:after_create
)
subject
.
should_receive
(
:after_create
)
UsersProject
.
observers
.
enable
:users_project_observer
do
UsersProject
.
observers
.
enable
:users_project_observer
do
Factory
.
create
(
:users_project
,
create
(
:users_project
)
project:
project
,
user:
user
)
end
end
end
end
it
"should send email to user"
do
it
"should send email to user"
do
Notify
.
should_receive
(
:project_access_granted_email
).
with
(
users_project
.
id
).
and_return
(
double
(
deliver:
true
))
Event
.
stub
(
:create
=>
true
)
Notify
.
should_receive
(
:project_access_granted_email
).
and_return
(
stub
(
deliver:
true
))
subject
.
after_create
(
users_project
)
subject
.
after_create
(
users_project
)
end
end
it
"should create new event"
do
it
"should create new event"
do
Event
.
should_receive
(
:create
).
with
(
Event
.
should_receive
(
:create
).
with
(
project_id:
users_project
.
project
.
id
,
project_id:
users_project
.
project
.
id
,
action:
Event
::
Joined
,
action:
Event
::
Joined
,
author_id:
users_project
.
user
.
id
author_id:
users_project
.
user
.
id
)
)
subject
.
after_create
(
users_project
)
subject
.
after_create
(
users_project
)
end
end
end
end
...
@@ -36,29 +34,32 @@ describe UsersProjectObserver do
...
@@ -36,29 +34,32 @@ describe UsersProjectObserver do
describe
"#after_update"
do
describe
"#after_update"
do
it
"should called when UsersProject updated"
do
it
"should called when UsersProject updated"
do
subject
.
should_receive
(
:after_update
)
subject
.
should_receive
(
:after_update
)
UsersProject
.
observers
.
enable
:users_project_observer
do
UsersProject
.
observers
.
enable
:users_project_observer
do
users_project
.
update_attribute
(
:project_access
,
40
)
create
(
:users_project
)
.
update_attribute
(
:project_access
,
40
)
end
end
end
end
it
"should send email to user"
do
it
"should send email to user"
do
Notify
.
should_receive
(
:project_access_granted_email
).
with
(
users_project
.
id
).
and_return
(
double
(
deliver:
true
))
Notify
.
should_receive
(
:project_access_granted_email
).
with
(
users_project
.
id
).
and_return
(
double
(
deliver:
true
))
subject
.
after_update
(
users_project
)
subject
.
after_update
(
users_project
)
end
end
end
end
describe
"#after_destroy"
do
describe
"#after_destroy"
do
it
"should called when UsersProject destroyed"
do
it
"should called when UsersProject destroyed"
do
subject
.
should_receive
(
:after_destroy
)
subject
.
should_receive
(
:after_destroy
)
UsersProject
.
observers
.
enable
:users_project_observer
do
UsersProject
.
observers
.
enable
:users_project_observer
do
UsersProject
.
bulk_delete
(
create
(
:users_project
).
destroy
users_project
.
project
,
[
users_project
.
user
.
id
]
)
end
end
end
end
it
"should create new event"
do
it
"should create new event"
do
Event
.
should_receive
(
:create
).
with
(
Event
.
should_receive
(
:create
).
with
(
project_id:
users_project
.
project
.
id
,
project_id:
users_project
.
project
.
id
,
action:
Event
::
Left
,
action:
Event
::
Left
,
author_id:
users_project
.
user
.
id
author_id:
users_project
.
user
.
id
)
)
subject
.
after_destroy
(
users_project
)
subject
.
after_destroy
(
users_project
)
...
...
spec/requests/gitlab_flavored_markdown_spec.rb
View file @
a82977c6
...
@@ -25,6 +25,7 @@ describe "Gitlab Flavored Markdown" do
...
@@ -25,6 +25,7 @@ describe "Gitlab Flavored Markdown" do
@tag_name
=
"gfm-test-tag"
@tag_name
=
"gfm-test-tag"
r
.
git
.
native
(
:tag
,
{},
@tag_name
,
commit
.
id
)
r
.
git
.
native
(
:tag
,
{},
@tag_name
,
commit
.
id
)
end
end
after
do
after
do
# delete test branch and tag
# delete test branch and tag
project
.
repo
.
git
.
native
(
:branch
,
{
D
:
true
},
@branch_name
)
project
.
repo
.
git
.
native
(
:branch
,
{
D
:
true
},
@branch_name
)
...
...
spec/support/gitolite_stub.rb
View file @
a82977c6
...
@@ -5,42 +5,16 @@ module GitoliteStub
...
@@ -5,42 +5,16 @@ module GitoliteStub
end
end
def
stub_gitolite_admin
def
stub_gitolite_admin
gitolite_repo
=
mock
(
gitolite_admin
=
double
(
'Gitolite::GitoliteAdmin'
)
clean_permissions:
true
,
gitolite_admin
.
as_null_object
add_permission:
true
)
gitolite_config
=
mock
(
add_repo:
true
,
get_repo:
gitolite_repo
,
has_repo?:
true
)
gitolite_admin
=
double
(
'Gitolite::GitoliteAdmin'
,
config:
gitolite_config
,
save:
true
,
)
Gitolite
::
GitoliteAdmin
.
stub
(
new:
gitolite_admin
)
Gitolite
::
GitoliteAdmin
.
stub
(
new:
gitolite_admin
)
end
end
def
stub_gitlab_gitolite
def
stub_gitlab_gitolite
gitolite_config
=
double
(
'Gitlab::GitoliteConfig'
)
gitolite_config
=
double
(
'Gitlab::GitoliteConfig'
)
gitolite_config
.
stub
(
gitolite_config
.
stub
(
apply:
->
()
{
yield
(
self
)
})
apply:
->
()
{
yield
(
self
)
},
gitolite_config
.
as_null_object
write_key:
true
,
rm_key:
true
,
update_projects:
true
,
update_project:
true
,
update_project!:
true
,
destroy_project:
true
,
destroy_project!:
true
,
admin_all_repo:
true
,
admin_all_repo!:
true
,
)
Gitlab
::
GitoliteConfig
.
stub
(
new:
gitolite_config
)
Gitlab
::
GitoliteConfig
.
stub
(
new:
gitolite_config
)
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