From 14830024df059ddfcdbcdfee9d1abd42e473d528 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Tue, 3 Nov 2020 17:22:48 +0000 Subject: [PATCH 01/33] Created the new config for using a different envfironment, instead of Rails.env Started work on changing how the keys are converted from the environment into the config, when using the underscore seperator, it should work as expected - it currently doesn't --- lib/config.rb | 3 +- lib/config/integrations/rails/railtie.rb | 4 +-- lib/config/options.rb | 44 +++++++++++++++++++---- lib/generators/config/templates/config.rb | 4 +++ spec/fixtures/from_env.yml | 3 ++ spec/options_spec.rb | 19 ++++++++++ 6 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 spec/fixtures/from_env.yml diff --git a/lib/config.rb b/lib/config.rb index 471b113d..24b24918 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -23,7 +23,8 @@ module Config merge_nil_values: true, overwrite_arrays: true, merge_hash_arrays: false, - validation_contract: nil + validation_contract: nil, + environment: nil ) def self.setup diff --git a/lib/config/integrations/rails/railtie.rb b/lib/config/integrations/rails/railtie.rb index 460fa5f3..8e105b3a 100644 --- a/lib/config/integrations/rails/railtie.rb +++ b/lib/config/integrations/rails/railtie.rb @@ -8,8 +8,8 @@ def preload require initializer if File.exist?(initializer) # Parse the settings before any of the initializers - Config.load_and_set_settings( - Config.setting_files(::Rails.root.join('config'), ::Rails.env) + Config.load_and_set_settings( + Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym) ) end diff --git a/lib/config/options.rb b/lib/config/options.rb index b139a26c..e8fd7c2b 100644 --- a/lib/config/options.rb +++ b/lib/config/options.rb @@ -38,13 +38,17 @@ def reload_env! ENV.each do |variable, value| separator = Config.env_separator - prefix = (Config.env_prefix || Config.const_name).to_s.split(separator) + prefix = (Config.env_prefix || Config.const_name).to_s + + # remove prefix + variable = variable.gsub(prefix, '') - keys = variable.to_s.split(separator) + # split the environment variable name based on the keys we have + new_keys = __lookup_key(variable.to_s.split(separator), separator) - next if keys.shift(prefix.size) != prefix + next if new_keys.shift(prefix.size) != prefix - keys.map! { |key| + new_keys.map! { |key| case Config.env_converter when :downcase then key.downcase.to_sym @@ -55,11 +59,11 @@ def reload_env! end } - leaf = keys[0...-1].inject(hash) { |h, key| + leaf = new_keys[0...-1].inject(hash) { |h, key| h[key] ||= {} } - leaf[keys.last] = Config.env_parse_values ? __value(value) : value + leaf[new_keys.last] = Config.env_parse_values ? __value(value) : value end merge!(hash) @@ -226,5 +230,33 @@ def __value(v) Integer(v) rescue Float(v) rescue v end end + + def __lookup_key(env_var_split_keys, split_char, found_keys = []) + # To allow us to prefix keys with the same seperation character that exists in the config key, we need to search for the keys + lookup_key = nil + + search_keys = env_var_split_keys.dup + (0..(search_keys.length - 1)).each do + byebug + lookup_key = keys.find{|k| k.to_sym == search_keys.join(split_char) } + break if !lookup_key.nil? + + search_keys.pop + end + + found_keys ||= [] + if !lookup_key.nil? + # we've found a key in our config that matches our env key, store this, and look inside this for the rest + found_keys << lookup_key + # get the new search key + env_key = env_var_split_keys.join(split_char) + env_key = env_key.gsub(lookup_key, split_char) + search_keys = env_key.split(split_char) + + # call myself to get the next key + found_keys = __lookup_key(search_keys, split_char, found_keys) + end + found_keys + end end end diff --git a/lib/generators/config/templates/config.rb b/lib/generators/config/templates/config.rb index 7c82c5f8..fb02aeea 100644 --- a/lib/generators/config/templates/config.rb +++ b/lib/generators/config/templates/config.rb @@ -15,6 +15,10 @@ # # config.overwrite_arrays = true + # Use a different methhod of determining the current environment + # defaults to ::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/fixtures/from_env.yml b/spec/fixtures/from_env.yml new file mode 100644 index 00000000..50e06b8b --- /dev/null +++ b/spec/fixtures/from_env.yml @@ -0,0 +1,3 @@ +some_seperated_key: + to_overide: + from_the_environment: "NOT SET" diff --git a/spec/options_spec.rb b/spec/options_spec.rb index 0a94061c..ca4f9a27 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -221,4 +221,23 @@ end + context "values from env with conflicting seperator" do + before { Config.setup { |config| + config.env_prefix = 'SETTINGS' + config.env_separator = '_' + config.env_converter = :downcase + config.env_parse_values = true + } } + + # some_seperated_key: + # to_overide: + # from_the_environment: "NOT SET" + + it 'should find the correct keys' do + ENV["SETTINGS_SOME_SEPERATED_KEY_TO_OVERIDE_FROM_THE_ENVIRONMENT"] = "test" + Config.load_files("#{fixture_path}/from_env.yml") + expect(config.some_seperated_key.to_overide.from_the_environment).to eq("test") + end + end + end From 544832b390cc8a126bf1bdd969e342fa652bb3a0 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 25 Nov 2020 21:41:42 +0000 Subject: [PATCH 02/33] Reverting work on additional feature and addressing PR comments --- config.gemspec | 10 +++-- lib/config/options.rb | 46 ++++------------------- lib/generators/config/templates/config.rb | 2 +- spec/fixtures/from_env.yml | 3 -- spec/options_spec.rb | 19 ---------- 5 files changed, 15 insertions(+), 65 deletions(-) delete mode 100644 spec/fixtures/from_env.yml diff --git a/config.gemspec b/config.gemspec index d59ced0c..e2977ea1 100644 --- a/config.gemspec +++ b/config.gemspec @@ -37,9 +37,13 @@ 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? + s.add_development_dependency name, version + elsif platform.to_s == RUBY_ENGINE + s.add_development_dependency name, version + end end end diff --git a/lib/config/options.rb b/lib/config/options.rb index e8fd7c2b..05f1d9fe 100644 --- a/lib/config/options.rb +++ b/lib/config/options.rb @@ -38,17 +38,13 @@ def reload_env! ENV.each do |variable, value| separator = Config.env_separator - prefix = (Config.env_prefix || Config.const_name).to_s - - # remove prefix - variable = variable.gsub(prefix, '') + prefix = (Config.env_prefix || Config.const_name).to_s.split(separator) - # split the environment variable name based on the keys we have - new_keys = __lookup_key(variable.to_s.split(separator), separator) + keys = variable.to_s.split(separator) - next if new_keys.shift(prefix.size) != prefix + next if keys.shift(prefix.size) != prefix - new_keys.map! { |key| + keys.map! { |key| case Config.env_converter when :downcase then key.downcase.to_sym @@ -59,11 +55,11 @@ def reload_env! end } - leaf = new_keys[0...-1].inject(hash) { |h, key| + leaf = keys[0...-1].inject(hash) { |h, key| h[key] ||= {} } - leaf[new_keys.last] = Config.env_parse_values ? __value(value) : value + leaf[keys.last] = Config.env_parse_values ? __value(value) : value end merge!(hash) @@ -230,33 +226,5 @@ def __value(v) Integer(v) rescue Float(v) rescue v end end - - def __lookup_key(env_var_split_keys, split_char, found_keys = []) - # To allow us to prefix keys with the same seperation character that exists in the config key, we need to search for the keys - lookup_key = nil - - search_keys = env_var_split_keys.dup - (0..(search_keys.length - 1)).each do - byebug - lookup_key = keys.find{|k| k.to_sym == search_keys.join(split_char) } - break if !lookup_key.nil? - - search_keys.pop - end - - found_keys ||= [] - if !lookup_key.nil? - # we've found a key in our config that matches our env key, store this, and look inside this for the rest - found_keys << lookup_key - # get the new search key - env_key = env_var_split_keys.join(split_char) - env_key = env_key.gsub(lookup_key, split_char) - search_keys = env_key.split(split_char) - - # call myself to get the next key - found_keys = __lookup_key(search_keys, split_char, found_keys) - end - found_keys - end end -end +end \ No newline at end of file diff --git a/lib/generators/config/templates/config.rb b/lib/generators/config/templates/config.rb index fb02aeea..426d3805 100644 --- a/lib/generators/config/templates/config.rb +++ b/lib/generators/config/templates/config.rb @@ -15,7 +15,7 @@ # # config.overwrite_arrays = true - # Use a different methhod of determining the current environment + # Use a different method of determining the current environment # defaults to ::Rails.env # config.environment = ENV.fetch('ENVIRONMENT', :development) diff --git a/spec/fixtures/from_env.yml b/spec/fixtures/from_env.yml deleted file mode 100644 index 50e06b8b..00000000 --- a/spec/fixtures/from_env.yml +++ /dev/null @@ -1,3 +0,0 @@ -some_seperated_key: - to_overide: - from_the_environment: "NOT SET" diff --git a/spec/options_spec.rb b/spec/options_spec.rb index ca4f9a27..0a94061c 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -221,23 +221,4 @@ end - context "values from env with conflicting seperator" do - before { Config.setup { |config| - config.env_prefix = 'SETTINGS' - config.env_separator = '_' - config.env_converter = :downcase - config.env_parse_values = true - } } - - # some_seperated_key: - # to_overide: - # from_the_environment: "NOT SET" - - it 'should find the correct keys' do - ENV["SETTINGS_SOME_SEPERATED_KEY_TO_OVERIDE_FROM_THE_ENVIRONMENT"] = "test" - Config.load_files("#{fixture_path}/from_env.yml") - expect(config.some_seperated_key.to_overide.from_the_environment).to eq("test") - end - end - end From ca21f0e44f1ff1bc1fc16eceae200b928894ce6d Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 25 Nov 2020 21:49:56 +0000 Subject: [PATCH 03/33] Removing unnecessary whitespace --- lib/config/integrations/rails/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/integrations/rails/railtie.rb b/lib/config/integrations/rails/railtie.rb index 8e105b3a..6748c116 100644 --- a/lib/config/integrations/rails/railtie.rb +++ b/lib/config/integrations/rails/railtie.rb @@ -8,7 +8,7 @@ def preload require initializer if File.exist?(initializer) # Parse the settings before any of the initializers - Config.load_and_set_settings( + Config.load_and_set_settings( Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym) ) end From a1c01dfc7b6db034cdeb05f7dd093d62ce85c177 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 25 Nov 2020 21:55:26 +0000 Subject: [PATCH 04/33] Bumping version number --- lib/config/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/version.rb b/lib/config/version.rb index c011340c..13c361d0 100644 --- a/lib/config/version.rb +++ b/lib/config/version.rb @@ -1,3 +1,3 @@ module Config - VERSION = '2.2.1'.freeze + VERSION = '2.3.0'.freeze end From e52940316b37406579e35ea23d011f80fa4298c0 Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Wed, 25 Nov 2020 23:13:35 +0100 Subject: [PATCH 05/33] Update config.gemspec --- config.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/config.gemspec b/config.gemspec index e2977ea1..892e5ebc 100644 --- a/config.gemspec +++ b/config.gemspec @@ -38,6 +38,7 @@ 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: \:(.*))?/ + File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, platform| if platform.nil? s.add_development_dependency name, version From f769e1eaa3e67a79f977ed42ad0e28756134066a Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Wed, 25 Nov 2020 23:14:22 +0100 Subject: [PATCH 06/33] Update options.rb --- lib/config/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/options.rb b/lib/config/options.rb index 1a0e2bd2..19006da6 100644 --- a/lib/config/options.rb +++ b/lib/config/options.rb @@ -227,4 +227,4 @@ def __value(v) end end end -end \ No newline at end of file +end From 6ecf2630bb085a90f04ec603382150ab566fb5fb Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Wed, 25 Nov 2020 23:15:06 +0100 Subject: [PATCH 07/33] Update version.rb --- lib/config/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/version.rb b/lib/config/version.rb index 13c361d0..c011340c 100644 --- a/lib/config/version.rb +++ b/lib/config/version.rb @@ -1,3 +1,3 @@ module Config - VERSION = '2.3.0'.freeze + VERSION = '2.2.1'.freeze end From b315448a281e8ea53caf90a17c4bce20ab2467d3 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 2 Dec 2020 14:44:39 +0000 Subject: [PATCH 08/33] Updating CHANGELOG, updating README and reverting version back to what it was --- CHANGELOG.md | 1 + README.md | 3 +++ lib/generators/config/templates/config.rb | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c5cbe9f..fed4b3cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changes +* Add ability to specify the environment for rails apps - [pull request #290](https://github.com/rubyconfig/config/pull/290) * Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228)) ## 2.2.1 diff --git a/README.md b/README.md index d6d271c1..b14aadcc 100644 --- a/README.md +++ b/README.md @@ -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 the ```config.environment``` in the config file. + ### Installing on Padrino Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config` @@ -265,6 +267,7 @@ After installing `Config` in Rails, you will find automatically generated file t ### General * `const_name` - name of the object holing you settings. Default: `'Settings'` +* `environment` - value for specifying the environment - currently only affects Rails applications. Default: `Rails.env` ### Merge customization diff --git a/lib/generators/config/templates/config.rb b/lib/generators/config/templates/config.rb index 426d3805..99428e4e 100644 --- a/lib/generators/config/templates/config.rb +++ b/lib/generators/config/templates/config.rb @@ -15,7 +15,7 @@ # # config.overwrite_arrays = true - # Use a different method of determining the current environment + # Use a different method of determining the current environment for rails applications # defaults to ::Rails.env # config.environment = ENV.fetch('ENVIRONMENT', :development) From 1708e42d82a7b5762f3f3fce17777cbc64c88780 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 2 Dec 2020 14:44:55 +0000 Subject: [PATCH 09/33] Reverting version back to what it was --- lib/config/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/version.rb b/lib/config/version.rb index 13c361d0..c011340c 100644 --- a/lib/config/version.rb +++ b/lib/config/version.rb @@ -1,3 +1,3 @@ module Config - VERSION = '2.3.0'.freeze + VERSION = '2.2.1'.freeze end From 26df03b9c91055e415cc6c186b0f43929bbb8b67 Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Tue, 8 Dec 2020 13:32:46 +0100 Subject: [PATCH 10/33] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 392507be..c7e8d41d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Changes -* Add ability to specify the environment for rails apps - [pull request #290](https://github.com/rubyconfig/config/pull/290) +* Add ability to specify the environment for Rails apps ([#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)) From ee039b256f11c62b6dbf25e95bdc9febb78a208c Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Tue, 8 Dec 2020 13:33:16 +0100 Subject: [PATCH 11/33] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e8d41d..e11ad192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Changes -* Add ability to specify the environment for Rails apps ([#290](https://github.com/rubyconfig/config/pull/290)) +* 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)) From 342d7cb14c59d351472d0e0f5104bc91f1749cbb Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Tue, 8 Dec 2020 13:33:23 +0100 Subject: [PATCH 12/33] Update CHANGELOG.md From 8627c67f75c8395db5127cdd45b0f8d33928a12f Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Tue, 8 Dec 2020 13:34:46 +0100 Subject: [PATCH 13/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b14aadcc..098d2d5c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ 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 the ```config.environment``` in the config file. +> Note: By default, the config environment will match the Rails environment (`Rails.env`). This can be changed by setting `config.environment`. ### Installing on Padrino From c772319026edfcc1645c92aa67c8385bc2b65ddd Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Tue, 8 Dec 2020 13:38:38 +0100 Subject: [PATCH 14/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 098d2d5c..4e832cc2 100644 --- a/README.md +++ b/README.md @@ -267,7 +267,7 @@ After installing `Config` in Rails, you will find automatically generated file t ### General * `const_name` - name of the object holing you settings. Default: `'Settings'` -* `environment` - value for specifying the environment - currently only affects Rails applications. Default: `Rails.env` +* `environment` - define current environment, affecting which settings file will be loaded. Default: `Rails.env` ### Merge customization From ee71de18a4bae4c83199c10b65c4eddc3b504fb5 Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Tue, 8 Dec 2020 13:40:23 +0100 Subject: [PATCH 15/33] Update config.rb --- lib/generators/config/templates/config.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/generators/config/templates/config.rb b/lib/generators/config/templates/config.rb index 99428e4e..85aafb5c 100644 --- a/lib/generators/config/templates/config.rb +++ b/lib/generators/config/templates/config.rb @@ -15,8 +15,8 @@ # # config.overwrite_arrays = true - # Use a different method of determining the current environment for rails applications - # defaults to ::Rails.env + # 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. @@ -55,5 +55,4 @@ # required(:age).maybe(:int?) # required(:email).filled(format?: EMAIL_REGEX) # end - end From 8df31ba5e942f5b354db617a3bb1abfe2766d9d1 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 13 Jan 2021 14:49:15 +0000 Subject: [PATCH 16/33] Fixing condition on gem platform in the gemspec to make more sense This change was to ensure that any gems with a platform condition are also installed locally when using bundle install --- config.gemspec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config.gemspec b/config.gemspec index 892e5ebc..c906b012 100644 --- a/config.gemspec +++ b/config.gemspec @@ -40,9 +40,7 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n" gems_to_install = /gem "(.*?)", "(.*?)"(?:, platform: \:(.*))?/ File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, platform| - if platform.nil? - s.add_development_dependency name, version - elsif platform.to_s == RUBY_ENGINE + if platform.nil? || platform.to_s == RUBY_ENGINE s.add_development_dependency name, version end end From 3e775aad6058f841fe2768220bf1e8f925dd6c18 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 13 Apr 2021 16:46:38 +0100 Subject: [PATCH 17/33] Init commit and adding 6.1 rails --- Appraisals | 18 ++++++++++++++++-- gemfiles/rails_5.2.gemfile | 2 +- gemfiles/rails_6.0.gemfile | 2 +- gemfiles/rails_6.1.gemfile | 11 +++++++++++ spec/config_env_spec.rb | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 gemfiles/rails_6.1.gemfile 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/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/spec/config_env_spec.rb b/spec/config_env_spec.rb index 65e7da8b..6e481a49 100644 --- a/spec/config_env_spec.rb +++ b/spec/config_env_spec.rb @@ -16,7 +16,7 @@ before :each do ENV.clear - + MyRailtie::Railtie.initializers.each(&:run) Config.use_env = true Config.env_prefix = nil Config.env_separator = '.' From c3e732e003958ec2636b9183fe9a18abe7c6c306 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 13 Apr 2021 16:58:49 +0100 Subject: [PATCH 18/33] Adding rails 6.1 --- spec/app/rails_6.1/Gemfile | 40 +++++++ spec/app/rails_6.1/Rakefile | 6 + .../app/controllers/application_controller.rb | 2 + .../app/rails_6.1/app/jobs/application_job.rb | 7 ++ .../app/models/application_record.rb | 3 + spec/app/rails_6.1/bin/bundle | 105 ++++++++++++++++ spec/app/rails_6.1/bin/rails | 5 + spec/app/rails_6.1/bin/rake | 5 + spec/app/rails_6.1/bin/setup | 33 +++++ spec/app/rails_6.1/bin/spring | 14 +++ spec/app/rails_6.1/config.ru | 6 + spec/app/rails_6.1/config/application.rb | 40 +++++++ spec/app/rails_6.1/config/boot.rb | 4 + spec/app/rails_6.1/config/credentials.yml.enc | 1 + spec/app/rails_6.1/config/database.yml | 25 ++++ spec/app/rails_6.1/config/environment.rb | 5 + .../config/environments/development.rb | 66 ++++++++++ .../config/environments/production.rb | 113 ++++++++++++++++++ .../app/rails_6.1/config/environments/test.rb | 60 ++++++++++ .../application_controller_renderer.rb | 8 ++ .../initializers/backtrace_silencers.rb | 8 ++ .../app/rails_6.1/config/initializers/cors.rb | 16 +++ .../initializers/filter_parameter_logging.rb | 6 + .../config/initializers/inflections.rb | 16 +++ .../config/initializers/mime_types.rb | 4 + .../config/initializers/wrap_parameters.rb | 14 +++ spec/app/rails_6.1/config/locales/en.yml | 33 +++++ spec/app/rails_6.1/config/routes.rb | 3 + spec/app/rails_6.1/db/seeds.rb | 7 ++ spec/app/rails_6.1/public/robots.txt | 1 + 30 files changed, 656 insertions(+) create mode 100644 spec/app/rails_6.1/Gemfile create mode 100644 spec/app/rails_6.1/Rakefile create mode 100644 spec/app/rails_6.1/app/controllers/application_controller.rb create mode 100644 spec/app/rails_6.1/app/jobs/application_job.rb create mode 100644 spec/app/rails_6.1/app/models/application_record.rb create mode 100755 spec/app/rails_6.1/bin/bundle create mode 100755 spec/app/rails_6.1/bin/rails create mode 100755 spec/app/rails_6.1/bin/rake create mode 100755 spec/app/rails_6.1/bin/setup create mode 100755 spec/app/rails_6.1/bin/spring create mode 100644 spec/app/rails_6.1/config.ru create mode 100644 spec/app/rails_6.1/config/application.rb create mode 100644 spec/app/rails_6.1/config/boot.rb create mode 100644 spec/app/rails_6.1/config/credentials.yml.enc create mode 100644 spec/app/rails_6.1/config/database.yml create mode 100644 spec/app/rails_6.1/config/environment.rb create mode 100644 spec/app/rails_6.1/config/environments/development.rb create mode 100644 spec/app/rails_6.1/config/environments/production.rb create mode 100644 spec/app/rails_6.1/config/environments/test.rb create mode 100644 spec/app/rails_6.1/config/initializers/application_controller_renderer.rb create mode 100644 spec/app/rails_6.1/config/initializers/backtrace_silencers.rb create mode 100644 spec/app/rails_6.1/config/initializers/cors.rb create mode 100644 spec/app/rails_6.1/config/initializers/filter_parameter_logging.rb create mode 100644 spec/app/rails_6.1/config/initializers/inflections.rb create mode 100644 spec/app/rails_6.1/config/initializers/mime_types.rb create mode 100644 spec/app/rails_6.1/config/initializers/wrap_parameters.rb create mode 100644 spec/app/rails_6.1/config/locales/en.yml create mode 100644 spec/app/rails_6.1/config/routes.rb create mode 100644 spec/app/rails_6.1/db/seeds.rb create mode 100644 spec/app/rails_6.1/public/robots.txt 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..04559286 --- /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..93ed4f1b --- /dev/null +++ b/spec/app/rails_6.1/config/environments/test.rb @@ -0,0 +1,60 @@ +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 + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # 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/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/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 From 73711af8231511f6ed80bdd17f413c79c2902e70 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Thu, 15 Apr 2021 16:08:35 +0100 Subject: [PATCH 19/33] fixture files added for non rails envs --- spec/fixtures/environments/preprod.yml | 6 ++++++ spec/fixtures/environments/stage.yml | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 spec/fixtures/environments/preprod.yml create mode 100644 spec/fixtures/environments/stage.yml diff --git a/spec/fixtures/environments/preprod.yml b/spec/fixtures/environments/preprod.yml new file mode 100644 index 00000000..891b8dd5 --- /dev/null +++ b/spec/fixtures/environments/preprod.yml @@ -0,0 +1,6 @@ +## +# Settings for Rails database.yml +# +databases: + preprod: + database: db/preprod.sqlite3 diff --git a/spec/fixtures/environments/stage.yml b/spec/fixtures/environments/stage.yml new file mode 100644 index 00000000..846cc626 --- /dev/null +++ b/spec/fixtures/environments/stage.yml @@ -0,0 +1,6 @@ +## +# Settings for Rails database.yml +# +databases: + stage: + database: db/stage.sqlite3 From 59352484fdd1a454ee37afca15f3b0ba7010e0e8 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:14:37 +0100 Subject: [PATCH 20/33] any_env.yml - Added these to show that other environment files can be used with Rails --- spec/app/rails_4.2/config/settings/any_env.yml | 8 ++++++++ spec/app/rails_5.0/config/settings/any_env.yml | 8 ++++++++ spec/app/rails_5.1/config/settings/any_env.yml | 8 ++++++++ spec/app/rails_5.2/config/settings/any_env.yml | 8 ++++++++ spec/app/rails_6.0/config/settings/any_env.yml | 8 ++++++++ spec/app/rails_6.1/config/settings/any_env.yml | 8 ++++++++ 6 files changed, 48 insertions(+) create mode 100644 spec/app/rails_4.2/config/settings/any_env.yml create mode 100644 spec/app/rails_5.0/config/settings/any_env.yml create mode 100644 spec/app/rails_5.1/config/settings/any_env.yml create mode 100644 spec/app/rails_5.2/config/settings/any_env.yml create mode 100644 spec/app/rails_6.0/config/settings/any_env.yml create mode 100644 spec/app/rails_6.1/config/settings/any_env.yml 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/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/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/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/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/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 From 5310f023f5b0ca0486a9dd1661f03273ea2f23e5 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:15:24 +0100 Subject: [PATCH 21/33] config.rb - An initialiser added to override the default behaviour from Rails in terms of environments --- spec/app/rails_4.2/config/initializers/config.rb | 8 ++++++++ spec/app/rails_5.0/config/initializers/config.rb | 8 ++++++++ spec/app/rails_5.1/config/initializers/config.rb | 9 +++++++++ spec/app/rails_5.2/config/initializers/config.rb | 9 +++++++++ spec/app/rails_6.0/config/initializers/config.rb | 9 +++++++++ 5 files changed, 43 insertions(+) create mode 100644 spec/app/rails_4.2/config/initializers/config.rb create mode 100644 spec/app/rails_5.0/config/initializers/config.rb create mode 100644 spec/app/rails_5.1/config/initializers/config.rb create mode 100644 spec/app/rails_5.2/config/initializers/config.rb create mode 100644 spec/app/rails_6.0/config/initializers/config.rb 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..b882a61b --- /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 = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.const_name = 'Settings' + config.env_parse_values = true +end 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..b882a61b --- /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 = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.const_name = 'Settings' + config.env_parse_values = true +end 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..c3846c8e --- /dev/null +++ b/spec/app/rails_5.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 = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.const_name = 'Settings' + config.env_parse_values = true +end + 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..c3846c8e --- /dev/null +++ b/spec/app/rails_5.2/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 = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.const_name = 'Settings' + config.env_parse_values = true +end + 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..c3846c8e --- /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 = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.const_name = 'Settings' + config.env_parse_values = true +end + From a1dff18bda771f5437f4c05681eec29334e212ee Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:16:12 +0100 Subject: [PATCH 22/33] config_env_spec.rb - Removed previous code that was added incorrectly --- spec/config_env_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/config_env_spec.rb b/spec/config_env_spec.rb index 6e481a49..f1ec394a 100644 --- a/spec/config_env_spec.rb +++ b/spec/config_env_spec.rb @@ -16,7 +16,6 @@ before :each do ENV.clear - MyRailtie::Railtie.initializers.each(&:run) Config.use_env = true Config.env_prefix = nil Config.env_separator = '.' From 561c58228e605388e27685e18b06e7625c0f6875 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:17:21 +0100 Subject: [PATCH 23/33] preprod.yml - Removed due to using a more obvious naming as people might not have the same env names. --- spec/fixtures/environments/preprod.yml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 spec/fixtures/environments/preprod.yml diff --git a/spec/fixtures/environments/preprod.yml b/spec/fixtures/environments/preprod.yml deleted file mode 100644 index 891b8dd5..00000000 --- a/spec/fixtures/environments/preprod.yml +++ /dev/null @@ -1,6 +0,0 @@ -## -# Settings for Rails database.yml -# -databases: - preprod: - database: db/preprod.sqlite3 From 214a5c1bfe75170f963425f7d14da22e8393a5da Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:17:53 +0100 Subject: [PATCH 24/33] rails_**.gemfile - Adeded byebug for testing --- gemfiles/rails_4.2.gemfile | 1 + gemfiles/rails_5.0.gemfile | 1 + gemfiles/rails_5.1.gemfile | 1 + gemfiles/rails_5.2.gemfile | 2 +- gemfiles/rails_6.0.gemfile | 2 +- gemfiles/rails_6.1.gemfile | 2 +- 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gemfiles/rails_4.2.gemfile b/gemfiles/rails_4.2.gemfile index 64589acb..8fcb4e8c 100644 --- a/gemfiles/rails_4.2.gemfile +++ b/gemfiles/rails_4.2.gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.25", platform: :jruby gem "rails", "4.2.11.3" +gem "byebug" gem "rspec-rails", "~> 3.7" gem "sprockets", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_5.0.gemfile b/gemfiles/rails_5.0.gemfile index f774d6c4..4afca93c 100644 --- a/gemfiles/rails_5.0.gemfile +++ b/gemfiles/rails_5.0.gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 50.6", platform: :jruby gem "rails", "5.0.7.2" +gem "byebug" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_5.1.gemfile b/gemfiles/rails_5.1.gemfile index 0ab61e5c..7836608b 100644 --- a/gemfiles/rails_5.1.gemfile +++ b/gemfiles/rails_5.1.gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 51.6", platform: :jruby gem "rails", "5.1.7" +gem "byebug" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile index 5ed02962..6d1af124 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -7,5 +7,5 @@ gem "bootsnap", "~> 1.4" gem "rails", "5.2.5" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby - +gem "byebug" gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index c55502f9..fcb2a76e 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -7,5 +7,5 @@ gem "bootsnap", "~> 1.4" gem "rails", "6.0.3.6" gem "rspec-rails", "~> 3.7" gem "sqlite3", "~> 1.4.0", platform: :ruby - +gem "byebug" gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index d08e66b7..9d7081a7 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -7,5 +7,5 @@ gem "bootsnap", "~> 1.4" gem "rails", "6.1.3.1" gem "rspec-rails", "~> 3.7" gem "sqlite3", "~> 1.4.0", platform: :ruby - +gem "byebug" gemspec path: "../" From 5c67eee971d9400ea1cfb8f009bf295c7b10a8d6 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:18:26 +0100 Subject: [PATCH 25/33] spec_helper.rb - Added the env var to set the environment file name on initialisation --- spec/spec_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4e802328..e50bfc02 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,10 @@ puts "RUBY_ENGINE: #{RUBY_ENGINE}" puts "RUBY_VERSION: #{RUBY_VERSION}\n\n" +# Set the env var that will be used in the config.rb initializer +# to set a non rails env - ANY_ENV can be any value: stage, preprod ... +ENV['NON_RAILS_ENVIRONMENT'] = 'ANY_ENV' + ## # Code Climate # @@ -22,7 +26,7 @@ if ENV['APPRAISAL_INITIALIZED'] || ENV['GITHUB_ACTIONS'] app_name = Pathname.new(ENV['BUNDLE_GEMFILE']).basename.sub('.gemfile', '') else - /.*?(?rails.*?)\.gemfile/ =~ Dir["gemfiles/rails*.gemfile"].sort.last + /.*?(?rails.*?)\.gemfile/ =~ Dir["gemfiles/rails*.gemfile"].sort.first end ## From f696df8ef4c3169ec9e18f86819f1aecb83e7364 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 13:18:45 +0100 Subject: [PATCH 26/33] stage.yml - Renamed to be more explicit --- spec/fixtures/environments/stage.yml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 spec/fixtures/environments/stage.yml diff --git a/spec/fixtures/environments/stage.yml b/spec/fixtures/environments/stage.yml deleted file mode 100644 index 846cc626..00000000 --- a/spec/fixtures/environments/stage.yml +++ /dev/null @@ -1,6 +0,0 @@ -## -# Settings for Rails database.yml -# -databases: - stage: - database: db/stage.sqlite3 From a8b7f8c629c1eca5a8a4469284698129c08f29f8 Mon Sep 17 00:00:00 2001 From: Gareth Griffiths Date: Tue, 20 Apr 2021 16:22:30 +0100 Subject: [PATCH 27/33] Missed tests and config --- spec/app/rails_6.1/config/initializers/config.rb | 9 +++++++++ spec/railtie_spec.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spec/app/rails_6.1/config/initializers/config.rb create mode 100644 spec/railtie_spec.rb 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..c3846c8e --- /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 = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.const_name = 'Settings' + config.env_parse_values = true +end + diff --git a/spec/railtie_spec.rb b/spec/railtie_spec.rb new file mode 100644 index 00000000..794075ab --- /dev/null +++ b/spec/railtie_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +context 'when a non rails environment is set' do + it 'should load a non rails environment file' do + byebug + expect(Settings.some_api.scheme).to eq 'https' + expect(Settings.some_api.host).to eq 'some-non-rails-environment' + expect(Settings.some_api.path).to eq '/some-path' + end +end + + From a4cb1d439e28967866dd90d2d7302775a9063b9e Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 21 Apr 2021 11:43:44 +0100 Subject: [PATCH 28/33] Initialising the config object as a different name from the rails app, so they don't conflict with the rspec config --- gemfiles/rails_4.2.gemfile | 1 - gemfiles/rails_5.0.gemfile | 1 - gemfiles/rails_5.1.gemfile | 1 - gemfiles/rails_5.2.gemfile | 2 +- gemfiles/rails_6.0.gemfile | 2 +- gemfiles/rails_6.1.gemfile | 2 +- spec/app/rails_4.2/config/database.yml | 6 +++--- spec/app/rails_4.2/config/initializers/config.rb | 2 +- spec/app/rails_5.0/config/initializers/config.rb | 2 +- spec/app/rails_5.1/config/initializers/config.rb | 3 +-- spec/app/rails_5.2/config/initializers/config.rb | 3 +-- spec/app/rails_6.0/config/initializers/config.rb | 2 +- spec/app/rails_6.1/config/initializers/config.rb | 2 +- spec/railtie_spec.rb | 9 +++++---- spec/support/rails_helper.rb | 2 +- 15 files changed, 18 insertions(+), 22 deletions(-) diff --git a/gemfiles/rails_4.2.gemfile b/gemfiles/rails_4.2.gemfile index 8fcb4e8c..64589acb 100644 --- a/gemfiles/rails_4.2.gemfile +++ b/gemfiles/rails_4.2.gemfile @@ -4,7 +4,6 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.25", platform: :jruby gem "rails", "4.2.11.3" -gem "byebug" gem "rspec-rails", "~> 3.7" gem "sprockets", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_5.0.gemfile b/gemfiles/rails_5.0.gemfile index 4afca93c..f774d6c4 100644 --- a/gemfiles/rails_5.0.gemfile +++ b/gemfiles/rails_5.0.gemfile @@ -4,7 +4,6 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 50.6", platform: :jruby gem "rails", "5.0.7.2" -gem "byebug" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_5.1.gemfile b/gemfiles/rails_5.1.gemfile index 7836608b..0ab61e5c 100644 --- a/gemfiles/rails_5.1.gemfile +++ b/gemfiles/rails_5.1.gemfile @@ -4,7 +4,6 @@ source "https://rubygems.org" gem "activerecord-jdbcsqlite3-adapter", "~> 51.6", platform: :jruby gem "rails", "5.1.7" -gem "byebug" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile index 6d1af124..5ed02962 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -7,5 +7,5 @@ gem "bootsnap", "~> 1.4" gem "rails", "5.2.5" gem "rspec-rails", "~> 3.7" gem "sqlite3", "< 1.4.0", platform: :ruby -gem "byebug" + gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index fcb2a76e..c55502f9 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -7,5 +7,5 @@ gem "bootsnap", "~> 1.4" gem "rails", "6.0.3.6" gem "rspec-rails", "~> 3.7" gem "sqlite3", "~> 1.4.0", platform: :ruby -gem "byebug" + gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 9d7081a7..d08e66b7 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -7,5 +7,5 @@ gem "bootsnap", "~> 1.4" gem "rails", "6.1.3.1" gem "rspec-rails", "~> 3.7" gem "sqlite3", "~> 1.4.0", platform: :ruby -gem "byebug" + gemspec path: "../" 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 index b882a61b..1e782f24 100644 --- a/spec/app/rails_4.2/config/initializers/config.rb +++ b/spec/app/rails_4.2/config/initializers/config.rb @@ -3,6 +3,6 @@ Config.setup do |config| config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase - config.const_name = 'Settings' + config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_5.0/config/initializers/config.rb b/spec/app/rails_5.0/config/initializers/config.rb index b882a61b..1e782f24 100644 --- a/spec/app/rails_5.0/config/initializers/config.rb +++ b/spec/app/rails_5.0/config/initializers/config.rb @@ -3,6 +3,6 @@ Config.setup do |config| config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase - config.const_name = 'Settings' + config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_5.1/config/initializers/config.rb b/spec/app/rails_5.1/config/initializers/config.rb index c3846c8e..1e782f24 100644 --- a/spec/app/rails_5.1/config/initializers/config.rb +++ b/spec/app/rails_5.1/config/initializers/config.rb @@ -3,7 +3,6 @@ Config.setup do |config| config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase - config.const_name = 'Settings' + config.const_name = 'RailtieSettings' config.env_parse_values = true end - diff --git a/spec/app/rails_5.2/config/initializers/config.rb b/spec/app/rails_5.2/config/initializers/config.rb index c3846c8e..1e782f24 100644 --- a/spec/app/rails_5.2/config/initializers/config.rb +++ b/spec/app/rails_5.2/config/initializers/config.rb @@ -3,7 +3,6 @@ Config.setup do |config| config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase - config.const_name = 'Settings' + config.const_name = 'RailtieSettings' config.env_parse_values = true end - diff --git a/spec/app/rails_6.0/config/initializers/config.rb b/spec/app/rails_6.0/config/initializers/config.rb index c3846c8e..095196eb 100644 --- a/spec/app/rails_6.0/config/initializers/config.rb +++ b/spec/app/rails_6.0/config/initializers/config.rb @@ -3,7 +3,7 @@ Config.setup do |config| config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase - config.const_name = 'Settings' + config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_6.1/config/initializers/config.rb b/spec/app/rails_6.1/config/initializers/config.rb index c3846c8e..095196eb 100644 --- a/spec/app/rails_6.1/config/initializers/config.rb +++ b/spec/app/rails_6.1/config/initializers/config.rb @@ -3,7 +3,7 @@ Config.setup do |config| config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase - config.const_name = 'Settings' + config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/railtie_spec.rb b/spec/railtie_spec.rb index 794075ab..0901ad92 100644 --- a/spec/railtie_spec.rb +++ b/spec/railtie_spec.rb @@ -2,10 +2,11 @@ context 'when a non rails environment is set' do it 'should load a non rails environment file' do - byebug - expect(Settings.some_api.scheme).to eq 'https' - expect(Settings.some_api.host).to eq 'some-non-rails-environment' - expect(Settings.some_api.path).to eq '/some-path' + unless 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/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}" From a8e256443f97fde0c308fbe9f66fe666af7e5f38 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 12 Jul 2021 12:54:04 +0100 Subject: [PATCH 29/33] Tweaking the config of the new rails apps and pushing the intermittent railstie test for review --- .byebug_history | 55 +++++++++++++++++++ config.gemspec | 1 + lib/config.rb | 1 - .../rails_4.2/config/initializers/config.rb | 2 +- .../rails_5.0/config/initializers/config.rb | 2 +- .../rails_5.1/config/initializers/config.rb | 2 +- .../rails_5.2/config/initializers/config.rb | 2 +- .../rails_6.0/config/initializers/config.rb | 2 +- spec/app/rails_6.1/config/application.rb | 12 ++-- .../app/rails_6.1/config/environments/test.rb | 10 ---- .../rails_6.1/config/initializers/config.rb | 2 +- spec/config_env_spec.rb | 8 ++- spec/railtie_spec.rb | 6 +- spec/spec_helper.rb | 8 +-- 14 files changed, 79 insertions(+), 34 deletions(-) create mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 00000000..9c04783f --- /dev/null +++ b/.byebug_history @@ -0,0 +1,55 @@ +c +Settings +n +c +config +Config.const_name +config.const_name +n +config.const_name +config +c +self +sekf +n +s +c +Config.const_name +n +Settings +name +Object.const_set(name, Config.load_files(files)) +Object.const_defined?(name) +if Object.const_defined?(name) +n +Config.const_name +c +Config.const_name +exit +c +Settings +self.const_name +n +b +Settings +n +self.const_name +self +c +Settings +c +Config.reload! + ENV['RailtieSettings.new_var'] = 'value' +RailtieSettings +Config.reload! +config +Settings +c +app_name +exit +c +app_name +c +app_name +c +app_name diff --git a/config.gemspec b/config.gemspec index c906b012..e3beab32 100644 --- a/config.gemspec +++ b/config.gemspec @@ -53,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/lib/config.rb b/lib/config.rb index 3dcc1a6c..1cdf06b6 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -45,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/spec/app/rails_4.2/config/initializers/config.rb b/spec/app/rails_4.2/config/initializers/config.rb index 1e782f24..232f3f4d 100644 --- a/spec/app/rails_4.2/config/initializers/config.rb +++ b/spec/app/rails_4.2/config/initializers/config.rb @@ -2,7 +2,7 @@ # when not using the default rails environments Config.setup do |config| - config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.environment = 'any_env' config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_5.0/config/initializers/config.rb b/spec/app/rails_5.0/config/initializers/config.rb index 1e782f24..232f3f4d 100644 --- a/spec/app/rails_5.0/config/initializers/config.rb +++ b/spec/app/rails_5.0/config/initializers/config.rb @@ -2,7 +2,7 @@ # when not using the default rails environments Config.setup do |config| - config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.environment = 'any_env' config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_5.1/config/initializers/config.rb b/spec/app/rails_5.1/config/initializers/config.rb index 1e782f24..232f3f4d 100644 --- a/spec/app/rails_5.1/config/initializers/config.rb +++ b/spec/app/rails_5.1/config/initializers/config.rb @@ -2,7 +2,7 @@ # when not using the default rails environments Config.setup do |config| - config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.environment = 'any_env' config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_5.2/config/initializers/config.rb b/spec/app/rails_5.2/config/initializers/config.rb index 1e782f24..232f3f4d 100644 --- a/spec/app/rails_5.2/config/initializers/config.rb +++ b/spec/app/rails_5.2/config/initializers/config.rb @@ -2,7 +2,7 @@ # when not using the default rails environments Config.setup do |config| - config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.environment = 'any_env' config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_6.0/config/initializers/config.rb b/spec/app/rails_6.0/config/initializers/config.rb index 095196eb..9969cdd1 100644 --- a/spec/app/rails_6.0/config/initializers/config.rb +++ b/spec/app/rails_6.0/config/initializers/config.rb @@ -2,7 +2,7 @@ # when not using the default rails environments Config.setup do |config| - config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.environment = 'any_env' config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/app/rails_6.1/config/application.rb b/spec/app/rails_6.1/config/application.rb index 04559286..fdf024bc 100644 --- a/spec/app/rails_6.1/config/application.rb +++ b/spec/app/rails_6.1/config/application.rb @@ -5,15 +5,15 @@ require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" -require "active_storage/engine" +# require "active_storage/engine" require "action_controller/railtie" -require "action_mailer/railtie" -require "action_mailbox/engine" -require "action_text/engine" +# require "action_mailer/railtie" +# require "action_mailbox/engine" +# require "action_text/engine" require "action_view/railtie" -require "action_cable/engine" +# require "action_cable/engine" # require "sprockets/railtie" -require "rails/test_unit/railtie" +# require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/spec/app/rails_6.1/config/environments/test.rb b/spec/app/rails_6.1/config/environments/test.rb index 93ed4f1b..39eb9be7 100644 --- a/spec/app/rails_6.1/config/environments/test.rb +++ b/spec/app/rails_6.1/config/environments/test.rb @@ -33,16 +33,6 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Store uploaded files on the local file system in a temporary directory. - config.active_storage.service = :test - - config.action_mailer.perform_caching = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/spec/app/rails_6.1/config/initializers/config.rb b/spec/app/rails_6.1/config/initializers/config.rb index 095196eb..9969cdd1 100644 --- a/spec/app/rails_6.1/config/initializers/config.rb +++ b/spec/app/rails_6.1/config/initializers/config.rb @@ -2,7 +2,7 @@ # when not using the default rails environments Config.setup do |config| - config.environment = ENV['NON_RAILS_ENVIRONMENT'].downcase + config.environment = 'any_env' config.const_name = 'RailtieSettings' config.env_parse_values = true end diff --git a/spec/config_env_spec.rb b/spec/config_env_spec.rb index f1ec394a..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 @@ -207,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 index 0901ad92..ba49605a 100644 --- a/spec/railtie_spec.rb +++ b/spec/railtie_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -context 'when a non rails environment is set' do - it 'should load a non rails environment file' do - unless defined?(::Rails) +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' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e50bfc02..160f2d92 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,10 @@ +require 'byebug' + ENV['RAILS_ENV'] ||= 'test' puts "RUBY_ENGINE: #{RUBY_ENGINE}" puts "RUBY_VERSION: #{RUBY_VERSION}\n\n" -# Set the env var that will be used in the config.rb initializer -# to set a non rails env - ANY_ENV can be any value: stage, preprod ... -ENV['NON_RAILS_ENVIRONMENT'] = 'ANY_ENV' - ## # Code Climate # @@ -26,7 +24,7 @@ if ENV['APPRAISAL_INITIALIZED'] || ENV['GITHUB_ACTIONS'] app_name = Pathname.new(ENV['BUNDLE_GEMFILE']).basename.sub('.gemfile', '') else - /.*?(?rails.*?)\.gemfile/ =~ Dir["gemfiles/rails*.gemfile"].sort.first + /.*?(?rails.*?)\.gemfile/ =~ Dir["gemfiles/rails*.gemfile"].sort.last end ## From ec3f2b914de8c25ce061a10dd45277097f5073b5 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 12 Jul 2021 12:57:57 +0100 Subject: [PATCH 30/33] Fixing syntax error after merge conflicts --- lib/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.rb b/lib/config.rb index bef28568..99a04848 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -25,7 +25,7 @@ module Config overwrite_arrays: true, merge_hash_arrays: false, validation_contract: nil, - environment: nil + environment: nil, evaluate_erb_in_yaml: true ) From 997e1c471467964dd363356bc738a88e17b17d6e Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 12 Jul 2021 15:45:30 +0100 Subject: [PATCH 31/33] Removing byebug history and ignoring from git --- .byebug_history | 55 ------------------------------------------------- .gitignore | 1 + 2 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history deleted file mode 100644 index 9c04783f..00000000 --- a/.byebug_history +++ /dev/null @@ -1,55 +0,0 @@ -c -Settings -n -c -config -Config.const_name -config.const_name -n -config.const_name -config -c -self -sekf -n -s -c -Config.const_name -n -Settings -name -Object.const_set(name, Config.load_files(files)) -Object.const_defined?(name) -if Object.const_defined?(name) -n -Config.const_name -c -Config.const_name -exit -c -Settings -self.const_name -n -b -Settings -n -self.const_name -self -c -Settings -c -Config.reload! - ENV['RailtieSettings.new_var'] = 'value' -RailtieSettings -Config.reload! -config -Settings -c -app_name -exit -c -app_name -c -app_name -c -app_name 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 From 1b9b8e001a89cd06d7d6d8af3a5e912e24d6f379 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 12 Jul 2021 15:53:40 +0100 Subject: [PATCH 32/33] ignoring errors requiring byebug in the CI environment - useful for local debugging --- spec/spec_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 160f2d92..ff7f043d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,8 @@ -require 'byebug' +begin + require 'byebug' +rescue LoadError + # we don't install this in the ci pipeline +end ENV['RAILS_ENV'] ||= 'test' From 12b112fefe9346a2dfbc89866e7a5381a7a09c36 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 12 Jul 2021 15:54:43 +0100 Subject: [PATCH 33/33] Don't require byebug when in CI environment --- spec/spec_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff7f043d..cda8dd97 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,5 @@ -begin +unless ENV['GITHUB_ACTIONS'] require 'byebug' -rescue LoadError - # we don't install this in the ci pipeline end ENV['RAILS_ENV'] ||= 'test'