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
Léo-Paul Géneau
gitlab-ce
Commits
56296f1e
Commit
56296f1e
authored
Dec 15, 2018
by
Jasper Maes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove rails4 specific code
parent
8b460204
Changes
38
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
59 additions
and
280 deletions
+59
-280
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-4
app/controllers/concerns/invalid_utf8_error_handler.rb
app/controllers/concerns/invalid_utf8_error_handler.rb
+0
-27
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-11
app/models/ci/runner.rb
app/models/ci/runner.rb
+1
-2
app/models/concerns/enum_with_nil.rb
app/models/concerns/enum_with_nil.rb
+1
-2
app/models/concerns/redis_cacheable.rb
app/models/concerns/redis_cacheable.rb
+1
-5
app/models/event.rb
app/models/event.rb
+0
-13
app/models/service.rb
app/models/service.rb
+1
-5
changelogs/unreleased/remove-rails4-specific-code.yml
changelogs/unreleased/remove-rails4-specific-code.yml
+5
-0
config/application.rb
config/application.rb
+0
-6
db/migrate/20160226114608_add_trigram_indexes_for_searching.rb
...grate/20160226114608_add_trigram_indexes_for_searching.rb
+1
-6
db/migrate/20161207231620_fixup_environment_name_uniqueness.rb
...grate/20161207231620_fixup_environment_name_uniqueness.rb
+1
-2
db/migrate/20161207231626_add_environment_slug.rb
db/migrate/20161207231626_add_environment_slug.rb
+1
-2
db/post_migrate/20161109150329_fix_project_records_with_invalid_visibility.rb
...1109150329_fix_project_records_with_invalid_visibility.rb
+1
-2
db/post_migrate/20170324160416_migrate_user_activities_to_users_last_activity_on.rb
...0416_migrate_user_activities_to_users_last_activity_on.rb
+1
-2
lib/api/helpers.rb
lib/api/helpers.rb
+1
-1
lib/declarative_policy.rb
lib/declarative_policy.rb
+4
-8
lib/gitlab/database.rb
lib/gitlab/database.rb
+1
-5
lib/gitlab/database/arel_methods.rb
lib/gitlab/database/arel_methods.rb
+0
-20
lib/gitlab/database/median.rb
lib/gitlab/database/median.rb
+3
-14
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+1
-3
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
...atabase/rename_reserved_paths_migration/v1/rename_base.rb
+1
-3
lib/gitlab/database/sha_attribute.rb
lib/gitlab/database/sha_attribute.rb
+4
-33
lib/gitlab/database/subquery.rb
lib/gitlab/database/subquery.rb
+5
-9
lib/gitlab/gpg.rb
lib/gitlab/gpg.rb
+1
-7
lib/gitlab/middleware/correlation_id.rb
lib/gitlab/middleware/correlation_id.rb
+1
-5
lib/mysql_zero_date.rb
lib/mysql_zero_date.rb
+1
-1
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+2
-18
spec/controllers/boards/lists_controller_spec.rb
spec/controllers/boards/lists_controller_spec.rb
+1
-5
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+1
-5
spec/controllers/projects/pipeline_schedules_controller_spec.rb
...ontrollers/projects/pipeline_schedules_controller_spec.rb
+5
-13
spec/controllers/uploads_controller_spec.rb
spec/controllers/uploads_controller_spec.rb
+1
-5
spec/helpers/storage_helper_spec.rb
spec/helpers/storage_helper_spec.rb
+1
-5
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+2
-7
spec/lib/gitlab/sql/glob_spec.rb
spec/lib/gitlab/sql/glob_spec.rb
+1
-2
spec/models/notification_setting_spec.rb
spec/models/notification_setting_spec.rb
+1
-6
spec/requests/api/internal_spec.rb
spec/requests/api/internal_spec.rb
+4
-11
spec/support/helpers/test_request_helpers.rb
spec/support/helpers/test_request_helpers.rb
+1
-5
No files found.
app/controllers/application_controller.rb
View file @
56296f1e
...
@@ -12,9 +12,6 @@ class ApplicationController < ActionController::Base
...
@@ -12,9 +12,6 @@ class ApplicationController < ActionController::Base
include
EnforcesTwoFactorAuthentication
include
EnforcesTwoFactorAuthentication
include
WithPerformanceBar
include
WithPerformanceBar
include
SessionlessAuthentication
include
SessionlessAuthentication
# this can be removed after switching to rails 5
# https://gitlab.com/gitlab-org/gitlab-ce/issues/51908
include
InvalidUTF8ErrorHandler
unless
Gitlab
.
rails5?
before_action
:authenticate_user!
before_action
:authenticate_user!
before_action
:enforce_terms!
,
if: :should_enforce_terms?
before_action
:enforce_terms!
,
if: :should_enforce_terms?
...
@@ -157,7 +154,7 @@ class ApplicationController < ActionController::Base
...
@@ -157,7 +154,7 @@ class ApplicationController < ActionController::Base
def
log_exception
(
exception
)
def
log_exception
(
exception
)
Gitlab
::
Sentry
.
track_acceptable_exception
(
exception
)
Gitlab
::
Sentry
.
track_acceptable_exception
(
exception
)
backtrace_cleaner
=
Gitlab
.
rails5?
?
request
.
env
[
"action_dispatch.backtrace_cleaner"
]
:
env
backtrace_cleaner
=
request
.
env
[
"action_dispatch.backtrace_cleaner"
]
application_trace
=
ActionDispatch
::
ExceptionWrapper
.
new
(
backtrace_cleaner
,
exception
).
application_trace
application_trace
=
ActionDispatch
::
ExceptionWrapper
.
new
(
backtrace_cleaner
,
exception
).
application_trace
application_trace
.
map!
{
|
t
|
"
#{
t
}
\n
"
}
application_trace
.
map!
{
|
t
|
"
#{
t
}
\n
"
}
logger
.
error
"
\n
#{
exception
.
class
.
name
}
(
#{
exception
.
message
}
):
\n
#{
application_trace
.
join
}
"
logger
.
error
"
\n
#{
exception
.
class
.
name
}
(
#{
exception
.
message
}
):
\n
#{
application_trace
.
join
}
"
...
...
app/controllers/concerns/invalid_utf8_error_handler.rb
deleted
100644 → 0
View file @
8b460204
# frozen_string_literal: true
module
InvalidUTF8ErrorHandler
extend
ActiveSupport
::
Concern
included
do
rescue_from
ArgumentError
,
with: :handle_invalid_utf8
end
private
def
handle_invalid_utf8
(
error
)
if
error
.
message
==
"invalid byte sequence in UTF-8"
render_412
else
raise
(
error
)
end
end
def
render_412
respond_to
do
|
format
|
format
.
html
{
render
"errors/precondition_failed"
,
layout:
"errors"
,
status:
412
}
format
.
js
{
render
json:
{
error:
'Invalid UTF-8'
},
status: :precondition_failed
,
content_type:
'application/json'
}
format
.
any
{
head
:precondition_failed
}
end
end
end
app/models/ci/pipeline.rb
View file @
56296f1e
...
@@ -56,11 +56,7 @@ module Ci
...
@@ -56,11 +56,7 @@ module Ci
validates
:tag
,
inclusion:
{
in:
[
false
],
if: :merge_request?
}
validates
:tag
,
inclusion:
{
in:
[
false
],
if: :merge_request?
}
validates
:status
,
presence:
{
unless: :importing?
}
validates
:status
,
presence:
{
unless: :importing?
}
validate
:valid_commit_sha
,
unless: :importing?
validate
:valid_commit_sha
,
unless: :importing?
validates
:source
,
exclusion:
{
in:
%w(unknown)
,
unless: :importing?
},
on: :create
# Replace validator below with
# `validates :source, presence: { unless: :importing? }, on: :create`
# when removing Gitlab.rails5? code.
validate
:valid_source
,
unless: :importing?
,
on: :create
after_create
:keep_around_commits
,
unless: :importing?
after_create
:keep_around_commits
,
unless: :importing?
...
@@ -738,11 +734,5 @@ module Ci
...
@@ -738,11 +734,5 @@ module Ci
project
.
repository
.
keep_around
(
self
.
sha
,
self
.
before_sha
)
project
.
repository
.
keep_around
(
self
.
sha
,
self
.
before_sha
)
end
end
def
valid_source
if
source
.
nil?
||
source
==
"unknown"
errors
.
add
(
:source
,
"invalid source"
)
end
end
end
end
end
end
app/models/ci/runner.rb
View file @
56296f1e
...
@@ -58,8 +58,7 @@ module Ci
...
@@ -58,8 +58,7 @@ module Ci
# BACKWARD COMPATIBILITY: There are needed to maintain compatibility with `AVAILABLE_SCOPES` used by `lib/api/runners.rb`
# BACKWARD COMPATIBILITY: There are needed to maintain compatibility with `AVAILABLE_SCOPES` used by `lib/api/runners.rb`
scope
:deprecated_shared
,
->
{
instance_type
}
scope
:deprecated_shared
,
->
{
instance_type
}
# this should get replaced with `project_type.or(group_type)` once using Rails5
scope
:deprecated_specific
,
->
{
project_type
.
or
(
group_type
)
}
scope
:deprecated_specific
,
->
{
where
(
runner_type:
[
runner_types
[
:project_type
],
runner_types
[
:group_type
]])
}
scope
:belonging_to_project
,
->
(
project_id
)
{
scope
:belonging_to_project
,
->
(
project_id
)
{
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
...
...
app/models/concerns/enum_with_nil.rb
View file @
56296f1e
...
@@ -16,7 +16,7 @@ module EnumWithNil
...
@@ -16,7 +16,7 @@ module EnumWithNil
# E.g. for enum_with_nil failure_reason: { unknown_failure: nil }
# E.g. for enum_with_nil failure_reason: { unknown_failure: nil }
# this overrides auto-generated method `unknown_failure?`
# this overrides auto-generated method `unknown_failure?`
define_method
(
"
#{
key_with_nil
}
?"
)
do
define_method
(
"
#{
key_with_nil
}
?"
)
do
Gitlab
.
rails5?
?
self
[
name
].
nil?
:
super
()
self
[
name
].
nil?
end
end
# E.g. for enum_with_nil failure_reason: { unknown_failure: nil }
# E.g. for enum_with_nil failure_reason: { unknown_failure: nil }
...
@@ -24,7 +24,6 @@ module EnumWithNil
...
@@ -24,7 +24,6 @@ module EnumWithNil
define_method
(
name
)
do
define_method
(
name
)
do
orig
=
super
()
orig
=
super
()
return
orig
unless
Gitlab
.
rails5?
return
orig
unless
orig
.
nil?
return
orig
unless
orig
.
nil?
self
.
class
.
public_send
(
name
.
to_s
.
pluralize
).
key
(
nil
)
# rubocop:disable GitlabSecurity/PublicSend
self
.
class
.
public_send
(
name
.
to_s
.
pluralize
).
key
(
nil
)
# rubocop:disable GitlabSecurity/PublicSend
...
...
app/models/concerns/redis_cacheable.rb
View file @
56296f1e
...
@@ -49,10 +49,6 @@ module RedisCacheable
...
@@ -49,10 +49,6 @@ module RedisCacheable
end
end
def
cast_value_from_cache
(
attribute
,
value
)
def
cast_value_from_cache
(
attribute
,
value
)
if
Gitlab
.
rails5?
self
.
class
.
type_for_attribute
(
attribute
.
to_s
).
cast
(
value
)
self
.
class
.
type_for_attribute
(
attribute
.
to_s
).
cast
(
value
)
else
self
.
class
.
column_for_attribute
(
attribute
).
type_cast_from_database
(
value
)
end
end
end
end
end
app/models/event.rb
View file @
56296f1e
...
@@ -114,19 +114,6 @@ class Event < ActiveRecord::Base
...
@@ -114,19 +114,6 @@ class Event < ActiveRecord::Base
end
end
end
end
# Remove this method when removing Gitlab.rails5? code.
def
subclass_from_attributes
(
attrs
)
return
super
if
Gitlab
.
rails5?
# Without this Rails will keep calling this method on the returned class,
# resulting in an infinite loop.
return
unless
self
==
Event
action
=
attrs
.
with_indifferent_access
[
inheritance_column
].
to_i
PushEvent
if
action
==
PUSHED
end
# Update Gitlab::ContributionsCalendar#activity_dates if this changes
# Update Gitlab::ContributionsCalendar#activity_dates if this changes
def
contributions
def
contributions
where
(
"action = ? OR (target_type IN (?) AND action IN (?)) OR (target_type = ? AND action = ?)"
,
where
(
"action = ? OR (target_type IN (?) AND action IN (?)) OR (target_type = ? AND action = ?)"
,
...
...
app/models/service.rb
View file @
56296f1e
...
@@ -210,11 +210,7 @@ class Service < ActiveRecord::Base
...
@@ -210,11 +210,7 @@ class Service < ActiveRecord::Base
class_eval
%{
class_eval
%{
def #{arg}?
def #{arg}?
# '!!' is used because nil or empty string is converted to nil
# '!!' is used because nil or empty string is converted to nil
if Gitlab.rails5?
!!ActiveRecord::Type::Boolean.new.cast(#{arg})
!!ActiveRecord::Type::Boolean.new.cast(#{arg})
else
!!ActiveRecord::Type::Boolean.new.type_cast_from_database(#{arg})
end
end
end
}
}
end
end
...
...
changelogs/unreleased/remove-rails4-specific-code.yml
0 → 100644
View file @
56296f1e
---
title
:
Remove rails4 specific code
merge_request
:
23847
author
:
Jasper Maes
type
:
other
config/application.rb
View file @
56296f1e
...
@@ -5,12 +5,6 @@ require 'rails/all'
...
@@ -5,12 +5,6 @@ require 'rails/all'
Bundler
.
require
(
:default
,
Rails
.
env
)
Bundler
.
require
(
:default
,
Rails
.
env
)
module
Gitlab
module
Gitlab
# This method is used for smooth upgrading from the current Rails 4.x to Rails 5.0.
# https://gitlab.com/gitlab-org/gitlab-ce/issues/14286
def
self
.
rails5?
true
end
class
Application
<
Rails
::
Application
class
Application
<
Rails
::
Application
require_dependency
Rails
.
root
.
join
(
'lib/gitlab/redis/wrapper'
)
require_dependency
Rails
.
root
.
join
(
'lib/gitlab/redis/wrapper'
)
require_dependency
Rails
.
root
.
join
(
'lib/gitlab/redis/cache'
)
require_dependency
Rails
.
root
.
join
(
'lib/gitlab/redis/cache'
)
...
...
db/migrate/20160226114608_add_trigram_indexes_for_searching.rb
View file @
56296f1e
...
@@ -37,12 +37,7 @@ class AddTrigramIndexesForSearching < ActiveRecord::Migration[4.2]
...
@@ -37,12 +37,7 @@ class AddTrigramIndexesForSearching < ActiveRecord::Migration[4.2]
res
=
execute
(
"SELECT true AS enabled FROM pg_available_extensions WHERE name = 'pg_trgm' AND installed_version IS NOT NULL;"
)
res
=
execute
(
"SELECT true AS enabled FROM pg_available_extensions WHERE name = 'pg_trgm' AND installed_version IS NOT NULL;"
)
row
=
res
.
first
row
=
res
.
first
check
=
if
Gitlab
.
rails5?
row
&&
row
[
'enabled'
]
==
true
true
else
't'
end
row
&&
row
[
'enabled'
]
==
check
?
true
:
false
end
end
def
create_trigrams_extension
def
create_trigrams_extension
...
...
db/migrate/20161207231620_fixup_environment_name_uniqueness.rb
View file @
56296f1e
class
FixupEnvironmentNameUniqueness
<
ActiveRecord
::
Migration
[
4.2
]
class
FixupEnvironmentNameUniqueness
<
ActiveRecord
::
Migration
[
4.2
]
include
Gitlab
::
Database
::
ArelMethods
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
true
DOWNTIME
=
true
...
@@ -42,7 +41,7 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration[4.2]
...
@@ -42,7 +41,7 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration[4.2]
conflicts
.
each
do
|
id
,
name
|
conflicts
.
each
do
|
id
,
name
|
update_sql
=
update_sql
=
arel_update_manager
Arel
::
UpdateManager
.
new
.
table
(
environments
)
.
table
(
environments
)
.
set
(
environments
[
:name
]
=>
name
+
"-"
+
id
.
to_s
)
.
set
(
environments
[
:name
]
=>
name
+
"-"
+
id
.
to_s
)
.
where
(
environments
[
:id
].
eq
(
id
))
.
where
(
environments
[
:id
].
eq
(
id
))
...
...
db/migrate/20161207231626_add_environment_slug.rb
View file @
56296f1e
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
# for more information on how to write migrations for GitLab.
# for more information on how to write migrations for GitLab.
class
AddEnvironmentSlug
<
ActiveRecord
::
Migration
[
4.2
]
class
AddEnvironmentSlug
<
ActiveRecord
::
Migration
[
4.2
]
include
Gitlab
::
Database
::
ArelMethods
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
true
DOWNTIME
=
true
...
@@ -20,7 +19,7 @@ class AddEnvironmentSlug < ActiveRecord::Migration[4.2]
...
@@ -20,7 +19,7 @@ class AddEnvironmentSlug < ActiveRecord::Migration[4.2]
finder
=
environments
.
project
(
:id
,
:name
)
finder
=
environments
.
project
(
:id
,
:name
)
connection
.
exec_query
(
finder
.
to_sql
).
rows
.
each
do
|
id
,
name
|
connection
.
exec_query
(
finder
.
to_sql
).
rows
.
each
do
|
id
,
name
|
updater
=
arel_update_manager
updater
=
Arel
::
UpdateManager
.
new
.
table
(
environments
)
.
table
(
environments
)
.
set
(
environments
[
:slug
]
=>
generate_slug
(
name
))
.
set
(
environments
[
:slug
]
=>
generate_slug
(
name
))
.
where
(
environments
[
:id
].
eq
(
id
))
.
where
(
environments
[
:id
].
eq
(
id
))
...
...
db/post_migrate/20161109150329_fix_project_records_with_invalid_visibility.rb
View file @
56296f1e
class
FixProjectRecordsWithInvalidVisibility
<
ActiveRecord
::
Migration
[
4.2
]
class
FixProjectRecordsWithInvalidVisibility
<
ActiveRecord
::
Migration
[
4.2
]
include
Gitlab
::
Database
::
ArelMethods
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
BATCH_SIZE
=
500
BATCH_SIZE
=
500
...
@@ -34,7 +33,7 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration[4.2]
...
@@ -34,7 +33,7 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration[4.2]
end
end
updates
.
each
do
|
visibility_level
,
project_ids
|
updates
.
each
do
|
visibility_level
,
project_ids
|
updater
=
arel_update_manager
updater
=
Arel
::
UpdateManager
.
new
.
table
(
projects
)
.
table
(
projects
)
.
set
(
projects
[
:visibility_level
]
=>
visibility_level
)
.
set
(
projects
[
:visibility_level
]
=>
visibility_level
)
.
where
(
projects
[
:id
].
in
(
project_ids
))
.
where
(
projects
[
:id
].
in
(
project_ids
))
...
...
db/post_migrate/20170324160416_migrate_user_activities_to_users_last_activity_on.rb
View file @
56296f1e
# rubocop:disable Migration/UpdateLargeTable
# rubocop:disable Migration/UpdateLargeTable
class
MigrateUserActivitiesToUsersLastActivityOn
<
ActiveRecord
::
Migration
[
4.2
]
class
MigrateUserActivitiesToUsersLastActivityOn
<
ActiveRecord
::
Migration
[
4.2
]
include
Gitlab
::
Database
::
ArelMethods
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
disable_ddl_transaction!
...
@@ -40,7 +39,7 @@ class MigrateUserActivitiesToUsersLastActivityOn < ActiveRecord::Migration[4.2]
...
@@ -40,7 +39,7 @@ class MigrateUserActivitiesToUsersLastActivityOn < ActiveRecord::Migration[4.2]
activities
=
activities
(
day
.
at_beginning_of_day
,
day
.
at_end_of_day
,
page:
page
)
activities
=
activities
(
day
.
at_beginning_of_day
,
day
.
at_end_of_day
,
page:
page
)
update_sql
=
update_sql
=
arel_update_manager
Arel
::
UpdateManager
.
new
.
table
(
users_table
)
.
table
(
users_table
)
.
set
(
users_table
[
:last_activity_on
]
=>
day
.
to_date
)
.
set
(
users_table
[
:last_activity_on
]
=>
day
.
to_date
)
.
where
(
users_table
[
:username
].
in
(
activities
.
map
(
&
:first
)))
.
where
(
users_table
[
:username
].
in
(
activities
.
map
(
&
:first
)))
...
...
lib/api/helpers.rb
View file @
56296f1e
...
@@ -291,7 +291,7 @@ module API
...
@@ -291,7 +291,7 @@ module API
end
end
end
end
permitted_attrs
=
ActionController
::
Parameters
.
new
(
attrs
).
permit!
permitted_attrs
=
ActionController
::
Parameters
.
new
(
attrs
).
permit!
Gitlab
.
rails5?
?
permitted_attrs
.
to_h
:
permitted_attrs
permitted_attrs
.
to_h
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
...
...
lib/declarative_policy.rb
View file @
56296f1e
...
@@ -22,14 +22,10 @@ module DeclarativePolicy
...
@@ -22,14 +22,10 @@ module DeclarativePolicy
key
=
Cache
.
policy_key
(
user
,
subject
)
key
=
Cache
.
policy_key
(
user
,
subject
)
cache
[
key
]
||=
cache
[
key
]
||=
if
Gitlab
.
rails5?
# to avoid deadlocks in multi-threaded environment when
# to avoid deadlocks in multi-threaded environment when
# autoloading is enabled, we allow concurrent loads,
# autoloading is enabled, we allow concurrent loads,
# https://gitlab.com/gitlab-org/gitlab-ce/issues/48263
# https://gitlab.com/gitlab-org/gitlab-ce/issues/48263
ActiveSupport
::
Dependencies
.
interlock
.
permit_concurrent_loads
do
ActiveSupport
::
Dependencies
.
interlock
.
permit_concurrent_loads
do
class_for
(
subject
).
new
(
user
,
subject
,
opts
)
end
else
class_for
(
subject
).
new
(
user
,
subject
,
opts
)
class_for
(
subject
).
new
(
user
,
subject
,
opts
)
end
end
end
end
...
...
lib/gitlab/database.rb
View file @
56296f1e
...
@@ -232,11 +232,7 @@ module Gitlab
...
@@ -232,11 +232,7 @@ module Gitlab
end
end
def
self
.
cached_table_exists?
(
table_name
)
def
self
.
cached_table_exists?
(
table_name
)
if
Gitlab
.
rails5?
connection
.
schema_cache
.
data_source_exists?
(
table_name
)
connection
.
schema_cache
.
data_source_exists?
(
table_name
)
else
connection
.
schema_cache
.
table_exists?
(
table_name
)
end
end
end
private_class_method
:connection
private_class_method
:connection
...
...
lib/gitlab/database/arel_methods.rb
deleted
100644 → 0
View file @
8b460204
# frozen_string_literal: true
module
Gitlab
module
Database
module
ArelMethods
private
# In Arel 7.0.0 (Arel 7.1.4 is used in Rails 5.0) the `engine` parameter of `Arel::UpdateManager#initializer`
# was removed.
# Remove this file and inline this method when removing rails5? code.
def
arel_update_manager
if
Gitlab
.
rails5?
Arel
::
UpdateManager
.
new
else
Arel
::
UpdateManager
.
new
(
ActiveRecord
::
Base
)
end
end
end
end
end
lib/gitlab/database/median.rb
View file @
56296f1e
...
@@ -35,13 +35,7 @@ module Gitlab
...
@@ -35,13 +35,7 @@ module Gitlab
end
end
def
mysql_median_datetime_sql
(
arel_table
,
query_so_far
,
column_sym
)
def
mysql_median_datetime_sql
(
arel_table
,
query_so_far
,
column_sym
)
arel_from
=
if
Gitlab
.
rails5?
query
=
arel_table
.
from
arel_table
.
from
else
arel_table
end
query
=
arel_from
.
from
(
arel_table
.
project
(
Arel
.
sql
(
'*'
)).
order
(
arel_table
[
column_sym
]).
as
(
arel_table
.
table_name
))
.
from
(
arel_table
.
project
(
Arel
.
sql
(
'*'
)).
order
(
arel_table
[
column_sym
]).
as
(
arel_table
.
table_name
))
.
project
(
average
([
arel_table
[
column_sym
]],
'median'
))
.
project
(
average
([
arel_table
[
column_sym
]],
'median'
))
.
where
(
.
where
(
...
@@ -151,13 +145,8 @@ module Gitlab
...
@@ -151,13 +145,8 @@ module Gitlab
.
order
(
arel_table
[
column_sym
])
.
order
(
arel_table
[
column_sym
])
).
as
(
'row_id'
)
).
as
(
'row_id'
)
arel_from
=
if
Gitlab
.
rails5?
count
=
arel_table
.
from
.
from
(
arel_table
.
alias
)
arel_table
.
from
.
from
(
arel_table
.
alias
)
.
project
(
'COUNT(*)'
)
else
arel_table
.
from
(
arel_table
.
alias
)
end
count
=
arel_from
.
project
(
'COUNT(*)'
)
.
where
(
arel_table
[
partition_column
].
eq
(
arel_table
.
alias
[
partition_column
]))
.
where
(
arel_table
[
partition_column
].
eq
(
arel_table
.
alias
[
partition_column
]))
.
as
(
'ct'
)
.
as
(
'ct'
)
...
...
lib/gitlab/database/migration_helpers.rb
View file @
56296f1e
...
@@ -3,8 +3,6 @@
...
@@ -3,8 +3,6 @@
module
Gitlab
module
Gitlab
module
Database
module
Database
module
MigrationHelpers
module
MigrationHelpers
include
Gitlab
::
Database
::
ArelMethods
BACKGROUND_MIGRATION_BATCH_SIZE
=
1000
# Number of rows to process per job
BACKGROUND_MIGRATION_BATCH_SIZE
=
1000
# Number of rows to process per job
BACKGROUND_MIGRATION_JOB_BUFFER_SIZE
=
1000
# Number of jobs to bulk queue at a time
BACKGROUND_MIGRATION_JOB_BUFFER_SIZE
=
1000
# Number of jobs to bulk queue at a time
...
@@ -361,7 +359,7 @@ module Gitlab
...
@@ -361,7 +359,7 @@ module Gitlab
stop_arel
=
yield
table
,
stop_arel
if
block_given?
stop_arel
=
yield
table
,
stop_arel
if
block_given?
stop_row
=
exec_query
(
stop_arel
.
to_sql
).
to_hash
.
first
stop_row
=
exec_query
(
stop_arel
.
to_sql
).
to_hash
.
first
update_arel
=
arel_update_manager
update_arel
=
Arel
::
UpdateManager
.
new
.
table
(
table
)
.
table
(
table
)
.
set
([[
table
[
column
],
value
]])
.
set
([[
table
[
column
],
value
]])
.
where
(
table
[
:id
].
gteq
(
start_id
))
.
where
(
table
[
:id
].
gteq
(
start_id
))
...
...
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
View file @
56296f1e
...
@@ -5,8 +5,6 @@ module Gitlab
...
@@ -5,8 +5,6 @@ module Gitlab
module
RenameReservedPathsMigration
module
RenameReservedPathsMigration
module
V1
module
V1
class
RenameBase
class
RenameBase
include
Gitlab
::
Database
::
ArelMethods
attr_reader
:paths
,
:migration
attr_reader
:paths
,
:migration
delegate
:update_column_in_batches
,
delegate
:update_column_in_batches
,
...
@@ -66,7 +64,7 @@ module Gitlab
...
@@ -66,7 +64,7 @@ module Gitlab
old_full_path
,
old_full_path
,
new_full_path
)
new_full_path
)
update
=
arel_update_manager
update
=
Arel
::
UpdateManager
.
new
.
table
(
routes
)
.
table
(
routes
)
.
set
([[
routes
[
:path
],
replace_statement
]])
.
set
([[
routes
[
:path
],
replace_statement
]])
.
where
(
Arel
::
Nodes
::
SqlLiteral
.
new
(
filter
))
.
where
(
Arel
::
Nodes
::
SqlLiteral
.
new
(
filter
))
...
...
lib/gitlab/database/sha_attribute.rb
View file @
56296f1e
...
@@ -8,14 +8,7 @@ module Gitlab
...
@@ -8,14 +8,7 @@ module Gitlab
# behaviour from the default Binary type.
# behaviour from the default Binary type.
ActiveRecord
::
ConnectionAdapters
::
PostgreSQL
::
OID
::
Bytea
ActiveRecord
::
ConnectionAdapters
::
PostgreSQL
::
OID
::
Bytea
else
else
# In Rails 5.0 `Type` has been moved from `ActiveRecord` to `ActiveModel`
ActiveModel
::
Type
::
Binary
# https://github.com/rails/rails/commit/9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6#diff-f8ba7983a51d687976e115adcd95822b
# Remove this method and leave just `ActiveModel::Type::Binary` when removing Gitlab.rails5? code.
if
Gitlab
.
rails5?
ActiveModel
::
Type
::
Binary
else
ActiveRecord
::
Type
::
Binary
end
end
end
# Class for casting binary data to hexadecimal SHA1 hashes (and vice-versa).
# Class for casting binary data to hexadecimal SHA1 hashes (and vice-versa).
...
@@ -26,31 +19,9 @@ module Gitlab
...
@@ -26,31 +19,9 @@ module Gitlab
class
ShaAttribute
<
BINARY_TYPE
class
ShaAttribute
<
BINARY_TYPE
PACK_FORMAT
=
'H*'
.
freeze
PACK_FORMAT
=
'H*'
.
freeze
# It is called from activerecord-4.2.10/lib/active_record internal methods.
# Remove this method when removing Gitlab.rails5? code.
def
type_cast_from_database
(
value
)
unpack_sha
(
super
)
end
# It is called from activerecord-4.2.10/lib/active_record internal methods.
# Remove this method when removing Gitlab.rails5? code.
def
type_cast_for_database
(
value
)
serialize
(
value
)
end
# It is called from activerecord-5.0.6/lib/active_record/attribute.rb
# Remove this method when removing Gitlab.rails5? code..
def
deserialize
(
value
)
value
=
Gitlab
.
rails5?
?
super
:
method
(
:type_cast_from_database
).
super_method
.
call
(
value
)
unpack_sha
(
value
)
end
# Rename this method to `deserialize(value)` removing Gitlab.rails5? code.
# Casts binary data to a SHA1 in hexadecimal.
# Casts binary data to a SHA1 in hexadecimal.
def
unpack_sha
(
value
)
def
deserialize
(
value
)
# Uncomment this line when removing Gitlab.rails5? code.
value
=
super
(
value
)
# value = super
value
?
value
.
unpack
(
PACK_FORMAT
)[
0
]
:
nil
value
?
value
.
unpack
(
PACK_FORMAT
)[
0
]
:
nil
end
end
...
@@ -58,7 +29,7 @@ module Gitlab
...
@@ -58,7 +29,7 @@ module Gitlab
def
serialize
(
value
)
def
serialize
(
value
)
arg
=
value
?
[
value
].
pack
(
PACK_FORMAT
)
:
nil
arg
=
value
?
[
value
].
pack
(
PACK_FORMAT
)
:
nil
Gitlab
.
rails5?
?
super
(
arg
)
:
method
(
:type_cast_for_database
).
super_method
.
call
(
arg
)
super
(
arg
)
end
end
end
end
end
end
...
...
lib/gitlab/database/subquery.rb
View file @
56296f1e
...
@@ -6,15 +6,11 @@ module Gitlab
...
@@ -6,15 +6,11 @@ module Gitlab
class
<<
self
class
<<
self
def
self_join
(
relation
)
def
self_join
(
relation
)
t
=
relation
.
arel_table
t
=
relation
.
arel_table
t2
=
if
!
Gitlab
.
rails5?
# Work around a bug in Rails 5, where LIMIT causes trouble
relation
.
arel
.
as
(
't2'
)
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729
else
r
=
relation
.
limit
(
nil
).
arel
# Work around a bug in Rails 5, where LIMIT causes trouble
r
.
take
(
relation
.
limit_value
)
if
relation
.
limit_value
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729
t2
=
r
.
as
(
't2'
)
r
=
relation
.
limit
(
nil
).
arel
r
.
take
(
relation
.
limit_value
)
if
relation
.
limit_value
r
.
as
(
't2'
)
end
relation
.
unscoped
.
joins
(
t
.
join
(
t2
).
on
(
t
[
:id
].
eq
(
t2
[
:id
])).
join_sources
.
first
)
relation
.
unscoped
.
joins
(
t
.
join
(
t2
).
on
(
t
[
:id
].
eq
(
t2
[
:id
])).
join_sources
.
first
)
end
end
...
...
lib/gitlab/gpg.rb
View file @
56296f1e
...
@@ -73,13 +73,7 @@ module Gitlab
...
@@ -73,13 +73,7 @@ module Gitlab
if
MUTEX
.
locked?
&&
MUTEX
.
owned?
if
MUTEX
.
locked?
&&
MUTEX
.
owned?
optimistic_using_tmp_keychain
(
&
block
)
optimistic_using_tmp_keychain
(
&
block
)
else
else
if
Gitlab
.
rails5?
ActiveSupport
::
Dependencies
.
interlock
.
permit_concurrent_loads
do
ActiveSupport
::
Dependencies
.
interlock
.
permit_concurrent_loads
do
MUTEX
.
synchronize
do
optimistic_using_tmp_keychain
(
&
block
)
end
end
else
MUTEX
.
synchronize
do
MUTEX
.
synchronize
do
optimistic_using_tmp_keychain
(
&
block
)
optimistic_using_tmp_keychain
(
&
block
)
end
end
...
...
lib/gitlab/middleware/correlation_id.rb
View file @
56296f1e
...
@@ -20,11 +20,7 @@ module Gitlab
...
@@ -20,11 +20,7 @@ module Gitlab
private
private
def
correlation_id
(
env
)
def
correlation_id
(
env
)
if
Gitlab
.
rails5?
request
(
env
).
request_id
request
(
env
).
request_id
else
request
(
env
).
uuid
end
end
end
def
request
(
env
)
def
request
(
env
)
...
...
lib/mysql_zero_date.rb
View file @
56296f1e
...
@@ -17,4 +17,4 @@ module MysqlZeroDate
...
@@ -17,4 +17,4 @@ module MysqlZeroDate
end
end
end
end
ActiveRecord
::
ConnectionAdapters
::
AbstractMysqlAdapter
.
prepend
(
MysqlZeroDate
)
if
Gitlab
.
rails5?
ActiveRecord
::
ConnectionAdapters
::
AbstractMysqlAdapter
.
prepend
(
MysqlZeroDate
)
spec/controllers/application_controller_spec.rb
View file @
56296f1e
...
@@ -551,14 +551,7 @@ describe ApplicationController do
...
@@ -551,14 +551,7 @@ describe ApplicationController do
subject
{
get
:index
,
text:
"hi
\255
"
}
subject
{
get
:index
,
text:
"hi
\255
"
}
it
'renders 412'
do
it
'renders 412'
do
if
Gitlab
.
rails5?
expect
{
subject
}.
to
raise_error
(
ActionController
::
BadRequest
)
expect
{
subject
}.
to
raise_error
(
ActionController
::
BadRequest
)
else
subject
expect
(
response
).
to
have_gitlab_http_status
(
412
)
expect
(
response
).
to
render_template
:precondition_failed
end
end
end
end
end
...
@@ -566,16 +559,7 @@ describe ApplicationController do
...
@@ -566,16 +559,7 @@ describe ApplicationController do
subject
{
get
:index
,
text:
"hi
\255
"
,
format: :js
}
subject
{
get
:index
,
text:
"hi
\255
"
,
format: :js
}
it
'renders 412'
do
it
'renders 412'
do
if
Gitlab
.
rails5?
expect
{
subject
}.
to
raise_error
(
ActionController
::
BadRequest
)
expect
{
subject
}.
to
raise_error
(
ActionController
::
BadRequest
)
else
subject
json_response
=
JSON
.
parse
(
response
.
body
)
expect
(
response
).
to
have_gitlab_http_status
(
412
)
expect
(
json_response
[
'error'
]).
to
eq
(
'Invalid UTF-8'
)
end
end
end
end
end
end
end
...
...
spec/controllers/boards/lists_controller_spec.rb
View file @
56296f1e
...
@@ -163,11 +163,7 @@ describe Boards::ListsController do
...
@@ -163,11 +163,7 @@ describe Boards::ListsController do
list:
{
position:
position
},
list:
{
position:
position
},
format: :json
}
format: :json
}
if
Gitlab
.
rails5?
patch
:update
,
params:
params
,
as: :json
patch
:update
,
params:
params
,
as: :json
else
patch
:update
,
params
end
end
end
end
end
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
56296f1e
...
@@ -357,11 +357,7 @@ describe Projects::MergeRequestsController do
...
@@ -357,11 +357,7 @@ describe Projects::MergeRequestsController do
context
'when the sha parameter matches the source SHA'
do
context
'when the sha parameter matches the source SHA'
do
def
merge_with_sha
(
params
=
{})
def
merge_with_sha
(
params
=
{})
post_params
=
base_params
.
merge
(
sha:
merge_request
.
diff_head_sha
).
merge
(
params
)
post_params
=
base_params
.
merge
(
sha:
merge_request
.
diff_head_sha
).
merge
(
params
)
if
Gitlab
.
rails5?
post
:merge
,
params:
post_params
,
as: :json
post
:merge
,
params:
post_params
,
as: :json
else
post
:merge
,
post_params
end
end
end
it
'returns :success'
do
it
'returns :success'
do
...
...
spec/controllers/projects/pipeline_schedules_controller_spec.rb
View file @
56296f1e
...
@@ -310,19 +310,11 @@ describe Projects::PipelineSchedulesController do
...
@@ -310,19 +310,11 @@ describe Projects::PipelineSchedulesController do
end
end
def
go
def
go
if
Gitlab
.
rails5?
put
:update
,
params:
{
namespace_id:
project
.
namespace
.
to_param
,
put
:update
,
params:
{
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
project_id:
project
,
id:
pipeline_schedule
,
id:
pipeline_schedule
,
schedule:
schedule
},
schedule:
schedule
},
as: :html
as: :html
else
put
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
id:
pipeline_schedule
,
schedule:
schedule
end
end
end
end
end
...
...
spec/controllers/uploads_controller_spec.rb
View file @
56296f1e
...
@@ -8,11 +8,7 @@ end
...
@@ -8,11 +8,7 @@ end
shared_examples
'content not cached without revalidation and no-store'
do
shared_examples
'content not cached without revalidation and no-store'
do
it
'ensures content will not be cached without revalidation'
do
it
'ensures content will not be cached without revalidation'
do
# Fixed in newer versions of ActivePack, it will only output a single `private`.
# Fixed in newer versions of ActivePack, it will only output a single `private`.
if
Gitlab
.
rails5?
expect
(
subject
[
'Cache-Control'
]).
to
eq
(
'max-age=0, private, must-revalidate, no-store'
)
expect
(
subject
[
'Cache-Control'
]).
to
eq
(
'max-age=0, private, must-revalidate, no-store'
)
else
expect
(
subject
[
'Cache-Control'
]).
to
eq
(
'max-age=0, private, must-revalidate, private, no-store'
)
end
end
end
end
end
...
...
spec/helpers/storage_helper_spec.rb
View file @
56296f1e
...
@@ -15,11 +15,7 @@ describe StorageHelper do
...
@@ -15,11 +15,7 @@ describe StorageHelper do
end
end
it
"uses commas as thousands separator"
do
it
"uses commas as thousands separator"
do
if
Gitlab
.
rails5?
expect
(
helper
.
storage_counter
(
100_000_000_000_000_000_000_000
)).
to
eq
(
"86,736.2 EB"
)
expect
(
helper
.
storage_counter
(
100_000_000_000_000_000_000_000
)).
to
eq
(
"86,736.2 EB"
)
else
expect
(
helper
.
storage_counter
(
100_000_000_000_000_000
)).
to
eq
(
"90,949.5 TB"
)
end
end
end
end
end
end
end
spec/lib/gitlab/database_spec.rb
View file @
56296f1e
...
@@ -400,13 +400,8 @@ describe Gitlab::Database do
...
@@ -400,13 +400,8 @@ describe Gitlab::Database do
describe
'.cached_table_exists?'
do
describe
'.cached_table_exists?'
do
it
'only retrieves data once per table'
do
it
'only retrieves data once per table'
do
if
Gitlab
.
rails5?
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:data_source_exists?
).
with
(
:projects
).
once
.
and_call_original
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:data_source_exists?
).
with
(
:projects
).
once
.
and_call_original
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:data_source_exists?
).
with
(
:bogus_table_name
).
once
.
and_call_original
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:data_source_exists?
).
with
(
:bogus_table_name
).
once
.
and_call_original
else
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
with
(
:projects
).
once
.
and_call_original
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
with
(
:bogus_table_name
).
once
.
and_call_original
end
2
.
times
do
2
.
times
do
expect
(
described_class
.
cached_table_exists?
(
:projects
)).
to
be_truthy
expect
(
described_class
.
cached_table_exists?
(
:projects
)).
to
be_truthy
...
...
spec/lib/gitlab/sql/glob_spec.rb
View file @
56296f1e
...
@@ -35,9 +35,8 @@ describe Gitlab::SQL::Glob do
...
@@ -35,9 +35,8 @@ describe Gitlab::SQL::Glob do
value
=
query
(
"SELECT
#{
quote
(
string
)
}
LIKE
#{
pattern
}
"
)
value
=
query
(
"SELECT
#{
quote
(
string
)
}
LIKE
#{
pattern
}
"
)
.
rows
.
flatten
.
first
.
rows
.
flatten
.
first
check
=
Gitlab
.
rails5?
?
true
:
't'
case
value
case
value
when
check
,
1
when
true
,
1
true
true
else
else
false
false
...
...
spec/models/notification_setting_spec.rb
View file @
56296f1e
...
@@ -42,12 +42,7 @@ RSpec.describe NotificationSetting do
...
@@ -42,12 +42,7 @@ RSpec.describe NotificationSetting do
expect
(
notification_setting
.
new_issue
).
to
eq
(
true
)
expect
(
notification_setting
.
new_issue
).
to
eq
(
true
)
expect
(
notification_setting
.
close_issue
).
to
eq
(
true
)
expect
(
notification_setting
.
close_issue
).
to
eq
(
true
)
expect
(
notification_setting
.
merge_merge_request
).
to
eq
(
true
)
expect
(
notification_setting
.
merge_merge_request
).
to
eq
(
true
)
expect
(
notification_setting
.
close_merge_request
).
to
eq
(
true
)
# In Rails 5 assigning a value which is not explicitly `true` or `false` ("nil" in this case)
# to a boolean column transforms it to `true`.
# In Rails 4 it transforms the value to `false` with deprecation warning.
# Replace `eq(Gitlab.rails5?)` with `eq(true)` when removing rails5? code.
expect
(
notification_setting
.
close_merge_request
).
to
eq
(
Gitlab
.
rails5?
)
expect
(
notification_setting
.
reopen_merge_request
).
to
eq
(
false
)
expect
(
notification_setting
.
reopen_merge_request
).
to
eq
(
false
)
end
end
end
end
...
...
spec/requests/api/internal_spec.rb
View file @
56296f1e
...
@@ -969,17 +969,10 @@ describe API::Internal do
...
@@ -969,17 +969,10 @@ describe API::Internal do
env:
env
env:
env
}
}
if
Gitlab
.
rails5?
post
(
post
(
api
(
"/internal/allowed"
),
api
(
"/internal/allowed"
),
params:
params
params:
params
)
)
else
post
(
api
(
"/internal/allowed"
),
params
)
end
end
end
def
archive
(
key
,
project
)
def
archive
(
key
,
project
)
...
...
spec/support/helpers/test_request_helpers.rb
View file @
56296f1e
...
@@ -2,10 +2,6 @@
...
@@ -2,10 +2,6 @@
module
TestRequestHelpers
module
TestRequestHelpers
def
test_request
(
remote_ip:
'127.0.0.1'
)
def
test_request
(
remote_ip:
'127.0.0.1'
)
if
Gitlab
.
rails5?
ActionController
::
TestRequest
.
new
({
remote_ip:
remote_ip
},
ActionController
::
TestSession
.
new
)
ActionController
::
TestRequest
.
new
({
remote_ip:
remote_ip
},
ActionController
::
TestSession
.
new
)
else
ActionController
::
TestRequest
.
new
(
remote_ip:
remote_ip
)
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