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
4cc6c539
Commit
4cc6c539
authored
Dec 23, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Override to specify that we're overriding
parent
bf6149a5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
8 deletions
+121
-8
ee/app/controllers/ee/projects/git_http_controller.rb
ee/app/controllers/ee/projects/git_http_controller.rb
+5
-6
lib/gitlab/utils/override.rb
lib/gitlab/utils/override.rb
+31
-0
lib/tasks/dev.rake
lib/tasks/dev.rake
+5
-0
scripts/static-analysis
scripts/static-analysis
+3
-2
spec/lib/gitlab/utils/override_spec.rb
spec/lib/gitlab/utils/override_spec.rb
+77
-0
No files found.
ee/app/controllers/ee/projects/git_http_controller.rb
View file @
4cc6c539
module
EE
module
Projects
module
GitHttpController
def
render_ok
raise
NotImplementedError
.
new
unless
defined?
(
super
)
extend
::
Gitlab
::
Utils
::
Override
override
:render_ok
def
render_ok
set_workhorse_internal_api_content_type
render
json:
::
Gitlab
::
Workhorse
.
git_http_ok
(
repository
,
wiki?
,
user
,
action_name
,
show_all_refs:
geo_request?
)
end
...
...
@@ -18,17 +19,15 @@ module EE
authentication_result
.
geo?
(
project
)
end
override
:access_actor
def
access_actor
raise
NotImplementedError
.
new
unless
defined?
(
super
)
return
:geo
if
geo?
super
end
override
:authenticate_user
def
authenticate_user
raise
NotImplementedError
.
new
unless
defined?
(
super
)
return
super
unless
geo_request?
payload
=
::
Gitlab
::
Geo
::
JwtRequestDecoder
.
new
(
request
.
headers
[
'Authorization'
]).
decode
...
...
lib/gitlab/utils/override.rb
0 → 100644
View file @
4cc6c539
module
Gitlab
module
Utils
module
Override
# Instead of writing patterns like this:
#
# def f
# raise NotImplementedError unless defined?(super)
#
# true
# end
#
# We could write it like:
#
# include ::Gitlab::Utils::Override
#
# override :f
# def f
# true
# end
#
# This would make sure we're overriding something. See:
# https://gitlab.com/gitlab-org/gitlab-ee/issues/1819
def
override
(
method_name
)
return
unless
ENV
[
'STATIC_VERIFICATION'
]
return
if
instance_methods
.
include?
(
method_name
)
raise
NotImplementedError
.
new
(
"Method
#{
method_name
}
doesn't exist"
)
end
end
end
end
lib/tasks/dev.rake
View file @
4cc6c539
...
...
@@ -7,4 +7,9 @@ namespace :dev do
Rake
::
Task
[
"gitlab:setup"
].
invoke
Rake
::
Task
[
"gitlab:shell:setup"
].
invoke
end
desc
"GitLab | Eager load application"
task
load: :environment
do
Rails
.
application
.
eager_load!
end
end
scripts/static-analysis
View file @
4cc6c539
...
...
@@ -12,9 +12,10 @@ tasks = [
%w[bundle exec license_finder]
,
%w[yarn run eslint]
,
%w[bundle exec rubocop --parallel]
,
%w[scripts/lint-conflicts.sh]
,
%w[bundle exec rake gettext:lint]
,
%w[scripts/lint-changelog-yaml]
%w[env STATIC_VERIFICATION=true bundle exec rake dev:load]
,
%w[scripts/lint-changelog-yaml]
,
%w[scripts/lint-conflicts.sh]
]
failed_tasks
=
tasks
.
reduce
({})
do
|
failures
,
task
|
...
...
spec/lib/gitlab/utils/override_spec.rb
0 → 100644
View file @
4cc6c539
require
'spec_helper'
describe
Gitlab
::
Utils
::
Override
do
let
(
:base
)
{
Struct
.
new
(
:good
)
}
let
(
:derived
)
do
Class
.
new
(
base
)
do
extend
Gitlab
::
Utils
::
Override
# rubocop:disable RSpec/DescribedClass
end
end
shared_examples
'good derivation'
do
subject
do
derived
.
module_eval
do
override
:good
def
good
super
.
succ
end
end
derived
end
end
shared_examples
'bad derivation'
do
subject
do
derived
.
module_eval
do
override
:bad
def
bad
true
end
end
derived
end
end
describe
'#override'
do
context
'when STATIC_VERIFICATION is set'
do
before
do
stub_env
(
'STATIC_VERIFICATION'
,
'true'
)
end
it_behaves_like
'good derivation'
do
it
'checks ok for overriding method'
do
result
=
subject
.
new
(
0
).
good
expect
(
result
).
to
eq
(
1
)
end
end
it_behaves_like
'bad derivation'
do
it
'raises NotImplementedError when it is not overriding anything'
do
expect
{
subject
}.
to
raise_error
(
NotImplementedError
)
end
end
end
context
'when STATIC_VERIFICATION is not set'
do
it_behaves_like
'good derivation'
do
it
'does not complain when it is overriding anything'
do
result
=
subject
.
new
(
0
).
good
expect
(
result
).
to
eq
(
1
)
end
end
it_behaves_like
'bad derivation'
do
it
'does not complain when it is not overriding anything'
do
result
=
subject
.
new
(
0
).
bad
expect
(
result
).
to
eq
(
true
)
end
end
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