2011-01-31 14:18:25 +00:00
|
|
|
require 'rubygems'
|
|
|
|
require 'bundler/setup'
|
2010-07-20 18:04:23 +00:00
|
|
|
|
2021-02-13 06:32:44 +00:00
|
|
|
if RUBY_ENGINE == 'jruby'
|
|
|
|
# Workaround for JRuby CI failure https://github.com/jruby/jruby/issues/6547#issuecomment-774104996
|
|
|
|
require 'i18n/backend'
|
|
|
|
require 'i18n/backend/simple'
|
|
|
|
end
|
|
|
|
|
2022-02-03 09:17:09 +00:00
|
|
|
require 'pry' unless ENV['GITHUB_ACTIONS']
|
2008-08-28 18:06:46 +00:00
|
|
|
require 'tempfile'
|
2010-01-30 22:33:21 +00:00
|
|
|
require 'time'
|
2009-05-10 11:12:16 +00:00
|
|
|
require 'logger'
|
2021-04-14 10:14:18 +00:00
|
|
|
require 'csv'
|
2009-05-10 11:12:16 +00:00
|
|
|
|
2010-07-20 16:58:34 +00:00
|
|
|
require 'carrierwave'
|
2010-07-20 17:58:12 +00:00
|
|
|
require 'timecop'
|
2011-03-10 21:37:34 +00:00
|
|
|
require 'open-uri'
|
2016-01-08 15:32:54 +00:00
|
|
|
require "webmock/rspec"
|
2013-05-30 12:06:48 +00:00
|
|
|
require 'mini_magick'
|
2020-07-20 09:46:39 +00:00
|
|
|
require "vips"
|
2021-02-21 10:53:50 +00:00
|
|
|
require 'active_support/core_ext'
|
2021-03-13 10:34:52 +00:00
|
|
|
require 'rspec/retry'
|
2011-03-10 21:37:34 +00:00
|
|
|
|
2014-10-16 11:58:47 +00:00
|
|
|
I18n.enforce_available_locales = false
|
|
|
|
|
2009-02-15 20:15:21 +00:00
|
|
|
def file_path( *paths )
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
2008-08-28 20:25:39 +00:00
|
|
|
end
|
|
|
|
|
2009-02-15 20:15:21 +00:00
|
|
|
def public_path( *paths )
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
|
2008-08-28 20:25:39 +00:00
|
|
|
end
|
|
|
|
|
2014-02-19 07:06:50 +00:00
|
|
|
def tmp_path( *paths )
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'tmp', *paths))
|
|
|
|
end
|
|
|
|
|
2009-10-24 08:00:09 +00:00
|
|
|
CarrierWave.root = public_path
|
2013-11-21 17:25:15 +00:00
|
|
|
I18n.load_path << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "carrierwave", "locale", 'en.yml'))
|
2009-02-15 20:15:21 +00:00
|
|
|
|
2009-03-29 19:20:58 +00:00
|
|
|
module CarrierWave
|
|
|
|
module Test
|
2009-05-10 11:43:47 +00:00
|
|
|
module MockStorage
|
|
|
|
def mock_storage(kind)
|
2014-07-08 17:05:42 +00:00
|
|
|
storage = double("storage for #{kind} uploader")
|
2015-04-22 18:58:56 +00:00
|
|
|
allow(storage).to receive(:setup!)
|
2009-05-10 11:43:47 +00:00
|
|
|
storage
|
|
|
|
end
|
|
|
|
end
|
2010-07-07 19:34:27 +00:00
|
|
|
|
2009-03-29 19:20:58 +00:00
|
|
|
module MockFiles
|
|
|
|
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
|
|
|
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
2008-08-28 18:06:46 +00:00
|
|
|
|
2014-10-19 17:09:07 +00:00
|
|
|
tempfile = Tempfile.new(filename)
|
|
|
|
FileUtils.copy_file(file_path(filename), tempfile.path)
|
2015-04-22 18:58:56 +00:00
|
|
|
allow(tempfile).to receive_messages(:original_filename => fake_name || filename,
|
2014-10-19 17:09:07 +00:00
|
|
|
:content_type => mime_type)
|
|
|
|
tempfile
|
2009-03-29 19:20:58 +00:00
|
|
|
end
|
|
|
|
|
2014-10-19 17:09:07 +00:00
|
|
|
alias_method :stub_merb_tempfile, :stub_tempfile
|
|
|
|
|
2009-03-29 19:20:58 +00:00
|
|
|
def stub_stringio(filename, mime_type=nil, fake_name=nil)
|
2014-10-19 17:09:07 +00:00
|
|
|
file = IO.read( file_path( filename ) ) if filename
|
|
|
|
stringio = StringIO.new(file)
|
2015-04-22 18:58:56 +00:00
|
|
|
allow(stringio).to receive_messages(:local_path => "",
|
2014-10-19 17:09:07 +00:00
|
|
|
:original_filename => filename || fake_name,
|
|
|
|
:content_type => mime_type)
|
|
|
|
stringio
|
2009-03-29 19:20:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_file(filename, mime_type=nil, fake_name=nil)
|
2016-05-07 00:28:28 +00:00
|
|
|
f = File.open(file_path(filename))
|
2019-06-21 09:51:16 +00:00
|
|
|
allow(f).to receive(:content_type) { mime_type } if mime_type
|
2016-05-07 00:28:28 +00:00
|
|
|
return f
|
2009-03-29 19:20:58 +00:00
|
|
|
end
|
2008-08-28 18:06:46 +00:00
|
|
|
end
|
2010-07-07 19:34:27 +00:00
|
|
|
|
|
|
|
module I18nHelpers
|
|
|
|
def change_locale_and_store_translations(locale, translations, &block)
|
|
|
|
current_locale = I18n.locale
|
|
|
|
begin
|
2018-02-10 06:56:26 +00:00
|
|
|
# I18n.available_locales needs to be cleared before storing translations:
|
|
|
|
# https://github.com/svenfuchs/i18n/pull/391
|
|
|
|
I18n.available_locales = nil
|
2010-07-07 19:34:27 +00:00
|
|
|
I18n.backend.store_translations locale, translations
|
|
|
|
I18n.locale = locale
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
I18n.reload!
|
|
|
|
I18n.locale = current_locale
|
|
|
|
end
|
|
|
|
end
|
2016-12-16 14:22:11 +00:00
|
|
|
|
|
|
|
def change_and_enforece_available_locales(locale, available_locales, &block)
|
|
|
|
current_available_locales = I18n.available_locales
|
|
|
|
current_enforce_available_locales_value = I18n.enforce_available_locales
|
|
|
|
current_locale = I18n.locale
|
|
|
|
begin
|
|
|
|
I18n.available_locales = [:nl]
|
|
|
|
I18n.enforce_available_locales = true
|
|
|
|
I18n.locale = :nl
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
I18n.available_locales = current_available_locales
|
|
|
|
I18n.enforce_available_locales = current_enforce_available_locales_value
|
|
|
|
I18n.locale = current_locale
|
|
|
|
end
|
|
|
|
end
|
2010-07-07 19:34:27 +00:00
|
|
|
end
|
2013-05-22 18:15:15 +00:00
|
|
|
|
|
|
|
module ManipulationHelpers
|
|
|
|
def color_of_pixel(path, x, y)
|
|
|
|
image = ::MiniMagick::Image.open(path)
|
2017-11-23 01:03:23 +00:00
|
|
|
image.run_command("convert", "#{image.path}[1x1+#{x}+#{y}]", "-depth", "8", "txt:").split("\n")[1]
|
2013-05-22 18:15:15 +00:00
|
|
|
end
|
|
|
|
end
|
2021-01-25 09:04:35 +00:00
|
|
|
|
|
|
|
module SsrfProtectionAwareWebMock
|
2021-03-20 08:48:22 +00:00
|
|
|
class Matcher
|
|
|
|
def initialize(uri)
|
|
|
|
@uri = uri
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(target_uri)
|
|
|
|
Resolv.getaddresses(@uri.hostname).any? do |address|
|
|
|
|
candidate = @uri.dup
|
|
|
|
candidate.hostname = address
|
|
|
|
target_uri === WebMock::Util::URI.normalize_uri(candidate)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{@uri}>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-25 09:04:35 +00:00
|
|
|
def stub_request(method, uri)
|
|
|
|
uri = URI.parse(uri) if uri.is_a?(String)
|
2021-03-20 08:48:22 +00:00
|
|
|
if uri.is_a?(URI)
|
|
|
|
super method, Matcher.new(uri)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
2021-01-25 09:04:35 +00:00
|
|
|
end
|
|
|
|
end
|
2008-08-28 18:06:46 +00:00
|
|
|
end
|
2009-03-29 19:20:58 +00:00
|
|
|
end
|
2008-08-28 18:06:46 +00:00
|
|
|
|
2011-05-18 19:13:55 +00:00
|
|
|
RSpec.configure do |config|
|
2009-04-15 19:39:25 +00:00
|
|
|
config.include CarrierWave::Test::Matchers
|
2009-03-29 19:20:58 +00:00
|
|
|
config.include CarrierWave::Test::MockFiles
|
2009-05-10 11:43:47 +00:00
|
|
|
config.include CarrierWave::Test::MockStorage
|
2010-07-07 19:34:27 +00:00
|
|
|
config.include CarrierWave::Test::I18nHelpers
|
2013-05-22 18:15:15 +00:00
|
|
|
config.include CarrierWave::Test::ManipulationHelpers
|
2021-01-25 09:04:35 +00:00
|
|
|
config.prepend CarrierWave::Test::SsrfProtectionAwareWebMock
|
2021-03-13 10:34:52 +00:00
|
|
|
config.verbose_retry = true
|
|
|
|
config.display_try_failure_messages = true
|
2022-06-18 04:01:13 +00:00
|
|
|
config.raise_errors_for_deprecations!
|
2021-03-13 10:34:52 +00:00
|
|
|
config.around :each, :with_retry do |example|
|
|
|
|
example.run_with_retry retry: 2
|
|
|
|
end
|
|
|
|
config.retry_callback = proc do |example|
|
|
|
|
sleep 1
|
|
|
|
end
|
2014-04-27 11:46:00 +00:00
|
|
|
if RUBY_ENGINE == 'jruby'
|
|
|
|
config.filter_run_excluding :rmagick => true
|
|
|
|
end
|
2010-01-30 22:33:21 +00:00
|
|
|
end
|