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
Tatuya Kamada
gitlab-ce
Commits
dad88568
Commit
dad88568
authored
May 21, 2015
by
Robert Speicher
Committed by
Dmitriy Zaporozhets
Jun 22, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update and simplify Import controller specs
parent
9874cf59
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
36 deletions
+75
-36
spec/controllers/import/bitbucket_controller_spec.rb
spec/controllers/import/bitbucket_controller_spec.rb
+11
-8
spec/controllers/import/github_controller_spec.rb
spec/controllers/import/github_controller_spec.rb
+8
-11
spec/controllers/import/gitlab_controller_spec.rb
spec/controllers/import/gitlab_controller_spec.rb
+10
-7
spec/controllers/import/gitorious_controller_spec.rb
spec/controllers/import/gitorious_controller_spec.rb
+6
-3
spec/controllers/import/google_code_controller_spec.rb
spec/controllers/import/google_code_controller_spec.rb
+7
-7
spec/controllers/import/import_spec_helper.rb
spec/controllers/import/import_spec_helper.rb
+33
-0
No files found.
spec/controllers/import/bitbucket_controller_spec.rb
View file @
dad88568
require
'spec_helper'
require
'spec_helper'
require_relative
'import_spec_helper'
describe
Import
::
BitbucketController
do
describe
Import
::
BitbucketController
do
include
ImportSpecHelper
let
(
:user
)
{
create
(
:user
,
bitbucket_access_token:
'asd123'
,
bitbucket_access_token_secret:
"sekret"
)
}
let
(
:user
)
{
create
(
:user
,
bitbucket_access_token:
'asd123'
,
bitbucket_access_token_secret:
"sekret"
)
}
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
controller
.
stub
(
:bitbucket_import_enabled?
).
and_return
(
true
)
allow
(
controller
).
to
receive
(
:bitbucket_import_enabled?
).
and_return
(
true
)
end
end
describe
"GET callback"
do
describe
"GET callback"
do
before
do
before
do
session
[
:oauth_request_token
]
=
{}
session
[
:oauth_request_token
]
=
{}
end
end
it
"updates access token"
do
it
"updates access token"
do
token
=
"asdasd12345"
token
=
"asdasd12345"
secret
=
"sekrettt"
secret
=
"sekrettt"
access_token
=
double
(
token:
token
,
secret:
secret
)
access_token
=
double
(
token:
token
,
secret:
secret
)
Gitlab
::
BitbucketImport
::
Client
.
any_instance
.
stub
(
:get_token
).
and_return
(
access_token
)
allow_any_instance_of
(
Gitlab
::
BitbucketImport
::
Client
).
Gitlab
.
config
.
omniauth
.
providers
<<
OpenStruct
.
new
(
app_id:
"asd123"
,
app_secret:
"asd123"
,
name:
"bitbucket"
)
to
receive
(
:get_token
).
and_return
(
access_token
)
stub_omniauth_provider
(
'bitbucket'
)
get
:callback
get
:callback
...
@@ -35,7 +39,7 @@ describe Import::BitbucketController do
...
@@ -35,7 +39,7 @@ describe Import::BitbucketController do
it
"assigns variables"
do
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'bitbucket'
,
creator_id:
user
.
id
)
@project
=
create
(
:project
,
import_type:
'bitbucket'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:client
,
:projects
).
and_return
(
[
@repo
])
stub_client
(
projects:
[
@repo
])
get
:status
get
:status
...
@@ -45,7 +49,7 @@ describe Import::BitbucketController do
...
@@ -45,7 +49,7 @@ describe Import::BitbucketController do
it
"does not show already added project"
do
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'bitbucket'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
@project
=
create
(
:project
,
import_type:
'bitbucket'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
controller
.
stub_chain
(
:client
,
:projects
).
and_return
(
[
@repo
])
stub_client
(
projects:
[
@repo
])
get
:status
get
:status
...
@@ -77,8 +81,7 @@ describe Import::BitbucketController do
...
@@ -77,8 +81,7 @@ describe Import::BitbucketController do
to
receive
(
:new
).
with
(
bitbucket_repo
,
user
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
user
).
and_return
(
double
(
execute:
true
))
and_return
(
double
(
execute:
true
))
controller
.
stub_chain
(
:client
,
:user
).
and_return
(
bitbucket_user
)
stub_client
(
user:
bitbucket_user
,
project:
bitbucket_repo
)
controller
.
stub_chain
(
:client
,
:project
).
and_return
(
bitbucket_repo
)
end
end
context
"when the repository owner is the Bitbucket user"
do
context
"when the repository owner is the Bitbucket user"
do
...
...
spec/controllers/import/github_controller_spec.rb
View file @
dad88568
require
'spec_helper'
require
'spec_helper'
require_relative
'import_spec_helper'
describe
Import
::
GithubController
do
describe
Import
::
GithubController
do
include
ImportSpecHelper
let
(
:user
)
{
create
(
:user
,
github_access_token:
'asd123'
)
}
let
(
:user
)
{
create
(
:user
,
github_access_token:
'asd123'
)
}
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
controller
.
stub
(
:github_import_enabled?
).
and_return
(
true
)
allow
(
controller
).
to
receive
(
:github_import_enabled?
).
and_return
(
true
)
end
end
describe
"GET callback"
do
describe
"GET callback"
do
...
@@ -13,9 +16,7 @@ describe Import::GithubController do
...
@@ -13,9 +16,7 @@ describe Import::GithubController do
token
=
"asdasd12345"
token
=
"asdasd12345"
allow_any_instance_of
(
Gitlab
::
GithubImport
::
Client
).
allow_any_instance_of
(
Gitlab
::
GithubImport
::
Client
).
to
receive
(
:get_token
).
and_return
(
token
)
to
receive
(
:get_token
).
and_return
(
token
)
Gitlab
.
config
.
omniauth
.
providers
<<
OpenStruct
.
new
(
app_id:
'asd123'
,
stub_omniauth_provider
(
'github'
)
app_secret:
'asd123'
,
name:
'github'
)
get
:callback
get
:callback
...
@@ -33,9 +34,7 @@ describe Import::GithubController do
...
@@ -33,9 +34,7 @@ describe Import::GithubController do
it
"assigns variables"
do
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'github'
,
creator_id:
user
.
id
)
@project
=
create
(
:project
,
import_type:
'github'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
stub_client
(
repos:
[
@repo
],
orgs:
[
@org
],
org_repos:
[
@org_repo
])
controller
.
stub_chain
(
:client
,
:orgs
).
and_return
([
@org
])
controller
.
stub_chain
(
:client
,
:org_repos
).
with
(
@org
.
login
).
and_return
([
@org_repo
])
get
:status
get
:status
...
@@ -45,8 +44,7 @@ describe Import::GithubController do
...
@@ -45,8 +44,7 @@ describe Import::GithubController do
it
"does not show already added project"
do
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'github'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
@project
=
create
(
:project
,
import_type:
'github'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
stub_client
(
repos:
[
@repo
],
orgs:
[])
controller
.
stub_chain
(
:client
,
:orgs
).
and_return
([])
get
:status
get
:status
...
@@ -67,8 +65,7 @@ describe Import::GithubController do
...
@@ -67,8 +65,7 @@ describe Import::GithubController do
}
}
before
do
before
do
controller
.
stub_chain
(
:client
,
:user
).
and_return
(
github_user
)
stub_client
(
user:
github_user
,
repo:
github_repo
)
controller
.
stub_chain
(
:client
,
:repo
).
and_return
(
github_repo
)
end
end
context
"when the repository owner is the GitHub user"
do
context
"when the repository owner is the GitHub user"
do
...
...
spec/controllers/import/gitlab_controller_spec.rb
View file @
dad88568
require
'spec_helper'
require
'spec_helper'
require_relative
'import_spec_helper'
describe
Import
::
GitlabController
do
describe
Import
::
GitlabController
do
include
ImportSpecHelper
let
(
:user
)
{
create
(
:user
,
gitlab_access_token:
'asd123'
)
}
let
(
:user
)
{
create
(
:user
,
gitlab_access_token:
'asd123'
)
}
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
controller
.
stub
(
:gitlab_import_enabled?
).
and_return
(
true
)
allow
(
controller
).
to
receive
(
:gitlab_import_enabled?
).
and_return
(
true
)
end
end
describe
"GET callback"
do
describe
"GET callback"
do
it
"updates access token"
do
it
"updates access token"
do
token
=
"asdasd12345"
token
=
"asdasd12345"
Gitlab
::
GitlabImport
::
Client
.
any_instance
.
stub_chain
(
:client
,
:auth_code
,
:get_token
,
:token
).
and_return
(
token
)
allow_any_instance_of
(
Gitlab
::
GitlabImport
::
Client
).
Gitlab
.
config
.
omniauth
.
providers
<<
OpenStruct
.
new
(
app_id:
"asd123"
,
app_secret:
"asd123"
,
name:
"gitlab"
)
to
receive
(
:get_token
).
and_return
(
token
)
stub_omniauth_provider
(
'gitlab'
)
get
:callback
get
:callback
...
@@ -28,7 +32,7 @@ describe Import::GitlabController do
...
@@ -28,7 +32,7 @@ describe Import::GitlabController do
it
"assigns variables"
do
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'gitlab'
,
creator_id:
user
.
id
)
@project
=
create
(
:project
,
import_type:
'gitlab'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:client
,
:projects
).
and_return
(
[
@repo
])
stub_client
(
projects:
[
@repo
])
get
:status
get
:status
...
@@ -38,7 +42,7 @@ describe Import::GitlabController do
...
@@ -38,7 +42,7 @@ describe Import::GitlabController do
it
"does not show already added project"
do
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'gitlab'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
@project
=
create
(
:project
,
import_type:
'gitlab'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
controller
.
stub_chain
(
:client
,
:projects
).
and_return
(
[
@repo
])
stub_client
(
projects:
[
@repo
])
get
:status
get
:status
...
@@ -66,8 +70,7 @@ describe Import::GitlabController do
...
@@ -66,8 +70,7 @@ describe Import::GitlabController do
}
}
before
do
before
do
controller
.
stub_chain
(
:client
,
:user
).
and_return
(
gitlab_user
)
stub_client
(
user:
gitlab_user
,
project:
gitlab_repo
)
controller
.
stub_chain
(
:client
,
:project
).
and_return
(
gitlab_repo
)
end
end
context
"when the repository owner is the GitLab.com user"
do
context
"when the repository owner is the GitLab.com user"
do
...
...
spec/controllers/import/gitorious_controller_spec.rb
View file @
dad88568
require
'spec_helper'
require
'spec_helper'
require_relative
'import_spec_helper'
describe
Import
::
GitoriousController
do
describe
Import
::
GitoriousController
do
include
ImportSpecHelper
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
before
do
...
@@ -30,7 +33,7 @@ describe Import::GitoriousController do
...
@@ -30,7 +33,7 @@ describe Import::GitoriousController do
it
"assigns variables"
do
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'gitorious'
,
creator_id:
user
.
id
)
@project
=
create
(
:project
,
import_type:
'gitorious'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
(
[
@repo
])
stub_client
(
repos:
[
@repo
])
get
:status
get
:status
...
@@ -40,7 +43,7 @@ describe Import::GitoriousController do
...
@@ -40,7 +43,7 @@ describe Import::GitoriousController do
it
"does not show already added project"
do
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'gitorious'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
@project
=
create
(
:project
,
import_type:
'gitorious'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
(
[
@repo
])
stub_client
(
repos:
[
@repo
])
get
:status
get
:status
...
@@ -59,7 +62,7 @@ describe Import::GitoriousController do
...
@@ -59,7 +62,7 @@ describe Import::GitoriousController do
expect
(
Gitlab
::
GitoriousImport
::
ProjectCreator
).
expect
(
Gitlab
::
GitoriousImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
@repo
,
namespace
,
user
).
to
receive
(
:new
).
with
(
@repo
,
namespace
,
user
).
and_return
(
double
(
execute:
true
))
and_return
(
double
(
execute:
true
))
controller
.
stub_chain
(
:client
,
:repo
).
and_return
(
@repo
)
stub_client
(
repo:
@repo
)
post
:create
,
format: :js
post
:create
,
format: :js
end
end
...
...
spec/controllers/import/google_code_controller_spec.rb
View file @
dad88568
require
'spec_helper'
require
'spec_helper'
require_relative
'import_spec_helper'
describe
Import
::
GoogleCodeController
do
describe
Import
::
GoogleCodeController
do
include
ImportSpecHelper
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:dump_file
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/GoogleCodeProjectHosting.json'
,
'application/json'
)
}
let
(
:dump_file
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/GoogleCodeProjectHosting.json'
,
'application/json'
)
}
...
@@ -21,13 +24,12 @@ describe Import::GoogleCodeController do
...
@@ -21,13 +24,12 @@ describe Import::GoogleCodeController do
describe
"GET status"
do
describe
"GET status"
do
before
do
before
do
@repo
=
OpenStruct
.
new
(
name:
'vim'
)
@repo
=
OpenStruct
.
new
(
name:
'vim'
)
controller
.
stub_chain
(
:client
,
:valid?
).
and_return
(
true
)
stub_client
(
valid?:
true
)
end
end
it
"assigns variables"
do
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'google_code'
,
creator_id:
user
.
id
)
@project
=
create
(
:project
,
import_type:
'google_code'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
stub_client
(
repos:
[
@repo
],
incompatible_repos:
[])
controller
.
stub_chain
(
:client
,
:incompatible_repos
).
and_return
([])
get
:status
get
:status
...
@@ -38,8 +40,7 @@ describe Import::GoogleCodeController do
...
@@ -38,8 +40,7 @@ describe Import::GoogleCodeController do
it
"does not show already added project"
do
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'google_code'
,
creator_id:
user
.
id
,
import_source:
'vim'
)
@project
=
create
(
:project
,
import_type:
'google_code'
,
creator_id:
user
.
id
,
import_source:
'vim'
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
stub_client
(
repos:
[
@repo
],
incompatible_repos:
[])
controller
.
stub_chain
(
:client
,
:incompatible_repos
).
and_return
([])
get
:status
get
:status
...
@@ -48,8 +49,7 @@ describe Import::GoogleCodeController do
...
@@ -48,8 +49,7 @@ describe Import::GoogleCodeController do
end
end
it
"does not show any invalid projects"
do
it
"does not show any invalid projects"
do
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([])
stub_client
(
repos:
[],
incompatible_repos:
[
@repo
])
controller
.
stub_chain
(
:client
,
:incompatible_repos
).
and_return
([
@repo
])
get
:status
get
:status
...
...
spec/controllers/import/import_spec_helper.rb
0 → 100644
View file @
dad88568
require
'ostruct'
# Helper methods for controller specs in the Import namespace
#
# Must be included manually.
module
ImportSpecHelper
# Stub `controller` to return a null object double with the provided messages
# when `client` is called
#
# Examples:
#
# stub_client(foo: %w(foo))
#
# controller.client.foo # => ["foo"]
# controller.client.bar.baz.foo # => ["foo"]
#
# Returns the client double
def
stub_client
(
messages
=
{})
client
=
double
(
'client'
,
messages
).
as_null_object
allow
(
controller
).
to
receive
(
:client
).
and_return
(
client
)
client
end
def
stub_omniauth_provider
(
name
)
provider
=
OpenStruct
.
new
(
name:
name
,
app_id:
'asd123'
,
app_secret:
'asd123'
)
Gitlab
.
config
.
omniauth
.
providers
<<
provider
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