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
05965162
Commit
05965162
authored
Mar 25, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug tracking snippet shard name
parent
18fe0434
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
18 deletions
+48
-18
app/models/snippet.rb
app/models/snippet.rb
+4
-4
changelogs/unreleased/fj-212399-fix-bug-tracking-snippet-shard-name.yml
...eleased/fj-212399-fix-bug-tracking-snippet-shard-name.yml
+5
-0
lib/gitlab/import_export/snippet_repo_restorer.rb
lib/gitlab/import_export/snippet_repo_restorer.rb
+1
-1
spec/factories/snippets.rb
spec/factories/snippets.rb
+1
-1
spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
+12
-1
spec/models/snippet_repository_spec.rb
spec/models/snippet_repository_spec.rb
+1
-1
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+24
-10
No files found.
app/models/snippet.rb
View file @
05965162
...
...
@@ -296,12 +296,12 @@ class Snippet < ApplicationRecord
return
if
repository_exists?
&&
snippet_repository
repository
.
create_if_not_exists
track_snippet_repository
track_snippet_repository
(
repository
.
storage
)
end
def
track_snippet_repository
repository
=
snippet_repository
||
build_snippet_repository
repository
.
update!
(
shard_name:
repository_storage
,
disk_path:
disk_path
)
def
track_snippet_repository
(
shard
)
snippet_repo
=
snippet_repository
||
build_snippet_repository
snippet_repo
.
update!
(
shard_name:
shard
,
disk_path:
disk_path
)
end
def
can_cache_field?
(
field
)
...
...
changelogs/unreleased/fj-212399-fix-bug-tracking-snippet-shard-name.yml
0 → 100644
View file @
05965162
---
title
:
Fix bug tracking snippet shard name
merge_request
:
27979
author
:
type
:
fixed
lib/gitlab/import_export/snippet_repo_restorer.rb
View file @
05965162
...
...
@@ -30,7 +30,7 @@ module Gitlab
def
create_repository_from_bundle
repository
.
create_from_bundle
(
path_to_bundle
)
snippet
.
track_snippet_repository
snippet
.
track_snippet_repository
(
repository
.
storage
)
end
def
create_repository_from_db
...
...
spec/factories/snippets.rb
View file @
05965162
...
...
@@ -28,7 +28,7 @@ FactoryBot.define do
bare_repo:
TestEnv
.
factory_repo_path_bare
,
refs:
TestEnv
::
BRANCH_SHA
)
snippet
.
track_snippet_repository
snippet
.
track_snippet_repository
(
snippet
.
repository
.
storage
)
end
end
...
...
spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
View file @
05965162
...
...
@@ -55,9 +55,11 @@ describe Gitlab::ImportExport::SnippetRepoRestorer do
let
(
:snippet_bundle_path
)
{
File
.
join
(
bundle_path
,
"
#{
snippet_with_repo
.
hexdigest
}
.bundle"
)
}
let
(
:result
)
{
exporter
.
save
}
it
'creates the repository from the bundle'
do
before
do
expect
(
exporter
.
save
).
to
be_truthy
end
it
'creates the repository from the bundle'
do
expect
(
snippet
.
repository_exists?
).
to
be_falsey
expect
(
snippet
.
snippet_repository
).
to
be_nil
expect
(
snippet
.
repository
).
to
receive
(
:create_from_bundle
).
and_call_original
...
...
@@ -66,5 +68,14 @@ describe Gitlab::ImportExport::SnippetRepoRestorer do
expect
(
snippet
.
repository_exists?
).
to
be_truthy
expect
(
snippet
.
snippet_repository
).
not_to
be_nil
end
it
'sets same shard in snippet repository as in the repository storage'
do
expect
(
snippet
).
to
receive
(
:repository_storage
).
and_return
(
'picked'
)
expect
(
snippet
.
repository
).
to
receive
(
:create_from_bundle
)
restorer
.
restore
expect
(
snippet
.
snippet_repository
.
shard_name
).
to
eq
'picked'
end
end
end
spec/models/snippet_repository_spec.rb
View file @
05965162
...
...
@@ -16,7 +16,7 @@ describe SnippetRepository do
describe
'.find_snippet'
do
it
'finds snippet by disk path'
do
snippet
=
create
(
:snippet
,
author:
user
)
snippet
.
track_snippet_repository
snippet
.
track_snippet_repository
(
snippet
.
repository
.
storage
)
expect
(
described_class
.
find_snippet
(
snippet
.
disk_path
)).
to
eq
(
snippet
)
end
...
...
spec/models/snippet_spec.rb
View file @
05965162
...
...
@@ -567,18 +567,21 @@ describe Snippet do
describe
'#track_snippet_repository'
do
let
(
:snippet
)
{
create
(
:snippet
)
}
let
(
:shard_name
)
{
'foo'
}
subject
{
snippet
.
track_snippet_repository
(
shard_name
)
}
context
'when a snippet repository entry does not exist'
do
it
'creates a new entry'
do
expect
{
s
nippet
.
track_snippet_repository
}.
to
change
(
snippet
,
:snippet_repository
)
expect
{
s
ubject
}.
to
change
(
snippet
,
:snippet_repository
)
end
it
'tracks the snippet storage location'
do
s
nippet
.
track_snippet_repository
s
ubject
expect
(
snippet
.
snippet_repository
).
to
have_attributes
(
disk_path:
snippet
.
disk_path
,
shard_name:
s
nippet
.
repository_storag
e
shard_name:
s
hard_nam
e
)
end
end
...
...
@@ -586,21 +589,20 @@ describe Snippet do
context
'when a tracking entry exists'
do
let!
(
:snippet
)
{
create
(
:snippet
,
:repository
)
}
let
(
:snippet_repository
)
{
snippet
.
snippet_repository
}
let
!
(
:shard
)
{
create
(
:shard
,
name:
'foo'
)
}
let
(
:shard_name
)
{
'bar'
}
it
'does not create a new entry in the database'
do
expect
{
s
nippet
.
track_snippet_repository
}.
not_to
change
(
snippet
,
:snippet_repository
)
expect
{
s
ubject
}.
not_to
change
(
snippet
,
:snippet_repository
)
end
it
'updates the snippet storage location'
do
allow
(
snippet
).
to
receive
(
:disk_path
).
and_return
(
'fancy/new/path'
)
allow
(
snippet
).
to
receive
(
:repository_storage
).
and_return
(
'foo'
)
s
nippet
.
track_snippet_repository
s
ubject
expect
(
snippet
.
snippet_repository
).
to
have_attributes
(
disk_path:
'fancy/new/path'
,
shard_name:
'foo'
shard_name:
shard_name
)
end
end
...
...
@@ -609,19 +611,31 @@ describe Snippet do
describe
'#create_repository'
do
let
(
:snippet
)
{
create
(
:snippet
)
}
subject
{
snippet
.
create_repository
}
it
'creates the repository'
do
expect
(
snippet
.
repository
).
to
receive
(
:after_create
).
and_call_original
expect
(
s
nippet
.
create_repository
).
to
be_truthy
expect
(
s
ubject
).
to
be_truthy
expect
(
snippet
.
repository
.
exists?
).
to
be_truthy
end
it
'tracks snippet repository'
do
expect
do
s
nippet
.
create_repository
s
ubject
end
.
to
change
(
SnippetRepository
,
:count
).
by
(
1
)
end
it
'sets same shard in snippet repository as in the repository storage'
do
expect
(
snippet
).
to
receive
(
:repository_storage
).
and_return
(
'picked'
)
expect
(
snippet
).
to
receive
(
:repository_exists?
).
and_return
(
false
)
expect
(
snippet
.
repository
).
to
receive
(
:create_if_not_exists
)
subject
expect
(
snippet
.
snippet_repository
.
shard_name
).
to
eq
'picked'
end
context
'when repository exists'
do
let!
(
:snippet
)
{
create
(
:snippet
,
:repository
)
}
...
...
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