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
0ed07587
Commit
0ed07587
authored
Apr 18, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use double instead of OpenStruct in the Issue/PR formatters specs
parent
3225f78f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
32 deletions
+34
-32
spec/lib/gitlab/github_import/issue_formatter_spec.rb
spec/lib/gitlab/github_import/issue_formatter_spec.rb
+13
-12
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
+21
-20
No files found.
spec/lib/gitlab/github_import/issue_formatter_spec.rb
View file @
0ed07587
...
...
@@ -2,13 +2,14 @@ require 'spec_helper'
describe
Gitlab
::
GithubImport
::
IssueFormatter
,
lib:
true
do
let!
(
:project
)
{
create
(
:project
,
namespace:
create
(
:namespace
,
path:
'octocat'
))
}
let
(
:octocat
)
{
OpenStruct
.
new
(
id:
123456
,
login:
'octocat'
)
}
let
(
:octocat
)
{
double
(
id:
123456
,
login:
'octocat'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:base_data
)
do
{
number:
1347
,
milestone:
nil
,
state:
'open'
,
title:
'Found a bug'
,
body:
"I'm having a problem with this."
,
...
...
@@ -26,7 +27,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
describe
'#attributes'
do
context
'when issue is open'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'open'
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'open'
))
}
it
'returns formatted attributes'
do
expected
=
{
...
...
@@ -48,7 +49,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
context
'when issue is closed'
do
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
it
'returns formatted attributes'
do
expected
=
{
...
...
@@ -69,7 +70,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
context
'when it is assigned to someone'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
assignee:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
assignee:
octocat
))
}
it
'returns nil as assignee_id when is not a GitLab user'
do
expect
(
issue
.
attributes
.
fetch
(
:assignee_id
)).
to
be_nil
...
...
@@ -83,8 +84,8 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
context
'when it has a milestone'
do
let
(
:milestone
)
{
OpenStruct
.
new
(
number:
45
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
milestone:
milestone
))
}
let
(
:milestone
)
{
double
(
number:
45
)
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
milestone:
milestone
))
}
it
'returns nil when milestone does not exist'
do
expect
(
issue
.
attributes
.
fetch
(
:milestone
)).
to
be_nil
...
...
@@ -98,7 +99,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
context
'when author is a GitLab user'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
user:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
user:
octocat
))
}
it
'returns project#creator_id as author_id when is not a GitLab user'
do
expect
(
issue
.
attributes
.
fetch
(
:author_id
)).
to
eq
project
.
creator_id
...
...
@@ -114,7 +115,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
describe
'#has_comments?'
do
context
'when number of comments is greater than zero'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
comments:
1
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
comments:
1
))
}
it
'returns true'
do
expect
(
issue
.
has_comments?
).
to
eq
true
...
...
@@ -122,7 +123,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
context
'when number of comments is equal to zero'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
comments:
0
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
comments:
0
))
}
it
'returns false'
do
expect
(
issue
.
has_comments?
).
to
eq
false
...
...
@@ -131,7 +132,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
describe
'#number'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
number:
1347
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
number:
1347
))
}
it
'returns pull request number'
do
expect
(
issue
.
number
).
to
eq
1347
...
...
@@ -140,7 +141,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
describe
'#valid?'
do
context
'when mention a pull request'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
pull_request:
OpenStruct
.
new
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
pull_request:
double
))
}
it
'returns false'
do
expect
(
issue
.
valid?
).
to
eq
false
...
...
@@ -148,7 +149,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
context
'when does not mention a pull request'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
pull_request:
nil
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
pull_request:
nil
))
}
it
'returns true'
do
expect
(
issue
.
valid?
).
to
eq
true
...
...
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
View file @
0ed07587
...
...
@@ -2,17 +2,18 @@ require 'spec_helper'
describe
Gitlab
::
GithubImport
::
PullRequestFormatter
,
lib:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
OpenStruct
.
new
(
id:
1
,
fork:
false
)
}
let
(
:repository
)
{
double
(
id:
1
,
fork:
false
)
}
let
(
:source_repo
)
{
repository
}
let
(
:source_branch
)
{
OpenStruct
.
new
(
ref:
'feature'
,
repo:
source_repo
)
}
let
(
:source_branch
)
{
double
(
ref:
'feature'
,
repo:
source_repo
)
}
let
(
:target_repo
)
{
repository
}
let
(
:target_branch
)
{
OpenStruct
.
new
(
ref:
'master'
,
repo:
target_repo
)
}
let
(
:octocat
)
{
OpenStruct
.
new
(
id:
123456
,
login:
'octocat'
)
}
let
(
:target_branch
)
{
double
(
ref:
'master'
,
repo:
target_repo
)
}
let
(
:octocat
)
{
double
(
id:
123456
,
login:
'octocat'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:base_data
)
do
{
number:
1347
,
milestone:
nil
,
state:
'open'
,
title:
'New feature'
,
body:
'Please pull these awesome changes'
,
...
...
@@ -31,7 +32,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
describe
'#attributes'
do
context
'when pull request is open'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'open'
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'open'
))
}
it
'returns formatted attributes'
do
expected
=
{
...
...
@@ -56,7 +57,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
context
'when pull request is closed'
do
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
it
'returns formatted attributes'
do
expected
=
{
...
...
@@ -81,7 +82,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
context
'when pull request is merged'
do
let
(
:merged_at
)
{
DateTime
.
strptime
(
'2011-01-28T13:01:12Z'
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'closed'
,
merged_at:
merged_at
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
merged_at:
merged_at
))
}
it
'returns formatted attributes'
do
expected
=
{
...
...
@@ -105,7 +106,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'when it is assigned to someone'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
assignee:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
assignee:
octocat
))
}
it
'returns nil as assignee_id when is not a GitLab user'
do
expect
(
pull_request
.
attributes
.
fetch
(
:assignee_id
)).
to
be_nil
...
...
@@ -119,7 +120,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'when author is a GitLab user'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
user:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
user:
octocat
))
}
it
'returns project#creator_id as author_id when is not a GitLab user'
do
expect
(
pull_request
.
attributes
.
fetch
(
:author_id
)).
to
eq
project
.
creator_id
...
...
@@ -133,8 +134,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'when it has a milestone'
do
let
(
:milestone
)
{
OpenStruct
.
new
(
number:
45
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
milestone:
milestone
))
}
let
(
:milestone
)
{
double
(
number:
45
)
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
milestone:
milestone
))
}
it
'returns nil when milestone does not exists'
do
expect
(
pull_request
.
attributes
.
fetch
(
:milestone
)).
to
be_nil
...
...
@@ -149,7 +150,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
describe
'#number'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
number:
1347
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
number:
1347
))
}
it
'returns pull request number'
do
expect
(
pull_request
.
number
).
to
eq
1347
...
...
@@ -157,11 +158,11 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
describe
'#valid?'
do
let
(
:invalid_branch
)
{
OpenStruct
.
new
(
ref:
'invalid-branch'
)
}
let
(
:invalid_branch
)
{
double
(
ref:
'invalid-branch'
).
as_null_object
}
context
'when source, and target repositories are the same'
do
context
'and source and target branches exists'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
head:
source_branch
,
base:
target_branch
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
source_branch
,
base:
target_branch
))
}
it
'returns true'
do
expect
(
pull_request
.
valid?
).
to
eq
true
...
...
@@ -169,7 +170,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'and source branch doesn not exists'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
head:
invalid_branch
,
base:
target_branch
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
invalid_branch
,
base:
target_branch
))
}
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
...
...
@@ -177,7 +178,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'and target branch doesn not exists'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
head:
source_branch
,
base:
invalid_branch
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
source_branch
,
base:
invalid_branch
))
}
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
...
...
@@ -186,8 +187,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'when source repo is a fork'
do
let
(
:source_repo
)
{
OpenStruct
.
new
(
id:
2
,
fork:
true
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
)
}
let
(
:source_repo
)
{
double
(
id:
2
,
fork:
true
)
}
let
(
:raw_data
)
{
double
(
base_data
)
}
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
...
...
@@ -195,8 +196,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
context
'when target repo is a fork'
do
let
(
:target_repo
)
{
OpenStruct
.
new
(
id:
2
,
fork:
true
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
)
}
let
(
:target_repo
)
{
double
(
id:
2
,
fork:
true
)
}
let
(
:raw_data
)
{
double
(
base_data
)
}
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
...
...
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