diff --git a/.gitignore b/.gitignore index c44c98cb..e92219a8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tmp .sass-cache Gemfile.lock *.gem +.byebug_history \ No newline at end of file diff --git a/Appraisals b/Appraisals index f9e72d62..324e0253 100644 --- a/Appraisals +++ b/Appraisals @@ -31,7 +31,7 @@ end appraise 'rails-5.2' do gem 'activerecord-jdbcsqlite3-adapter', '~> 52.5', platform: :jruby gem 'bootsnap', '~> 1.4' - gem 'rails', '5.2.4.3' + gem 'rails', '5.2.5' gem 'rspec-rails', '~> 3.7' gem 'sqlite3', '< 1.4.0', platform: :ruby end @@ -41,7 +41,7 @@ if (RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0') || RUBY_ENGINE != 'ruby' appraise 'rails-6.0' do gem 'activerecord-jdbcsqlite3-adapter', '~> 60.1', platform: :jruby gem 'bootsnap', '~> 1.4' - gem 'rails', '6.0.3.1' + gem 'rails', '6.0.3.6' gem 'rspec-rails', '~> 3.7' gem 'sqlite3', '~> 1.4.0', platform: :ruby end @@ -49,6 +49,20 @@ else puts 'Skipping rails-6.0 for Ruby < 2.5' end +# Rails 6.x requires Ruby >= 2.5.0 +if (RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0') || RUBY_ENGINE != 'ruby' + appraise 'rails-6.1' do + gem 'activerecord-jdbcsqlite3-adapter', '~> 60.1', platform: :jruby + gem 'bootsnap', '~> 1.4' + gem 'rails', '6.1.3.1' + gem 'rspec-rails', '~> 3.7' + gem 'sqlite3', '~> 1.4.0', platform: :ruby + end +else + puts 'Skipping rails-6.0 for Ruby < 2.5' +end + + appraise 'sinatra' do gem 'sinatra', '2.0.8.1' end diff --git a/CHANGELOG.md b/CHANGELOG.md index badb98b4..c19630fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ ### Changes +* Add option to specify environment (default: `RAILS_ENV`) ([#290](https://github.com/rubyconfig/config/pull/290)) * Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228)) * Add exit! to reserved keywords ([#289](https://github.com/railsconfig/config/issues/289)) diff --git a/README.md b/README.md index fea1309d..cbb2292a 100644 --- a/README.md +++ b/README.md @@ -12,25 +12,25 @@ Config helps you easily manage environment specific settings in an easy and usab ## Features -* simple YAML config files -* config files support ERB -* config files support inheritance and multiple environments -* access config information via convenient object member notation -* support for multi-level settings (`Settings.group.subgroup.setting`) -* local developer settings ignored when committing the code +- simple YAML config files +- config files support ERB +- config files support inheritance and multiple environments +- access config information via convenient object member notation +- support for multi-level settings (`Settings.group.subgroup.setting`) +- local developer settings ignored when committing the code ## Compatibility Current version supports and is [tested](.github/workflows/tests.yml#L19) for the following interpreters and frameworks: -* Interpreters - * [Ruby](https://www.ruby-lang.org) `>= 2.4` - * [JRuby](https://www.jruby.org) `>= 9.2` - * [TruffleRuby](https://github.com/oracle/truffleruby) `>= 19.3` -* Application frameworks - * Rails `>= 4.2`, `5` and `6` - * Padrino - * Sinatra +- Interpreters + - [Ruby](https://www.ruby-lang.org) `>= 2.4` + - [JRuby](https://www.jruby.org) `>= 9.2` + - [TruffleRuby](https://github.com/oracle/truffleruby) `>= 19.3` +- Application frameworks + - Rails `>= 4.2`, `5` and `6` + - Padrino + - Sinatra For Ruby `2.0` to `2.3` or Rails `3` to `4.1` use version `1.x` of this gem. For older versions of Rails or Ruby use [AppConfig](http://github.com/fredwu/app_config). @@ -52,6 +52,8 @@ which will generate customizable config file `config/initializers/config.rb` and You can now edit them to adjust to your needs. +> Note: By default, the config environment will match the Rails environment (`Rails.env`). This can be changed by setting `config.environment`. + ### Installing on Padrino Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config` @@ -209,21 +211,21 @@ Embedded Ruby is allowed in the YAML configuration files. ERB will be evaluated Consider the two following config files. -* ```#{Rails.root}/config/settings.yml``` +- `#{Rails.root}/config/settings.yml` ```yaml size: 1 server: google.com ``` -* ```#{Rails.root}/config/environments/development.yml``` +- `#{Rails.root}/config/environments/development.yml` ```yaml size: 2 computed: <%= 1 + 2 + 3 %> section: size: 3 - servers: [ {name: yahoo.com}, {name: amazon.com} ] + servers: [{ name: yahoo.com }, { name: amazon.com }] ``` Notice that the environment specific config entries overwrite the common entries. @@ -267,15 +269,16 @@ After installing `Config` in Rails, you will find automatically generated file t ### General -* `const_name` - name of the object holing you settings. Default: `'Settings'` -* `evaluate_erb_in_yaml` - evaluate ERB in YAML config files. Set to false if the config file contains ERB that should not be evaluated at load time. Default: `true` +- `const_name` - name of the object holding you settings. Default: `'Settings'` +- `environment` - define current environment, affecting which settings file will be loaded. Default: `Rails.env` +- `evaluate_erb_in_yaml` - evaluate ERB in YAML config files. Set to false if the config file contains ERB that should not be evaluated at load time. Default: `true` ### Merge customization -* `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true` -* `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false` -* `knockout_prefix` - ability to remove elements of the array set in earlier loaded settings file. Makes sense only when `overwrite_arrays = false`, otherwise array settings would be overwritten by default. Default: `nil` -* `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`. +- `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true` +- `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false` +- `knockout_prefix` - ability to remove elements of the array set in earlier loaded settings file. Makes sense only when `overwrite_arrays = false`, otherwise array settings would be overwritten by default. Default: `nil` +- `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`. ```ruby # merge_nil_values is true by default @@ -448,12 +451,12 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her You can customize how environment variables are processed: -* `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive) -* `env_separator` (default: `'.'`) - what string to use as level separator - default value of `.` works well with Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using dots in variable names might not be allowed (eg. Bash) -* `env_converter` (default: `:downcase`) - how to process variables names: - * `nil` - no change - * `:downcase` - convert to lower case -* `env_parse_values` (default: `true`) - try to parse values to a correct type (`Boolean`, `Integer`, `Float`, `String`) +- `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive) +- `env_separator` (default: `'.'`) - what string to use as level separator - default value of `.` works well with Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using dots in variable names might not be allowed (eg. Bash) +- `env_converter` (default: `:downcase`) - how to process variables names: + - `nil` - no change + - `:downcase` - convert to lower case +- `env_parse_values` (default: `true`) - try to parse values to a correct type (`Boolean`, `Integer`, `Float`, `String`) For instance, given the following environment: @@ -492,7 +495,7 @@ For example, the plaintext secret might look like this: ```json { "Settings.foo": "hello", - "Settings.bar": "world", + "Settings.bar": "world" } ``` @@ -535,10 +538,10 @@ Any and all contributions offered in any form, past present or future are unders ## Authors -* [Piotr Kuczynski](http://github.com/pkuczynski) -* [Fred Wu](http://github.com/fredwu) -* [Jacques Crocker](http://github.com/railsjedi) -* Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro) +- [Piotr Kuczynski](http://github.com/pkuczynski) +- [Fred Wu](http://github.com/fredwu) +- [Jacques Crocker](http://github.com/railsjedi) +- Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro) ## Contributors diff --git a/config.gemspec b/config.gemspec index d59ced0c..e3beab32 100644 --- a/config.gemspec +++ b/config.gemspec @@ -37,9 +37,12 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n" # Default RSpec run will test against latest Rails app unless ENV['APPRAISAL_INITIALIZED'] || ENV['GITHUB_ACTIONS'] - gems_to_install = /gem "(.*?)", "(.*?)"(?!, platform: (?!\[:ruby\]))/ - File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version| - s.add_development_dependency name, version + gems_to_install = /gem "(.*?)", "(.*?)"(?:, platform: \:(.*))?/ + + File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, platform| + if platform.nil? || platform.to_s == RUBY_ENGINE + s.add_development_dependency name, version + end end end @@ -50,5 +53,6 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n" # Static code analysis to be used locally s.add_development_dependency 'mdl', '~> 0.9', '>= 0.9.0' s.add_development_dependency 'rubocop', '~> 0.85.0' + s.add_development_dependency 'byebug', '~> 11.1.3' end end diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile index ee33c30d..5ed02962 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 52.5", platform: :jruby gem "bootsnap", "~> 1.4" -gem "rails", "5.2.4.3" +gem "rails", "5.2.5" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index f42298fc..c55502f9 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 60.1", platform: :jruby gem "bootsnap", "~> 1.4" -gem "rails", "6.0.3.1" +gem "rails", "6.0.3.6" gem "rspec-rails", "~> 3.7" gem "sqlite3", "~> 1.4.0", platform: :ruby diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 00000000..d08e66b7 --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord-jdbcsqlite3-adapter", "~> 60.1", platform: :jruby +gem "bootsnap", "~> 1.4" +gem "rails", "6.1.3.1" +gem "rspec-rails", "~> 3.7" +gem "sqlite3", "~> 1.4.0", platform: :ruby + +gemspec path: "../" diff --git a/lib/config.rb b/lib/config.rb index 7d8588e2..99a04848 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -25,6 +25,7 @@ module Config overwrite_arrays: true, merge_hash_arrays: false, validation_contract: nil, + environment: nil, evaluate_erb_in_yaml: true ) @@ -44,7 +45,6 @@ def self.load_files(*files) end config.add_source!(Sources::EnvSource.new(ENV)) if Config.use_env - config.load! config end diff --git a/lib/config/integrations/rails/railtie.rb b/lib/config/integrations/rails/railtie.rb index 460fa5f3..6748c116 100644 --- a/lib/config/integrations/rails/railtie.rb +++ b/lib/config/integrations/rails/railtie.rb @@ -9,7 +9,7 @@ def preload # Parse the settings before any of the initializers Config.load_and_set_settings( - Config.setting_files(::Rails.root.join('config'), ::Rails.env) + Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym) ) end diff --git a/lib/generators/config/templates/config.rb b/lib/generators/config/templates/config.rb index 8c4347a9..8608b1b8 100644 --- a/lib/generators/config/templates/config.rb +++ b/lib/generators/config/templates/config.rb @@ -15,6 +15,10 @@ # # config.overwrite_arrays = true + # Defines current environment, affecting which settings file will be loaded. + # Default: `::Rails.env` + # config.environment = ENV.fetch('ENVIRONMENT', :development) + # Load environment variables from the `ENV` object and override any settings defined in files. # # config.use_env = false diff --git a/spec/app/rails_4.2/config/database.yml b/spec/app/rails_4.2/config/database.yml index 246b40d9..1c1a37ca 100644 --- a/spec/app/rails_4.2/config/database.yml +++ b/spec/app/rails_4.2/config/database.yml @@ -11,15 +11,15 @@ default: &default development: <<: *default - database: <%= Settings.databases.development.database %> + database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default - database: <%= Settings.databases.test.database %> + database: db/test.sqlite3 production: <<: *default - database: <%= Settings.databases.production.database %> + database: db/production.sqlite3 diff --git a/spec/app/rails_4.2/config/initializers/config.rb b/spec/app/rails_4.2/config/initializers/config.rb new file mode 100644 index 00000000..232f3f4d --- /dev/null +++ b/spec/app/rails_4.2/config/initializers/config.rb @@ -0,0 +1,8 @@ +# This is how you would initialize the config object +# when not using the default rails environments + +Config.setup do |config| + config.environment = 'any_env' + config.const_name = 'RailtieSettings' + config.env_parse_values = true +end diff --git a/spec/app/rails_4.2/config/settings/any_env.yml b/spec/app/rails_4.2/config/settings/any_env.yml new file mode 100644 index 00000000..5c8b8db1 --- /dev/null +++ b/spec/app/rails_4.2/config/settings/any_env.yml @@ -0,0 +1,8 @@ +# +# An environment file that doesn't follow +# the default rails environments +# +some_api: + scheme: https + host: some-non-rails-environment + path: /some-path diff --git a/spec/app/rails_5.0/config/initializers/config.rb b/spec/app/rails_5.0/config/initializers/config.rb new file mode 100644 index 00000000..232f3f4d --- /dev/null +++ b/spec/app/rails_5.0/config/initializers/config.rb @@ -0,0 +1,8 @@ +# This is how you would initialize the config object +# when not using the default rails environments + +Config.setup do |config| + config.environment = 'any_env' + config.const_name = 'RailtieSettings' + config.env_parse_values = true +end diff --git a/spec/app/rails_5.0/config/settings/any_env.yml b/spec/app/rails_5.0/config/settings/any_env.yml new file mode 100644 index 00000000..5c8b8db1 --- /dev/null +++ b/spec/app/rails_5.0/config/settings/any_env.yml @@ -0,0 +1,8 @@ +# +# An environment file that doesn't follow +# the default rails environments +# +some_api: + scheme: https + host: some-non-rails-environment + path: /some-path diff --git a/spec/app/rails_5.1/config/initializers/config.rb b/spec/app/rails_5.1/config/initializers/config.rb new file mode 100644 index 00000000..232f3f4d --- /dev/null +++ b/spec/app/rails_5.1/config/initializers/config.rb @@ -0,0 +1,8 @@ +# This is how you would initialize the config object +# when not using the default rails environments + +Config.setup do |config| + config.environment = 'any_env' + config.const_name = 'RailtieSettings' + config.env_parse_values = true +end diff --git a/spec/app/rails_5.1/config/settings/any_env.yml b/spec/app/rails_5.1/config/settings/any_env.yml new file mode 100644 index 00000000..5c8b8db1 --- /dev/null +++ b/spec/app/rails_5.1/config/settings/any_env.yml @@ -0,0 +1,8 @@ +# +# An environment file that doesn't follow +# the default rails environments +# +some_api: + scheme: https + host: some-non-rails-environment + path: /some-path diff --git a/spec/app/rails_5.2/config/initializers/config.rb b/spec/app/rails_5.2/config/initializers/config.rb new file mode 100644 index 00000000..232f3f4d --- /dev/null +++ b/spec/app/rails_5.2/config/initializers/config.rb @@ -0,0 +1,8 @@ +# This is how you would initialize the config object +# when not using the default rails environments + +Config.setup do |config| + config.environment = 'any_env' + config.const_name = 'RailtieSettings' + config.env_parse_values = true +end diff --git a/spec/app/rails_5.2/config/settings/any_env.yml b/spec/app/rails_5.2/config/settings/any_env.yml new file mode 100644 index 00000000..5c8b8db1 --- /dev/null +++ b/spec/app/rails_5.2/config/settings/any_env.yml @@ -0,0 +1,8 @@ +# +# An environment file that doesn't follow +# the default rails environments +# +some_api: + scheme: https + host: some-non-rails-environment + path: /some-path diff --git a/spec/app/rails_6.0/config/initializers/config.rb b/spec/app/rails_6.0/config/initializers/config.rb new file mode 100644 index 00000000..9969cdd1 --- /dev/null +++ b/spec/app/rails_6.0/config/initializers/config.rb @@ -0,0 +1,9 @@ +# This is how you would initialize the config object +# when not using the default rails environments + +Config.setup do |config| + config.environment = 'any_env' + config.const_name = 'RailtieSettings' + config.env_parse_values = true +end + diff --git a/spec/app/rails_6.0/config/settings/any_env.yml b/spec/app/rails_6.0/config/settings/any_env.yml new file mode 100644 index 00000000..5c8b8db1 --- /dev/null +++ b/spec/app/rails_6.0/config/settings/any_env.yml @@ -0,0 +1,8 @@ +# +# An environment file that doesn't follow +# the default rails environments +# +some_api: + scheme: https + host: some-non-rails-environment + path: /some-path diff --git a/spec/app/rails_6.1/Gemfile b/spec/app/rails_6.1/Gemfile new file mode 100644 index 00000000..6d75aa0f --- /dev/null +++ b/spec/app/rails_6.1/Gemfile @@ -0,0 +1,40 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.6.6' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' +gem 'rails', '~> 6.1.3', '>= 6.1.3.1' +# Use sqlite3 as the database for Active Record +gem 'sqlite3', '~> 1.4' +# Use Puma as the app server +gem 'puma', '~> 5.0' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +# gem 'jbuilder', '~> 2.7' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use Active Model has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Active Storage variant +# gem 'image_processing', '~> 1.2' + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.4.4', require: false + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible +# gem 'rack-cors' + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + gem 'listen', '~> 3.3' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/spec/app/rails_6.1/Rakefile b/spec/app/rails_6.1/Rakefile new file mode 100644 index 00000000..9a5ea738 --- /dev/null +++ b/spec/app/rails_6.1/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/spec/app/rails_6.1/app/controllers/application_controller.rb b/spec/app/rails_6.1/app/controllers/application_controller.rb new file mode 100644 index 00000000..4ac8823b --- /dev/null +++ b/spec/app/rails_6.1/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/spec/app/rails_6.1/app/jobs/application_job.rb b/spec/app/rails_6.1/app/jobs/application_job.rb new file mode 100644 index 00000000..d394c3d1 --- /dev/null +++ b/spec/app/rails_6.1/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/spec/app/rails_6.1/app/models/application_record.rb b/spec/app/rails_6.1/app/models/application_record.rb new file mode 100644 index 00000000..10a4cba8 --- /dev/null +++ b/spec/app/rails_6.1/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/spec/app/rails_6.1/bin/bundle b/spec/app/rails_6.1/bin/bundle new file mode 100755 index 00000000..524dfd3f --- /dev/null +++ b/spec/app/rails_6.1/bin/bundle @@ -0,0 +1,105 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 || ">= 0.a" + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= begin + env_var_version || cli_arg_version || + lockfile_version || "#{Gem::Requirement.default}.a" + end + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + # must dup string for RG < 1.8 compatibility + activate_bundler(bundler_version.dup) + end + + def activate_bundler(bundler_version) + if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") + bundler_version = "< 2" + end + gem_error = activation_error_handling do + gem "bundler", bundler_version + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/spec/app/rails_6.1/bin/rails b/spec/app/rails_6.1/bin/rails new file mode 100755 index 00000000..21d3e02d --- /dev/null +++ b/spec/app/rails_6.1/bin/rails @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +load File.expand_path("spring", __dir__) +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/spec/app/rails_6.1/bin/rake b/spec/app/rails_6.1/bin/rake new file mode 100755 index 00000000..7327f471 --- /dev/null +++ b/spec/app/rails_6.1/bin/rake @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +load File.expand_path("spring", __dir__) +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/spec/app/rails_6.1/bin/setup b/spec/app/rails_6.1/bin/setup new file mode 100755 index 00000000..57923026 --- /dev/null +++ b/spec/app/rails_6.1/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:prepare' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/spec/app/rails_6.1/bin/spring b/spec/app/rails_6.1/bin/spring new file mode 100755 index 00000000..b4147e84 --- /dev/null +++ b/spec/app/rails_6.1/bin/spring @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) + gem "bundler" + require "bundler" + + # Load Spring without loading other gems in the Gemfile, for speed. + Bundler.locked_gems&.specs&.find { |spec| spec.name == "spring" }&.tap do |spring| + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem "spring", spring.version + require "spring/binstub" + rescue Gem::LoadError + # Ignore when Spring is not installed. + end +end diff --git a/spec/app/rails_6.1/config.ru b/spec/app/rails_6.1/config.ru new file mode 100644 index 00000000..4a3c09a6 --- /dev/null +++ b/spec/app/rails_6.1/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/spec/app/rails_6.1/config/application.rb b/spec/app/rails_6.1/config/application.rb new file mode 100644 index 00000000..fdf024bc --- /dev/null +++ b/spec/app/rails_6.1/config/application.rb @@ -0,0 +1,40 @@ +require_relative "boot" + +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +# require "active_storage/engine" +require "action_controller/railtie" +# require "action_mailer/railtie" +# require "action_mailbox/engine" +# require "action_text/engine" +require "action_view/railtie" +# require "action_cable/engine" +# require "sprockets/railtie" +# require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Rails61 + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 6.1 + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/spec/app/rails_6.1/config/boot.rb b/spec/app/rails_6.1/config/boot.rb new file mode 100644 index 00000000..3cda23b4 --- /dev/null +++ b/spec/app/rails_6.1/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/spec/app/rails_6.1/config/credentials.yml.enc b/spec/app/rails_6.1/config/credentials.yml.enc new file mode 100644 index 00000000..c5e4a800 --- /dev/null +++ b/spec/app/rails_6.1/config/credentials.yml.enc @@ -0,0 +1 @@ +JT+Q9/Tp5zKe/BlwDT0Ms6sY5jRjXQo2S6iP7B7kgqjIejp1BFX1mBA+5Zj2pLy5h1RSgqx53uUV/PbwHutmNhoDNzIVgic+CWpqslW2/7QueTHf9vBTS4ild7TrORM/w82/OpvkicDqPK4T1H8ynj2/Jr13EcRayoBVipa5K80y0n+umrFx7IogHRCTdkp06iXkPJxxR3FK+NDexEoZtSLBz7x4aXhUpuY1wrug47wQmVwWLjDKC+sq97lEPd6Pge/FC4ee7VDnwiGGg2SlfF3e7OpO6dWbhpWo0HYdb1CecMfRoClQGA4qmrLS17Fx2ICOXuI1BNK1FF3B+u+mAf3Fftg+kagjZApKKLW6Gk9ojX5gS54rMfp04pwiAOSgSe0ybLNPyLAb99EypMJT4TNNPq/mEMSDIBO7--QF5MaqmHyPb8aPJF--TVX6+rodI8PFGlHCeiIIkA== \ No newline at end of file diff --git a/spec/app/rails_6.1/config/database.yml b/spec/app/rails_6.1/config/database.yml new file mode 100644 index 00000000..4a8a1b26 --- /dev/null +++ b/spec/app/rails_6.1/config/database.yml @@ -0,0 +1,25 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/spec/app/rails_6.1/config/environment.rb b/spec/app/rails_6.1/config/environment.rb new file mode 100644 index 00000000..cac53157 --- /dev/null +++ b/spec/app/rails_6.1/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/spec/app/rails_6.1/config/environments/development.rb b/spec/app/rails_6.1/config/environments/development.rb new file mode 100644 index 00000000..231c2a6a --- /dev/null +++ b/spec/app/rails_6.1/config/environments/development.rb @@ -0,0 +1,66 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true +end diff --git a/spec/app/rails_6.1/config/environments/production.rb b/spec/app/rails_6.1/config/environments/production.rb new file mode 100644 index 00000000..7eac74a5 --- /dev/null +++ b/spec/app/rails_6.1/config/environments/production.rb @@ -0,0 +1,113 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "rails_6_1_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session +end diff --git a/spec/app/rails_6.1/config/environments/test.rb b/spec/app/rails_6.1/config/environments/test.rb new file mode 100644 index 00000000..39eb9be7 --- /dev/null +++ b/spec/app/rails_6.1/config/environments/test.rb @@ -0,0 +1,50 @@ +require "active_support/core_ext/integer/time" + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + config.cache_classes = false + config.action_view.cache_template_loading = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true +end diff --git a/spec/app/rails_6.1/config/initializers/application_controller_renderer.rb b/spec/app/rails_6.1/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000..89d2efab --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/spec/app/rails_6.1/config/initializers/backtrace_silencers.rb b/spec/app/rails_6.1/config/initializers/backtrace_silencers.rb new file mode 100644 index 00000000..33699c30 --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/backtrace_silencers.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code +# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". +Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] diff --git a/spec/app/rails_6.1/config/initializers/config.rb b/spec/app/rails_6.1/config/initializers/config.rb new file mode 100644 index 00000000..9969cdd1 --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/config.rb @@ -0,0 +1,9 @@ +# This is how you would initialize the config object +# when not using the default rails environments + +Config.setup do |config| + config.environment = 'any_env' + config.const_name = 'RailtieSettings' + config.env_parse_values = true +end + diff --git a/spec/app/rails_6.1/config/initializers/cors.rb b/spec/app/rails_6.1/config/initializers/cors.rb new file mode 100644 index 00000000..3b1c1b5e --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/spec/app/rails_6.1/config/initializers/filter_parameter_logging.rb b/spec/app/rails_6.1/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..4b34a036 --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/spec/app/rails_6.1/config/initializers/inflections.rb b/spec/app/rails_6.1/config/initializers/inflections.rb new file mode 100644 index 00000000..ac033bf9 --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/spec/app/rails_6.1/config/initializers/mime_types.rb b/spec/app/rails_6.1/config/initializers/mime_types.rb new file mode 100644 index 00000000..dc189968 --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/spec/app/rails_6.1/config/initializers/wrap_parameters.rb b/spec/app/rails_6.1/config/initializers/wrap_parameters.rb new file mode 100644 index 00000000..bbfc3961 --- /dev/null +++ b/spec/app/rails_6.1/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/spec/app/rails_6.1/config/locales/en.yml b/spec/app/rails_6.1/config/locales/en.yml new file mode 100644 index 00000000..cf9b342d --- /dev/null +++ b/spec/app/rails_6.1/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/spec/app/rails_6.1/config/routes.rb b/spec/app/rails_6.1/config/routes.rb new file mode 100644 index 00000000..c06383a1 --- /dev/null +++ b/spec/app/rails_6.1/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html +end diff --git a/spec/app/rails_6.1/config/settings/any_env.yml b/spec/app/rails_6.1/config/settings/any_env.yml new file mode 100644 index 00000000..5c8b8db1 --- /dev/null +++ b/spec/app/rails_6.1/config/settings/any_env.yml @@ -0,0 +1,8 @@ +# +# An environment file that doesn't follow +# the default rails environments +# +some_api: + scheme: https + host: some-non-rails-environment + path: /some-path diff --git a/spec/app/rails_6.1/db/seeds.rb b/spec/app/rails_6.1/db/seeds.rb new file mode 100644 index 00000000..f3a0480d --- /dev/null +++ b/spec/app/rails_6.1/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/spec/app/rails_6.1/public/robots.txt b/spec/app/rails_6.1/public/robots.txt new file mode 100644 index 00000000..c19f78ab --- /dev/null +++ b/spec/app/rails_6.1/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/config_env_spec.rb b/spec/config_env_spec.rb index 65e7da8b..97d7a4d3 100644 --- a/spec/config_env_spec.rb +++ b/spec/config_env_spec.rb @@ -1,8 +1,12 @@ require 'spec_helper' describe Config::Options do + before :all do + Config.load_and_set_settings "#{fixture_path}/settings.yml", "#{fixture_path}/multilevel.yml" + end + before :each do - Config.reset + Config.reset end context 'when overriding settings via ENV variables is enabled' do @@ -16,7 +20,6 @@ before :each do ENV.clear - Config.use_env = true Config.env_prefix = nil Config.env_separator = '.' @@ -208,9 +211,7 @@ ENV['Settings.new_var'] = 'value' expect(config.new_var).to eq('value') - Config.reload! - expect(config.new_var).to eq('value') end diff --git a/spec/railtie_spec.rb b/spec/railtie_spec.rb new file mode 100644 index 00000000..ba49605a --- /dev/null +++ b/spec/railtie_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +context 'when a the environment config is set' do + it 'should load a file that matches that environment' do + if defined?(::Rails) + expect(RailtieSettings.some_api.scheme).to eq 'https' + expect(RailtieSettings.some_api.host).to eq 'some-non-rails-environment' + expect(RailtieSettings.some_api.path).to eq '/some-path' + end + end +end + + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4e802328..cda8dd97 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,7 @@ +unless ENV['GITHUB_ACTIONS'] + require 'byebug' +end + ENV['RAILS_ENV'] ||= 'test' puts "RUBY_ENGINE: #{RUBY_ENGINE}" diff --git a/spec/support/rails_helper.rb b/spec/support/rails_helper.rb index 920597f3..f7e7637e 100644 --- a/spec/support/rails_helper.rb +++ b/spec/support/rails_helper.rb @@ -14,7 +14,7 @@ def load_env(filename) def config_available? where = caller[0].split(':')[0].gsub(File.expand_path(File.dirname(__FILE__)), '') - if defined?(::Settings) + if defined?(::Settings) || defined?(::RailtieSettings) puts "Config available in #{where}" else raise "Config not available in #{where}"