|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative 'helper' |
| 4 | + |
| 5 | +describe 'ActiveRecordShards' do |
| 6 | + describe '.app_env' do |
| 7 | + before do |
| 8 | + if defined?(Rails) || ENV['RAILS_ENV'] || defined?(APP_ENV) || ENV['APP_ENV'] |
| 9 | + raise "Tests in #{__FILE__} will overwrite environment constants, please update them to avoid conflicts" |
| 10 | + end |
| 11 | + |
| 12 | + Object.send(:remove_const, 'RAILS_ENV') |
| 13 | + end |
| 14 | + |
| 15 | + after { Object.const_set('RAILS_ENV', 'test') } |
| 16 | + |
| 17 | + describe 'Rails.env' do |
| 18 | + before do |
| 19 | + class Rails |
| 20 | + def self.env |
| 21 | + 'environment from Rails.env' |
| 22 | + end |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + after { Object.send(:remove_const, 'Rails') } |
| 27 | + |
| 28 | + it 'looks for Rails.env' do |
| 29 | + assert_equal 'environment from Rails.env', ActiveRecordShards.app_env |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe 'RAILS_ENV' do |
| 34 | + before { Object.const_set('RAILS_ENV', 'environment from RAILS_ENV') } |
| 35 | + after { Object.send(:remove_const, 'RAILS_ENV') } |
| 36 | + |
| 37 | + it 'looks for RAILS_ENV' do |
| 38 | + assert_equal 'environment from RAILS_ENV', ActiveRecordShards.app_env |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe "ENV['RAILS_ENV']" do |
| 43 | + before { ENV['RAILS_ENV'] = "environment from ENV['RAILS_ENV']" } |
| 44 | + after { ENV.delete('RAILS_ENV') } |
| 45 | + |
| 46 | + it 'looks for RAILS_ENV' do |
| 47 | + assert_equal "environment from ENV['RAILS_ENV']", ActiveRecordShards.app_env |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + describe 'APP_ENV' do |
| 52 | + before { Object.const_set('APP_ENV', 'environment from APP_ENV') } |
| 53 | + after { Object.send(:remove_const, 'APP_ENV') } |
| 54 | + |
| 55 | + it 'looks for APP_ENV' do |
| 56 | + assert_equal 'environment from APP_ENV', ActiveRecordShards.app_env |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe "ENV['APP_ENV']" do |
| 61 | + before { ENV['APP_ENV'] = "environment from ENV['APP_ENV']" } |
| 62 | + after { ENV.delete('APP_ENV') } |
| 63 | + |
| 64 | + it 'looks for APP_ENV' do |
| 65 | + assert_equal "environment from ENV['APP_ENV']", ActiveRecordShards.app_env |
| 66 | + end |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments