Commit 5e3b5b60 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-resolve-lib-gitlab-differences' into 'master'

EE: Move EE specific code out of lib/gitlab

Closes #5964, #6023, #6661, and #6662

See merge request gitlab-org/gitlab-ee!9831
parents 7c3330ef b1c86666
...@@ -33,8 +33,8 @@ module EE ...@@ -33,8 +33,8 @@ module EE
} }
when :project_creation_level when :project_creation_level
{ {
from: ::EE::Gitlab::Access.level_name(old), from: ::Gitlab::Access.level_name(old),
to: ::EE::Gitlab::Access.level_name(new) to: ::Gitlab::Access.level_name(new)
} }
when :plan_id when :plan_id
{ {
......
...@@ -8,13 +8,15 @@ ...@@ -8,13 +8,15 @@
module EE module EE
module Gitlab module Gitlab
module Access module Access
extend self extend ActiveSupport::Concern
# Default project creation level # Default project creation level
NO_ONE_PROJECT_ACCESS = 0 NO_ONE_PROJECT_ACCESS = 0
MAINTAINER_PROJECT_ACCESS = 1 MAINTAINER_PROJECT_ACCESS = 1
DEVELOPER_MAINTAINER_PROJECT_ACCESS = 2 DEVELOPER_MAINTAINER_PROJECT_ACCESS = 2
ADMIN = 60
class_methods do
def project_creation_options def project_creation_options
{ {
s_('ProjectCreationLevel|No one') => NO_ONE_PROJECT_ACCESS, s_('ProjectCreationLevel|No one') => NO_ONE_PROJECT_ACCESS,
...@@ -28,4 +30,5 @@ module EE ...@@ -28,4 +30,5 @@ module EE
end end
end end
end end
end
end end
# frozen_string_literal: true
module EE
module Gitlab
module BackgroundMigration
module PopulateImportState
extend ::Gitlab::Utils::Override
override :move_attributes_data_to_import_state
def move_attributes_data_to_import_state(start_id, end_id)
Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}")
ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO project_mirror_data (project_id, status, jid, last_update_at, last_successful_update_at, last_error)
SELECT id, import_status, import_jid, mirror_last_update_at, mirror_last_successful_update_at, import_error
FROM projects
WHERE projects.import_status != 'none'
AND projects.id BETWEEN #{start_id} AND #{end_id}
AND NOT EXISTS (
SELECT id
FROM project_mirror_data
WHERE project_id = projects.id
)
SQL
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects
SET import_status = 'none'
WHERE import_status != 'none'
AND id BETWEEN #{start_id} AND #{end_id}
SQL
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module BackgroundMigration
module RollbackImportStateData
extend ::Gitlab::Utils::Override
override :move_attributes_data_to_project
def move_attributes_data_to_project(start_id, end_id)
Rails.logger.info("#{self.class.name} - Moving import attributes data to projects table: #{start_id} - #{end_id}")
if ::Gitlab::Database.mysql?
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects, project_mirror_data
SET
projects.import_status = project_mirror_data.status,
projects.import_jid = project_mirror_data.jid,
projects.mirror_last_update_at = project_mirror_data.last_update_at,
projects.mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
projects.import_error = project_mirror_data.last_error
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
SQL
else
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects
SET
import_status = project_mirror_data.status,
import_jid = project_mirror_data.jid,
mirror_last_update_at = project_mirror_data.last_update_at,
mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
import_error = project_mirror_data.last_error
FROM project_mirror_data
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
SQL
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Ci
module Pipeline
module Chain
module Validate
module Abilities
extend ::Gitlab::Utils::Override
override :perform!
def perform!
# We check for `builds_enabled?` here so that this error does
# not get produced before the "pipelines are disabled" error.
if project.builds_enabled? &&
(command.allow_mirror_update && !project.mirror_trigger_builds?)
return error('Pipeline is disabled for mirror updates')
end
super
end
end
end
end
end
end
end
end
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
module EE module EE
module Gitlab module Gitlab
module Database module Database
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :read_only? override :read_only?
...@@ -42,4 +45,5 @@ module EE ...@@ -42,4 +45,5 @@ module EE
end end
end end
end end
end
end end
# frozen_string_literal: true
module EE
module Gitlab
module ExclusiveLease
# Try to obtain the lease. Returns the UUID and current TTL, which will be
# zero if it's not taken.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
def try_obtain_with_ttl
::Gitlab::Redis::SharedState.with do |redis|
output = redis.set(@redis_shared_state_key, @uuid, nx: true, ex: @timeout) && @uuid
ttl = output ? 0 : redis.ttl(@redis_shared_state_key)
{ ttl: [ttl, 0].max, uuid: output }
end
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
# Returns true if the UUID for the key hasn't changed.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
def same_uuid?
::Gitlab::Redis::SharedState.with do |redis|
redis.get(@redis_shared_state_key) == @uuid
end
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Favicon
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :development_favicon
def development_favicon
'favicon-green.png'
end
end
end
end
end
...@@ -5,6 +5,8 @@ module EE ...@@ -5,6 +5,8 @@ module EE
module GitAccess module GitAccess
prepend GeoGitAccess prepend GeoGitAccess
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
include ActionView::Helpers::SanitizeHelper
include PathLocksHelper
override :check override :check
def check(cmd, changes) def check(cmd, changes)
......
# frozen_string_literal: true
module EE
module Gitlab
module ObjectHierarchy
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module PathRegex
extend ActiveSupport::Concern
class_methods do
def saml_callback_regex
@saml_callback_regex ||= %r(\A\/groups\/(?<group>#{full_namespace_route_regex})\/\-\/saml\/callback\z).freeze
end
end
end
end
end
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
module EE module EE
module Gitlab module Gitlab
module Regex module Regex
extend ActiveSupport::Concern
class_methods do
def environment_scope_regex_chars def environment_scope_regex_chars
"#{environment_name_regex_chars}\\*" "#{environment_name_regex_chars}\\*"
end end
...@@ -41,4 +44,5 @@ module EE ...@@ -41,4 +44,5 @@ module EE
end end
end end
end end
end
end end
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
module EE module EE
module Gitlab module Gitlab
module UsageData module UsageData
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :features_usage_data override :features_usage_data
...@@ -142,4 +145,5 @@ module EE ...@@ -142,4 +145,5 @@ module EE
end end
end end
end end
end
end end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do
set(:project) { create(:project, :repository) }
set(:user) { create(:user) }
let(:pipeline) do
build_stubbed(:ci_pipeline, project: project)
end
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command
.new(project: project, current_user: user, origin_ref: ref)
end
let(:step) { described_class.new(pipeline, command) }
let(:ref) { 'master' }
describe '#perform!' do
context 'when triggering builds for project mirrors is disabled' do
it 'returns an error' do
project.add_developer(user)
allow(command)
.to receive(:allow_mirror_update)
.and_return(true)
allow(project)
.to receive(:mirror_trigger_builds?)
.and_return(false)
step.perform!
expect(pipeline.errors.to_a)
.to include('Pipeline is disabled for mirror updates')
end
end
end
end
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
# #
module Gitlab module Gitlab
module Access module Access
extend ::EE::Gitlab::Access # rubocop: disable Cop/InjectEnterpriseEditionModule
AccessDeniedError = Class.new(StandardError) AccessDeniedError = Class.new(StandardError)
NO_ACCESS = 0 NO_ACCESS = 0
...@@ -19,7 +17,6 @@ module Gitlab ...@@ -19,7 +17,6 @@ module Gitlab
# @deprecated # @deprecated
MASTER = MAINTAINER MASTER = MAINTAINER
OWNER = 50 OWNER = 50
ADMIN = 60
# Branch protection settings # Branch protection settings
PROTECTION_NONE = 0 PROTECTION_NONE = 0
...@@ -89,3 +86,5 @@ module Gitlab ...@@ -89,3 +86,5 @@ module Gitlab
end end
end end
end end
Gitlab::Access.prepend(EE::Gitlab::Access)
...@@ -15,8 +15,8 @@ module Gitlab ...@@ -15,8 +15,8 @@ module Gitlab
Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}") Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}")
ActiveRecord::Base.connection.execute <<~SQL ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO project_mirror_data (project_id, status, jid, last_update_at, last_successful_update_at, last_error) INSERT INTO project_mirror_data (project_id, status, jid, last_error)
SELECT id, import_status, import_jid, mirror_last_update_at, mirror_last_successful_update_at, import_error SELECT id, import_status, import_jid, import_error
FROM projects FROM projects
WHERE projects.import_status != 'none' WHERE projects.import_status != 'none'
AND projects.id BETWEEN #{start_id} AND #{end_id} AND projects.id BETWEEN #{start_id} AND #{end_id}
...@@ -37,3 +37,5 @@ module Gitlab ...@@ -37,3 +37,5 @@ module Gitlab
end end
end end
end end
Gitlab::BackgroundMigration::PopulateImportState.prepend(EE::Gitlab::BackgroundMigration::PopulateImportState)
...@@ -18,8 +18,6 @@ module Gitlab ...@@ -18,8 +18,6 @@ module Gitlab
SET SET
projects.import_status = project_mirror_data.status, projects.import_status = project_mirror_data.status,
projects.import_jid = project_mirror_data.jid, projects.import_jid = project_mirror_data.jid,
projects.mirror_last_update_at = project_mirror_data.last_update_at,
projects.mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
projects.import_error = project_mirror_data.last_error projects.import_error = project_mirror_data.last_error
WHERE project_mirror_data.project_id = projects.id WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id} AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
...@@ -30,8 +28,6 @@ module Gitlab ...@@ -30,8 +28,6 @@ module Gitlab
SET SET
import_status = project_mirror_data.status, import_status = project_mirror_data.status,
import_jid = project_mirror_data.jid, import_jid = project_mirror_data.jid,
mirror_last_update_at = project_mirror_data.last_update_at,
mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
import_error = project_mirror_data.last_error import_error = project_mirror_data.last_error
FROM project_mirror_data FROM project_mirror_data
WHERE project_mirror_data.project_id = projects.id WHERE project_mirror_data.project_id = projects.id
...@@ -42,3 +38,5 @@ module Gitlab ...@@ -42,3 +38,5 @@ module Gitlab
end end
end end
end end
Gitlab::BackgroundMigration::RollbackImportStateData.prepend(EE::Gitlab::BackgroundMigration::RollbackImportStateData)
...@@ -11,10 +11,7 @@ module Gitlab ...@@ -11,10 +11,7 @@ module Gitlab
:trigger_request, :schedule, :merge_request, :trigger_request, :schedule, :merge_request,
:ignore_skip_ci, :save_incompleted, :ignore_skip_ci, :save_incompleted,
:seeds_block, :variables_attributes, :push_options, :seeds_block, :variables_attributes, :push_options,
:chat_data, :chat_data, :allow_mirror_update
# EE specific
:allow_mirror_update
) do ) do
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
......
...@@ -14,10 +14,6 @@ module Gitlab ...@@ -14,10 +14,6 @@ module Gitlab
return error('Pipelines are disabled!') return error('Pipelines are disabled!')
end end
if @command.allow_mirror_update && !project.mirror_trigger_builds?
return error('Pipeline is disabled for mirror updates')
end
unless allowed_to_trigger_pipeline? unless allowed_to_trigger_pipeline?
if can?(current_user, :create_pipeline, project) if can?(current_user, :create_pipeline, project)
return error("Insufficient permissions for protected ref '#{command.ref}'") return error("Insufficient permissions for protected ref '#{command.ref}'")
...@@ -58,3 +54,5 @@ module Gitlab ...@@ -58,3 +54,5 @@ module Gitlab
end end
end end
end end
Gitlab::Ci::Pipeline::Chain::Validate::Abilities.prepend(EE::Gitlab::Ci::Pipeline::Chain::Validate::Abilities)
...@@ -11,10 +11,6 @@ module Gitlab ...@@ -11,10 +11,6 @@ module Gitlab
# https://dev.mysql.com/doc/refman/5.7/en/datetime.html # https://dev.mysql.com/doc/refman/5.7/en/datetime.html
MAX_TIMESTAMP_VALUE = Time.at((1 << 31) - 1).freeze MAX_TIMESTAMP_VALUE = Time.at((1 << 31) - 1).freeze
class << self
prepend EE::Gitlab::Database # rubocop: disable Cop/InjectEnterpriseEditionModule
end
def self.config def self.config
ActiveRecord::Base.configurations[Rails.env] ActiveRecord::Base.configurations[Rails.env]
end end
...@@ -274,3 +270,5 @@ module Gitlab ...@@ -274,3 +270,5 @@ module Gitlab
end end
end end
end end
Gitlab::Database.prepend(EE::Gitlab::Database)
...@@ -68,18 +68,6 @@ module Gitlab ...@@ -68,18 +68,6 @@ module Gitlab
end end
end end
# Try to obtain the lease. Returns the UUID and current TTL, which will be
# zero if it's not taken.
def try_obtain_with_ttl
Gitlab::Redis::SharedState.with do |redis|
output = redis.set(@redis_shared_state_key, @uuid, nx: true, ex: @timeout) && @uuid
ttl = output ? 0 : redis.ttl(@redis_shared_state_key)
{ ttl: [ttl, 0].max, uuid: output }
end
end
# Try to renew an existing lease. Return lease UUID on success, # Try to renew an existing lease. Return lease UUID on success,
# false if the lease is taken by a different UUID or inexistent. # false if the lease is taken by a different UUID or inexistent.
def renew def renew
...@@ -106,12 +94,7 @@ module Gitlab ...@@ -106,12 +94,7 @@ module Gitlab
ttl if ttl.positive? ttl if ttl.positive?
end end
end end
# Returns true if the UUID for the key hasn't changed.
def same_uuid?
Gitlab::Redis::SharedState.with do |redis|
redis.get(@redis_shared_state_key) == @uuid
end
end
end end
end end
Gitlab::ExclusiveLease.prepend(EE::Gitlab::ExclusiveLease)
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
elsif Gitlab::Utils.to_boolean(ENV['CANARY']) elsif Gitlab::Utils.to_boolean(ENV['CANARY'])
'favicon-yellow.png' 'favicon-yellow.png'
elsif Rails.env.development? elsif Rails.env.development?
'favicon-green.png' development_favicon
else else
'favicon.png' 'favicon.png'
end end
...@@ -18,6 +18,12 @@ module Gitlab ...@@ -18,6 +18,12 @@ module Gitlab
ActionController::Base.helpers.image_path(image_name, host: host) ActionController::Base.helpers.image_path(image_name, host: host)
end end
def development_favicon
# This is a separate method so that EE can return a different favicon
# for development environments.
'favicon-blue.png'
end
def status_overlay(status_name) def status_overlay(status_name)
path = File.join( path = File.join(
'ci_favicons', 'ci_favicons',
...@@ -58,3 +64,5 @@ module Gitlab ...@@ -58,3 +64,5 @@ module Gitlab
end end
end end
end end
Gitlab::Favicon.prepend(EE::Gitlab::Favicon)
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
# class return an instance of `GitlabAccessStatus` # class return an instance of `GitlabAccessStatus`
module Gitlab module Gitlab
class GitAccess class GitAccess
prepend ::EE::Gitlab::GitAccess # rubocop: disable Cop/InjectEnterpriseEditionModule
include ActionView::Helpers::SanitizeHelper
include PathLocksHelper
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
UnauthorizedError = Class.new(StandardError) UnauthorizedError = Class.new(StandardError)
...@@ -249,22 +246,18 @@ module Gitlab ...@@ -249,22 +246,18 @@ module Gitlab
end end
end end
# TODO: please clean this up
def check_push_access! def check_push_access!
if project.repository_read_only? if project.repository_read_only?
# The repository is temporarily read-only. Please try again later.
raise UnauthorizedError, ERROR_MESSAGES[:read_only] raise UnauthorizedError, ERROR_MESSAGES[:read_only]
end end
if deploy_key? if deploy_key?
unless deploy_key.can_push_to?(project) unless deploy_key.can_push_to?(project)
# This deploy key does not have write access to this project.
raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload] raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload]
end end
elsif user elsif user
# User access is verified in check_change_access! # User access is verified in check_change_access!
else else
# You are not allowed to upload code for this project.
raise UnauthorizedError, ERROR_MESSAGES[:upload] raise UnauthorizedError, ERROR_MESSAGES[:upload]
end end
...@@ -407,3 +400,5 @@ module Gitlab ...@@ -407,3 +400,5 @@ module Gitlab
end end
end end
end end
Gitlab::GitAccess.prepend(EE::Gitlab::GitAccess)
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
module Gitlab module Gitlab
module HookData module HookData
class IssueBuilder < BaseBuilder class IssueBuilder < BaseBuilder
prepend ::EE::Gitlab::HookData::IssueBuilder # rubocop: disable Cop/InjectEnterpriseEditionModule
SAFE_HOOK_RELATIONS = %i[ SAFE_HOOK_RELATIONS = %i[
assignees assignees
labels labels
...@@ -55,3 +53,5 @@ module Gitlab ...@@ -55,3 +53,5 @@ module Gitlab
end end
end end
end end
Gitlab::HookData::IssueBuilder.prepend(EE::Gitlab::HookData::IssueBuilder)
...@@ -39,12 +39,6 @@ module Gitlab ...@@ -39,12 +39,6 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
# Returns a relation that includes the ancestors_base set of objects # Returns a relation that includes the ancestors_base set of objects
# and all their ancestors (recursively). # and all their ancestors (recursively).
# #
...@@ -179,3 +173,5 @@ module Gitlab ...@@ -179,3 +173,5 @@ module Gitlab
end end
end end
end end
Gitlab::ObjectHierarchy.prepend(EE::Gitlab::ObjectHierarchy)
...@@ -233,10 +233,6 @@ module Gitlab ...@@ -233,10 +233,6 @@ module Gitlab
}x }x
end end
def saml_callback_regex
@saml_callback_regex ||= %r(\A\/groups\/(?<group>#{full_namespace_route_regex})\/\-\/saml\/callback\z).freeze
end
private private
def single_line_regexp(regex) def single_line_regexp(regex)
...@@ -246,3 +242,5 @@ module Gitlab ...@@ -246,3 +242,5 @@ module Gitlab
end end
end end
end end
Gitlab::PathRegex.prepend(EE::Gitlab::PathRegex)
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
module Gitlab module Gitlab
module Regex module Regex
extend self extend self
extend EE::Gitlab::Regex # rubocop: disable Cop/InjectEnterpriseEditionModule
def namespace_name_regex def namespace_name_regex
@namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze @namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
...@@ -108,3 +107,5 @@ module Gitlab ...@@ -108,3 +107,5 @@ module Gitlab
end end
end end
end end
Gitlab::Regex.prepend(EE::Gitlab::Regex)
...@@ -5,8 +5,6 @@ module Gitlab ...@@ -5,8 +5,6 @@ module Gitlab
APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze
class << self class << self
prepend EE::Gitlab::UsageData # rubocop: disable Cop/InjectEnterpriseEditionModule
def data(force_refresh: false) def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data } Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
end end
...@@ -31,7 +29,7 @@ module Gitlab ...@@ -31,7 +29,7 @@ module Gitlab
installation_type: Gitlab::INSTALLATION_TYPE, installation_type: Gitlab::INSTALLATION_TYPE,
active_user_count: count(User.active), active_user_count: count(User.active),
recorded_at: Time.now, recorded_at: Time.now,
edition: 'EE' edition: 'CE'
} }
usage_data usage_data
...@@ -192,3 +190,5 @@ module Gitlab ...@@ -192,3 +190,5 @@ module Gitlab
end end
end end
end end
Gitlab::UsageData.prepend(EE::Gitlab::UsageData)
...@@ -104,7 +104,6 @@ module Gitlab ...@@ -104,7 +104,6 @@ module Gitlab
nil nil
end end
# EE below
def try_megabytes_to_bytes(size) def try_megabytes_to_bytes(size)
Integer(size).megabytes Integer(size).megabytes
rescue ArgumentError rescue ArgumentError
......
...@@ -213,4 +213,22 @@ describe Gitlab::Utils do ...@@ -213,4 +213,22 @@ describe Gitlab::Utils do
expect(subject[:variables].first[:key]).to eq('VAR1') expect(subject[:variables].first[:key]).to eq('VAR1')
end end
end end
describe '.try_megabytes_to_bytes' do
context 'when the size can be converted to megabytes' do
it 'returns the size in megabytes' do
size = described_class.try_megabytes_to_bytes(1)
expect(size).to eq(1.megabytes)
end
end
context 'when the size can not be converted to megabytes' do
it 'returns the input size' do
size = described_class.try_megabytes_to_bytes('foo')
expect(size).to eq('foo')
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment