# frozen_string_literal: true require 'rails_helper' require 'tempfile' class GlobalSetting def self.reset_secret_key_base! @safe_secret_key_base = nil end end describe GlobalSetting do describe '.use_s3_assets?' do it 'returns false by default' do expect(GlobalSetting.use_s3?).to eq(false) end it 'returns true once set' do global_setting :s3_bucket, 'test_bucket' global_setting :s3_region, 'ap-australia' global_setting :s3_access_key_id, '123' global_setting :s3_secret_access_key, '123' expect(GlobalSetting.use_s3?).to eq(true) end end describe '.safe_secret_key_base' do it 'sets redis token if it is somehow flushed after 30 seconds' do # we have to reset so we reset all times and test runs consistently GlobalSetting.reset_secret_key_base! freeze_time Time.now token = GlobalSetting.safe_secret_key_base $redis.without_namespace.del(GlobalSetting::REDIS_SECRET_KEY) freeze_time Time.now + 20 GlobalSetting.safe_secret_key_base new_token = $redis.without_namespace.get(GlobalSetting::REDIS_SECRET_KEY) expect(new_token).to eq(nil) freeze_time Time.now + 11 GlobalSetting.safe_secret_key_base new_token = $redis.without_namespace.get(GlobalSetting::REDIS_SECRET_KEY) expect(new_token).to eq(token) end end describe '.add_default' do after do class < # this is a comment\n") f.close provider = GlobalSetting::FileProvider.from(f.path) expect(provider.lookup(:a, "")).to eq 500 f.unlink end end