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
Boxiang Sun
gitlab-ce
Commits
001f3bc5
Commit
001f3bc5
authored
Apr 10, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specs refactoring to reduce test time. Disabled observers by default for specs
parent
0ae89200
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
99 additions
and
112 deletions
+99
-112
spec/features/profile_spec.rb
spec/features/profile_spec.rb
+1
-0
spec/features/projects_spec.rb
spec/features/projects_spec.rb
+1
-0
spec/lib/votes_spec.rb
spec/lib/votes_spec.rb
+60
-56
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-1
spec/observers/issue_observer_spec.rb
spec/observers/issue_observer_spec.rb
+11
-47
spec/observers/merge_request_observer_spec.rb
spec/observers/merge_request_observer_spec.rb
+0
-6
spec/observers/user_observer_spec.rb
spec/observers/user_observer_spec.rb
+1
-0
spec/observers/users_project_observer_spec.rb
spec/observers/users_project_observer_spec.rb
+2
-0
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+1
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+1
-0
spec/spec_helper.rb
spec/spec_helper.rb
+3
-1
spec/support/test_env.rb
spec/support/test_env.rb
+17
-1
No files found.
spec/features/profile_spec.rb
View file @
001f3bc5
require
'spec_helper'
require
'spec_helper'
describe
"Profile account page"
do
describe
"Profile account page"
do
before
(
:each
)
{
enable_observers
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
before
do
...
...
spec/features/projects_spec.rb
View file @
001f3bc5
require
'spec_helper'
require
'spec_helper'
describe
"Projects"
do
describe
"Projects"
do
before
(
:each
)
{
enable_observers
}
before
{
login_as
:user
}
before
{
login_as
:user
}
describe
"DELETE /projects/:id"
do
describe
"DELETE /projects/:id"
do
...
...
spec/lib/votes_spec.rb
View file @
001f3bc5
require
'spec_helper'
require
'spec_helper'
describe
MergeRequest
do
describe
Issue
,
'Votes'
do
let
(
:
merge_request
)
{
FactoryGirl
.
create
(
:merge_request_with_diffs
)
}
let
(
:
issue
)
{
create
(
:issue
)
}
describe
"#upvotes"
do
describe
"#upvotes"
do
it
"with no notes has a 0/0 score"
do
it
"with no notes has a 0/0 score"
do
merge_request
.
upvotes
.
should
==
0
issue
.
upvotes
.
should
==
0
end
end
it
"should recognize non-+1 notes"
do
it
"should recognize non-+1 notes"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"No +1 here"
)
add_note
"No +1 here"
merge_request
.
should
have
(
1
).
note
issue
.
should
have
(
1
).
note
merge_request
.
notes
.
first
.
upvote?
.
should
be_false
issue
.
notes
.
first
.
upvote?
.
should
be_false
merge_request
.
upvotes
.
should
==
0
issue
.
upvotes
.
should
==
0
end
end
it
"should recognize a single +1 note"
do
it
"should recognize a single +1 note"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
upvotes
.
should
==
1
issue
.
upvotes
.
should
==
1
end
end
it
"should recognize multiple +1 notes"
do
it
"should recognize multiple +1 notes"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
add_note
"+1 I want this"
merge_request
.
upvotes
.
should
==
2
issue
.
upvotes
.
should
==
2
end
end
end
end
describe
"#downvotes"
do
describe
"#downvotes"
do
it
"with no notes has a 0/0 score"
do
it
"with no notes has a 0/0 score"
do
merge_request
.
downvotes
.
should
==
0
issue
.
downvotes
.
should
==
0
end
end
it
"should recognize non--1 notes"
do
it
"should recognize non--1 notes"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"Almost got a -1"
)
add_note
"Almost got a -1"
merge_request
.
should
have
(
1
).
note
issue
.
should
have
(
1
).
note
merge_request
.
notes
.
first
.
downvote?
.
should
be_false
issue
.
notes
.
first
.
downvote?
.
should
be_false
merge_request
.
downvotes
.
should
==
0
issue
.
downvotes
.
should
==
0
end
end
it
"should recognize a single -1 note"
do
it
"should recognize a single -1 note"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
downvotes
.
should
==
1
issue
.
downvotes
.
should
==
1
end
end
it
"should recognize multiple -1 notes"
do
it
"should recognize multiple -1 notes"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 Away with this"
)
add_note
"-1 Away with this"
merge_request
.
downvotes
.
should
==
2
issue
.
downvotes
.
should
==
2
end
end
end
end
describe
"#votes_count"
do
describe
"#votes_count"
do
it
"with no notes has a 0/0 score"
do
it
"with no notes has a 0/0 score"
do
merge_request
.
votes_count
.
should
==
0
issue
.
votes_count
.
should
==
0
end
end
it
"should recognize non notes"
do
it
"should recognize non notes"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"No +1 here"
)
add_note
"No +1 here"
merge_request
.
should
have
(
1
).
note
issue
.
should
have
(
1
).
note
merge_request
.
votes_count
.
should
==
0
issue
.
votes_count
.
should
==
0
end
end
it
"should recognize a single +1 note"
do
it
"should recognize a single +1 note"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
votes_count
.
should
==
1
issue
.
votes_count
.
should
==
1
end
end
it
"should recognize a single -1 note"
do
it
"should recognize a single -1 note"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
votes_count
.
should
==
1
issue
.
votes_count
.
should
==
1
end
end
it
"should recognize multiple notes"
do
it
"should recognize multiple notes"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
add_note
"+1 I want this"
merge_request
.
votes_count
.
should
==
3
issue
.
votes_count
.
should
==
3
end
end
end
end
describe
"#upvotes_in_percent"
do
describe
"#upvotes_in_percent"
do
it
"with no notes has a 0% score"
do
it
"with no notes has a 0% score"
do
merge_request
.
upvotes_in_percent
.
should
==
0
issue
.
upvotes_in_percent
.
should
==
0
end
end
it
"should count a single 1 note as 100%"
do
it
"should count a single 1 note as 100%"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
upvotes_in_percent
.
should
==
100
issue
.
upvotes_in_percent
.
should
==
100
end
end
it
"should count multiple +1 notes as 100%"
do
it
"should count multiple +1 notes as 100%"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
add_note
"+1 I want this"
merge_request
.
upvotes_in_percent
.
should
==
100
issue
.
upvotes_in_percent
.
should
==
100
end
end
it
"should count fractions for multiple +1 and -1 notes correctly"
do
it
"should count fractions for multiple +1 and -1 notes correctly"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
add_note
"+1 I want this"
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 me too"
)
add_note
"+1 me too"
merge_request
.
upvotes_in_percent
.
should
==
75
issue
.
upvotes_in_percent
.
should
==
75
end
end
end
end
describe
"#downvotes_in_percent"
do
describe
"#downvotes_in_percent"
do
it
"with no notes has a 0% score"
do
it
"with no notes has a 0% score"
do
merge_request
.
downvotes_in_percent
.
should
==
0
issue
.
downvotes_in_percent
.
should
==
0
end
end
it
"should count a single -1 note as 100%"
do
it
"should count a single -1 note as 100%"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
downvotes_in_percent
.
should
==
100
issue
.
downvotes_in_percent
.
should
==
100
end
end
it
"should count multiple -1 notes as 100%"
do
it
"should count multiple -1 notes as 100%"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 Away with this"
)
add_note
"-1 Away with this"
merge_request
.
downvotes_in_percent
.
should
==
100
issue
.
downvotes_in_percent
.
should
==
100
end
end
it
"should count fractions for multiple +1 and -1 notes correctly"
do
it
"should count fractions for multiple +1 and -1 notes correctly"
do
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
add_note
"+1 This is awesome"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
add_note
"+1 I want this"
merge_request
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
add_note
"-1 This is bad"
merge_request
.
notes
<<
create
(
:note
,
note:
"+1 me too"
)
add_note
"+1 me too"
merge_request
.
downvotes_in_percent
.
should
==
25
issue
.
downvotes_in_percent
.
should
==
25
end
end
end
end
def
add_note
(
text
)
issue
.
notes
<<
create
(
:note
,
note:
text
,
project:
issue
.
project
)
end
end
end
spec/models/project_spec.rb
View file @
001f3bc5
...
@@ -39,7 +39,6 @@ describe Project do
...
@@ -39,7 +39,6 @@ describe Project do
it
{
should
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:snippets
).
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
(
:hooks
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:wikis
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:protected_branches
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:protected_branches
).
dependent
(
:destroy
)
}
end
end
...
@@ -97,6 +96,7 @@ describe Project do
...
@@ -97,6 +96,7 @@ describe Project do
end
end
describe
"last_activity methods"
do
describe
"last_activity methods"
do
before
{
enable_observers
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:last_event
)
{
double
(
created_at:
Time
.
now
)
}
let
(
:last_event
)
{
double
(
created_at:
Time
.
now
)
}
...
...
spec/observers/issue_observer_spec.rb
View file @
001f3bc5
...
@@ -4,11 +4,7 @@ describe IssueObserver do
...
@@ -4,11 +4,7 @@ describe IssueObserver do
let
(
:some_user
)
{
create
:user
}
let
(
:some_user
)
{
create
:user
}
let
(
:assignee
)
{
create
:user
}
let
(
:assignee
)
{
create
:user
}
let
(
:author
)
{
create
:user
}
let
(
:author
)
{
create
:user
}
let
(
:mock_issue
)
{
double
(
:issue
,
id:
42
,
assignee:
assignee
,
author:
author
)
}
let
(
:mock_issue
)
{
create
(
:issue
,
assignee:
assignee
,
author:
author
)
}
let
(
:assigned_issue
)
{
create
(
:issue
,
assignee:
assignee
,
author:
author
)
}
let
(
:unassigned_issue
)
{
create
(
:issue
,
author:
author
)
}
let
(
:closed_assigned_issue
)
{
create
(
:closed_issue
,
assignee:
assignee
,
author:
author
)
}
let
(
:closed_unassigned_issue
)
{
create
(
:closed_issue
,
author:
author
)
}
before
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
before
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
...
@@ -18,15 +14,6 @@ describe IssueObserver do
...
@@ -18,15 +14,6 @@ describe IssueObserver do
subject
{
IssueObserver
.
instance
}
subject
{
IssueObserver
.
instance
}
describe
'#after_create'
do
describe
'#after_create'
do
it
'is called when an issue is created'
do
subject
.
should_receive
(
:after_create
)
Issue
.
observers
.
enable
:issue_observer
do
create
(
:issue
,
project:
create
(
:project
))
end
end
it
'trigger notification to send emails'
do
it
'trigger notification to send emails'
do
subject
.
should_receive
(
:notification
)
subject
.
should_receive
(
:notification
)
...
@@ -36,41 +23,28 @@ describe IssueObserver do
...
@@ -36,41 +23,28 @@ describe IssueObserver do
context
'#after_close'
do
context
'#after_close'
do
context
'a status "closed"'
do
context
'a status "closed"'
do
before
{
mock_issue
.
stub
(
state:
'closed'
)
}
it
'note is created if the issue is being closed'
do
it
'note is created if the issue is being closed'
do
Note
.
should_receive
(
:create_status_change_note
).
with
(
assigned
_issue
,
some_user
,
'closed'
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
mock
_issue
,
some_user
,
'closed'
)
assigned_issue
.
close
subject
.
after_close
(
mock_issue
,
nil
)
end
end
it
'trigger notification to send emails'
do
it
'trigger notification to send emails'
do
subject
.
should_receive
(
:notification
)
subject
.
notification
.
should_receive
(
:close_issue
).
with
(
mock_issue
,
some_user
)
assigned_issue
.
close
end
it
'creates a note'
do
subject
.
after_close
(
mock_issue
,
nil
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
unassigned_issue
,
some_user
,
'closed'
)
unassigned_issue
.
close
end
end
end
end
context
'a status "reopened"'
do
context
'a status "reopened"'
do
it
'note is created if the issue is being reopened'
do
before
{
mock_issue
.
stub
(
state:
'reopened'
)
}
Note
.
should_receive
(
:create_status_change_note
).
with
(
closed_assigned_issue
,
some_user
,
'reopened'
)
closed_assigned_issue
.
reopen
end
it
'trigger notification to send emails'
do
subject
.
should_receive
(
:notification
)
closed_assigned_issue
.
reopen
end
it
'
create a note
'
do
it
'
note is created if the issue is being reopened
'
do
Note
.
should_receive
(
:create_status_change_note
).
with
(
closed_unassigned
_issue
,
some_user
,
'reopened'
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
mock
_issue
,
some_user
,
'reopened'
)
closed_unassigned_issue
.
reopen
subject
.
after_reopen
(
mock_issue
,
nil
)
end
end
end
end
end
end
...
@@ -80,16 +54,6 @@ describe IssueObserver do
...
@@ -80,16 +54,6 @@ describe IssueObserver do
mock_issue
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
mock_issue
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
end
end
it
'is called when an issue is changed'
do
changed
=
create
(
:issue
,
project:
create
(
:project
))
subject
.
should_receive
(
:after_update
)
Issue
.
observers
.
enable
:issue_observer
do
changed
.
description
=
'I changed'
changed
.
save
end
end
context
'notification'
do
context
'notification'
do
it
'triggered if the issue is being reassigned'
do
it
'triggered if the issue is being reassigned'
do
mock_issue
.
should_receive
(
:is_being_reassigned?
).
and_return
(
true
)
mock_issue
.
should_receive
(
:is_being_reassigned?
).
and_return
(
true
)
...
...
spec/observers/merge_request_observer_spec.rb
View file @
001f3bc5
...
@@ -16,12 +16,6 @@ describe MergeRequestObserver do
...
@@ -16,12 +16,6 @@ describe MergeRequestObserver do
subject
{
MergeRequestObserver
.
instance
}
subject
{
MergeRequestObserver
.
instance
}
describe
'#after_create'
do
describe
'#after_create'
do
it
'is called when a merge request is created'
do
subject
.
should_receive
(
:after_create
)
create
(
:merge_request
,
project:
create
(
:project
))
end
it
'trigger notification service'
do
it
'trigger notification service'
do
subject
.
should_receive
(
:notification
)
subject
.
should_receive
(
:notification
)
subject
.
after_create
(
mr_mock
)
subject
.
after_create
(
mr_mock
)
...
...
spec/observers/user_observer_spec.rb
View file @
001f3bc5
require
'spec_helper'
require
'spec_helper'
describe
UserObserver
do
describe
UserObserver
do
before
(
:each
)
{
enable_observers
}
subject
{
UserObserver
.
instance
}
subject
{
UserObserver
.
instance
}
before
{
subject
.
stub
(
notification:
mock
(
'NotificationService'
).
as_null_object
)
}
before
{
subject
.
stub
(
notification:
mock
(
'NotificationService'
).
as_null_object
)
}
...
...
spec/observers/users_project_observer_spec.rb
View file @
001f3bc5
require
'spec_helper'
require
'spec_helper'
describe
UsersProjectObserver
do
describe
UsersProjectObserver
do
before
(
:each
)
{
enable_observers
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
UsersProjectObserver
.
instance
}
subject
{
UsersProjectObserver
.
instance
}
...
...
spec/requests/api/milestones_spec.rb
View file @
001f3bc5
...
@@ -2,6 +2,7 @@ require 'spec_helper'
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
API
do
describe
Gitlab
::
API
do
include
ApiHelpers
include
ApiHelpers
before
(
:each
)
{
enable_observers
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
...
...
spec/requests/api/projects_spec.rb
View file @
001f3bc5
...
@@ -2,6 +2,7 @@ require 'spec_helper'
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
API
do
describe
Gitlab
::
API
do
include
ApiHelpers
include
ApiHelpers
before
(
:each
)
{
enable_observers
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
...
...
spec/spec_helper.rb
View file @
001f3bc5
...
@@ -41,13 +41,15 @@ Spork.prefork do
...
@@ -41,13 +41,15 @@ Spork.prefork do
config
.
include
FactoryGirl
::
Syntax
::
Methods
config
.
include
FactoryGirl
::
Syntax
::
Methods
config
.
include
Devise
::
TestHelpers
,
type: :controller
config
.
include
Devise
::
TestHelpers
,
type: :controller
config
.
include
TestEnv
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# examples within a transaction, remove the following line or assign false
# instead of true.
# instead of true.
config
.
use_transactional_fixtures
=
false
config
.
use_transactional_fixtures
=
false
config
.
before
do
config
.
before
do
TestEnv
.
init
TestEnv
.
init
(
observers:
false
)
end
end
end
end
end
end
...
...
spec/support/test_env.rb
View file @
001f3bc5
...
@@ -12,7 +12,15 @@ module TestEnv
...
@@ -12,7 +12,15 @@ module TestEnv
# - add_key
# - add_key
# - remove_key
# - remove_key
#
#
def
init
def
init
(
opts
=
{})
# Disable observers to improve test speed
#
# You can enable it in whole test case where needed by next string:
#
# before(:each) { enable_observers }
#
disable_observers
if
opts
[
:observers
]
==
false
# Use tmp dir for FS manipulations
# Use tmp dir for FS manipulations
repos_path
=
Rails
.
root
.
join
(
'tmp'
,
'test-git-base-path'
)
repos_path
=
Rails
.
root
.
join
(
'tmp'
,
'test-git-base-path'
)
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
repos_path
)
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
repos_path
)
...
@@ -60,4 +68,12 @@ module TestEnv
...
@@ -60,4 +68,12 @@ module TestEnv
command
=
"git init --quiet --bare
#{
path
}
;"
command
=
"git init --quiet --bare
#{
path
}
;"
system
(
command
)
system
(
command
)
end
end
def
enable_observers
ActiveRecord
::
Base
.
observers
.
enable
(
:all
)
end
def
disable_observers
ActiveRecord
::
Base
.
observers
.
disable
(
:all
)
end
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