OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Replace stub_env with with_env
Oliver Günther10dcba6eb257
diff --git a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rbindex 34f2cd6ac89..203e9139596 100644--- a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb+++ b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb@@ -174,12 +174,13 @@ RSpec.describe RootSeeder,endend- describe 'demo data with a non-English language set with OPENPROJECT_DEFAULT__LANGUAGE', :settings_reset do+ describe 'demo data with a non-English language set with OPENPROJECT_DEFAULT__LANGUAGE',+ :settings_reset,+ with_env: { 'OPENPROJECT_DEFAULT__LANGUAGE' => 'de' } doshared_let(:root_seeder) { described_class.new }before_all dowith_edition('bim') do- stub_const('ENV', { 'OPENPROJECT_DEFAULT__LANGUAGE' => 'de' })reset(:default_language) # Settings are a pain to resetroot_seeder.seed_data!ensurediff --git a/spec/constants/settings/definition_spec.rb b/spec/constants/settings/definition_spec.rbindex 5d539b407c1..a779c47e533 100644--- a/spec/constants/settings/definition_spec.rb+++ b/spec/constants/settings/definition_spec.rb@@ -74,13 +74,12 @@ RSpec.describe Settings::Definition, :settings_reset doexpect(all[:brute_force_block_after_failed_logins].value).to eq(20)end- context 'when overriding from ENV' do+ context 'when overriding from ENV',+ with_env: {+ 'OPENPROJECT_EDITION' => 'bim',+ 'OPENPROJECT_DEFAULT__LANGUAGE' => 'de'+ } doit 'allows overriding configuration from ENV with OPENPROJECT_ prefix with double underscore case (legacy)' do- stub_const('ENV',- {- 'OPENPROJECT_EDITION' => 'bim',- 'OPENPROJECT_DEFAULT__LANGUAGE' => 'de'- })reset(:edition)reset(:default_language)@@ -88,42 +87,47 @@ RSpec.describe Settings::Definition, :settings_reset doexpect(all[:default_language].value).to eql 'de'end- it 'allows overriding configuration from ENV with OPENPROJECT_ prefix with single underscore case' do- stub_const('ENV', { 'OPENPROJECT_DEFAULT_LANGUAGE' => 'de' })+ it 'allows overriding configuration from ENV with OPENPROJECT_ prefix with single underscore case',+ with_env: { 'OPENPROJECT_DEFAULT_LANGUAGE' => 'de' } doreset(:default_language)expect(all[:default_language].value).to eql 'de'end- it 'allows overriding configuration from ENV without OPENPROJECT_ prefix' do- stub_const('ENV', { 'EDITION' => 'bim' })+ it 'allows overriding configuration from ENV without OPENPROJECT_ prefix',+ with_env: { 'EDITION' => 'bim' } doreset(:edition)expect(all[:edition].value).to eql 'bim'end- it 'does not allows overriding configuration from ENV without OPENPROJECT_ prefix if setting is writable' do- stub_const('ENV', { 'DEFAULT_LANGUAGE' => 'de' })+ it 'does not allows overriding configuration from ENV without OPENPROJECT_ prefix if setting is writable',+ with_env: { 'DEFAULT_LANGUAGE' => 'de' } doreset(:default_language)expect(all[:default_language].value).to eql 'en'end- it 'allows overriding email/smtp configuration from ENV without OPENPROJECT_ prefix even though setting is writable' do- env_vars = {- 'EMAIL_DELIVERY_CONFIGURATION' => 'legacy',- 'EMAIL_DELIVERY_METHOD' => 'smtp',- 'SMTP_ADDRESS' => 'smtp.somedomain.org',- 'SMTP_AUTHENTICATION' => 'something',- 'SMTP_DOMAIN' => 'email.bogus.abc',- 'SMTP_ENABLE_STARTTLS_AUTO' => 'true',- 'SMTP_PASSWORD' => 'password',- 'SMTP_PORT' => '987',- 'SMTP_USER_NAME' => 'user',- 'SMTP_SSL' => 'true'- }- stub_const('ENV', env_vars)-- env_vars.each_key do |env_var|- reset(env_var.downcase.to_sym)- end+ it 'allows overriding email/smtp configuration from ENV without OPENPROJECT_ prefix even though setting is writable',+ with_env: {+ 'EMAIL_DELIVERY_CONFIGURATION' => 'legacy',+ 'EMAIL_DELIVERY_METHOD' => 'smtp',+ 'SMTP_ADDRESS' => 'smtp.somedomain.org',+ 'SMTP_AUTHENTICATION' => 'something',+ 'SMTP_DOMAIN' => 'email.bogus.abc',+ 'SMTP_ENABLE_STARTTLS_AUTO' => 'true',+ 'SMTP_PASSWORD' => 'password',+ 'SMTP_PORT' => '987',+ 'SMTP_USER_NAME' => 'user',+ 'SMTP_SSL' => 'true'+ } do+ reset(:email_delivery_configuration)+ reset(:email_delivery_method)+ reset(:smtp_address)+ reset(:smtp_authentication)+ reset(:smtp_domain)+ reset(:smtp_enable_starttls_auto)+ reset(:smtp_password)+ reset(:smtp_port)+ reset(:smtp_user_name)+ reset(:smtp_ssl)expect(all[:email_delivery_configuration].value).to eql 'legacy'expect(all[:email_delivery_method].value).to eq :smtp@@ -137,9 +141,9 @@ RSpec.describe Settings::Definition, :settings_reset doexpect(all[:smtp_ssl].value).to be trueend- it 'logs a deprecation warning when overriding configuration from ENV without OPENPROJECT_ prefix' do+ it 'logs a deprecation warning when overriding configuration from ENV without OPENPROJECT_ prefix',+ with_env: { 'EDITION' => 'bim' } doallow(Rails.logger).to receive(:warn)- stub_const('ENV', { 'EDITION' => 'bim' })reset(:edition)@@ -148,55 +152,55 @@ RSpec.describe Settings::Definition, :settings_reset do.with(a_string_including("use OPENPROJECT_EDITION instead of EDITION"))end- it 'overriding boolean configuration from ENV will cast the value' do- stub_const('ENV', { 'OPENPROJECT_REST__API__ENABLED' => '0' })+ it 'overriding boolean configuration from ENV will cast the value',+ with_env: { 'OPENPROJECT_REST__API__ENABLED' => '0' } doreset(:rest_api_enabled)expect(all[:rest_api_enabled].value).to be falseend- it 'overriding symbol configuration having allowed values from ENV will cast the value before validation check' do- stub_const('ENV', { 'OPENPROJECT_RAILS__CACHE__STORE' => 'memcache' })+ it 'overriding symbol configuration having allowed values from ENV will cast the value before validation check',+ with_env: { 'OPENPROJECT_RAILS__CACHE__STORE' => 'memcache' } doreset(:rails_cache_store)expect(all[:rails_cache_store].value).to eq :memcacheend- it 'overriding datetime configuration from ENV will cast the value' do- stub_const('ENV', { 'OPENPROJECT_CONSENT__TIME' => '2222-01-01' })+ it 'overriding datetime configuration from ENV will cast the value',+ with_env: { 'OPENPROJECT_CONSENT__TIME' => '2222-01-01' } doreset(:consent_time)expect(all[:consent_time].value).to eql DateTime.parse('2222-01-01')end- it 'overriding timezone configuration from ENV will cast the value' do- stub_const('ENV', { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'Europe/Berlin' })+ it 'overriding timezone configuration from ENV will cast the value',+ with_env: { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'Europe/Berlin' } doreset(:user_default_timezone)expect(all[:user_default_timezone].value).to eq 'Europe/Berlin'end- it 'overriding timezone configuration from ENV with a bogus value' do- stub_const('ENV', { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'foobar' })+ it 'overriding timezone configuration from ENV with a bogus value',+ with_env: { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'foobar' } doexpect { reset(:user_default_timezone) }.to raise_error(ArgumentError)end- it 'overriding configuration from ENV will set it to non writable' do- stub_const('ENV', { 'OPENPROJECT_EDITION' => 'bim' })+ it 'overriding configuration from ENV will set it to non writable',+ with_env: { 'OPENPROJECT_EDITION' => 'bim' } doreset(:edition)expect(all[:edition]).not_to be_writableend- it 'allows overriding settings array from ENV' do- stub_const('ENV', { 'OPENPROJECT_PASSWORD__ACTIVE__RULES' => YAML.dump(['lowercase']) })+ it 'allows overriding settings array from ENV',+ with_env: { 'OPENPROJECT_PASSWORD__ACTIVE__RULES' => YAML.dump(['lowercase']) } doreset(:password_active_rules)expect(all[:password_active_rules].value).to eql ['lowercase']end- it 'overriding settings from ENV will set it to non writable' do- stub_const('ENV', { 'OPENPROJECT_WELCOME__TITLE' => 'Some title' })+ it 'overriding settings from ENV will set it to non writable',+ with_env: { 'OPENPROJECT_WELCOME__TITLE' => 'Some title' } doreset(:welcome_title)expect(all[:welcome_title]).not_to be_writableend- it 'allows overriding settings hash partially from ENV' do- stub_const('ENV', { 'OPENPROJECT_REPOSITORY__CHECKOUT__DATA_GIT_ENABLED' => '1' })+ it 'allows overriding settings hash partially from ENV',+ with_env: { 'OPENPROJECT_REPOSITORY__CHECKOUT__DATA_GIT_ENABLED' => '1' } doreset(:repository_checkout_data)expect(all[:repository_checkout_data].value).to eql({'git' => { 'enabled' => 1 },@@ -204,8 +208,8 @@ RSpec.describe Settings::Definition, :settings_reset do})end- it 'allows overriding settings hash partially from ENV with single underscore name' do- stub_const('ENV', { 'OPENPROJECT_REPOSITORY_CHECKOUT_DATA_GIT_ENABLED' => '1' })+ it 'allows overriding settings hash partially from ENV with single underscore name',+ with_env: { 'OPENPROJECT_REPOSITORY_CHECKOUT_DATA_GIT_ENABLED' => '1' } doreset(:repository_checkout_data)expect(all[:repository_checkout_data].value).to eql({'git' => { 'enabled' => 1 },@@ -213,8 +217,8 @@ RSpec.describe Settings::Definition, :settings_reset do})end- it 'allows overriding settings hash partially from ENV with yaml data' do- stub_const('ENV', { 'OPENPROJECT_REPOSITORY_CHECKOUT_DATA' => '{git: {enabled: 1}}' })+ it 'allows overriding settings hash partially from ENV with yaml data',+ with_env: { 'OPENPROJECT_REPOSITORY_CHECKOUT_DATA' => '{git: {enabled: 1}}' } doreset(:repository_checkout_data)expect(all[:repository_checkout_data].value).to eql({'git' => { 'enabled' => 1 },@@ -364,13 +368,13 @@ RSpec.describe Settings::Definition, :settings_reset doendend- it 'will not handle ENV vars for which no definition exists' do- stub_const('ENV', { 'OPENPROJECT_BOGUS' => '1234' })+ it 'will not handle ENV vars for which no definition exists',+ with_env: { 'OPENPROJECT_BOGUS' => '1234' } doexpect(all[:bogus]).to be_nilend- it 'will handle ENV vars for definitions added after #all was called (e.g. in a module)' do- stub_const('ENV', { 'OPENPROJECT_BOGUS' => '1' })+ it 'will handle ENV vars for definitions added after #all was called (e.g. in a module)',+ with_env: { 'OPENPROJECT_BOGUS' => '1' } dodescribed_class.add(:bogus, default: 0)expect(all[:bogus].value).to eq 1end@@ -479,10 +483,8 @@ RSpec.describe Settings::Definition, :settings_reset doendend- context 'when overwritten from ENV' do- before do- stub_const('ENV', { 'OPENPROJECT_SENDMAIL__LOCATION' => 'env location' })- end+ context 'when overwritten from ENV',+ with_env: { 'OPENPROJECT_SENDMAIL__LOCATION' => 'env location' } doit 'overrides from ENV' doreset(:sendmail_location)diff --git a/spec/helpers/frontend_asset_helper_spec.rb b/spec/helpers/frontend_asset_helper_spec.rbindex 278887ffd31..3d3e27cc99e 100644--- a/spec/helpers/frontend_asset_helper_spec.rb+++ b/spec/helpers/frontend_asset_helper_spec.rb@@ -30,10 +30,10 @@ require 'spec_helper'RSpec.describe FrontendAssetHelper dodescribe '#include_frontend_assets' do- context 'when in development or test' do+ context 'when in development or test',+ with_env: { 'OPENPROJECT_DISABLE_DEV_ASSET_PROXY' => '' } dobefore doallow(Rails.env).to receive(:production?).and_return(false)- stub_const('ENV', 'OPENPROJECT_DISABLE_DEV_ASSET_PROXY' => '')endit 'returns the proxied frontend server' dodiff --git a/spec/lib/open_project/feature_decisions_spec.rb b/spec/lib/open_project/feature_decisions_spec.rbindex a931ee306cd..3a6bd5771b1 100644--- a/spec/lib/open_project/feature_decisions_spec.rb+++ b/spec/lib/open_project/feature_decisions_spec.rb@@ -38,10 +38,8 @@ RSpec.describe OpenProject::FeatureDecisions, :settings_reset doendend- shared_context 'when adding with env variable set to true' do+ shared_context 'when adding the given feature flag' dobefore do- stub_const('ENV', 'OPENPROJECT_FEATURE_EXAMPLE_FLAG_ACTIVE' => 'true')-described_class.add flag_nameendend@@ -56,8 +54,9 @@ RSpec.describe OpenProject::FeatureDecisions, :settings_reset doendend- context 'with an ENV variable (set to true)' do- include_context 'when adding with env variable set to true'+ context 'with an ENV variable (set to true)',+ with_env: { 'OPENPROJECT_FEATURE_EXAMPLE_FLAG_ACTIVE' => 'true' } do+ include_context 'when adding the given feature flag'it 'is true' doexpect(described_class.send("#{flag_name}_active?"))@@ -83,8 +82,9 @@ RSpec.describe OpenProject::FeatureDecisions, :settings_reset doendend- context 'with a flag defined that is enabled via env' do- include_context 'when adding with env variable set to true'+ context 'with a flag defined that is enabled via env',+ with_env: { 'OPENPROJECT_FEATURE_EXAMPLE_FLAG_ACTIVE' => 'true' } do+ include_context 'when adding the given feature flag'it 'returns an empty array' doexpect(described_class.active)diff --git a/spec/requests/api/v3/configuration_resource_spec.rb b/spec/requests/api/v3/configuration_resource_spec.rbindex 6f11fb95f32..d94d9cd5e24 100644--- a/spec/requests/api/v3/configuration_resource_spec.rb+++ b/spec/requests/api/v3/configuration_resource_spec.rb@@ -70,13 +70,14 @@ RSpec.describe 'API v3 Configuration resource' do.not_to have_json_path('_embedded/user_preferences')end- context 'with feature flags', :settings_reset do+ context 'with feature flags',+ :settings_reset,+ with_env: {+ 'OPENPROJECT_FEATURE_AN_EXAMPLE_ACTIVE' => 'true',+ 'OPENPROJECT_FEATURE_ANOTHER_EXAMPLE_ACTIVE' => 'true',+ 'OPENPROJECT_FEATURE_INACTIVE_EXAMPLE_ACTIVE' => 'false'+ } dobefore do- stub_const('ENV',- 'OPENPROJECT_FEATURE_AN_EXAMPLE_ACTIVE' => 'true',- 'OPENPROJECT_FEATURE_ANOTHER_EXAMPLE_ACTIVE' => 'true',- 'OPENPROJECT_FEATURE_INACTIVE_EXAMPLE_ACTIVE' => 'false')-OpenProject::FeatureDecisions.add :an_exampleOpenProject::FeatureDecisions.add :another_exampleOpenProject::FeatureDecisions.add :deactivated_examplediff --git a/spec/seeders/root_seeder_standard_edition_spec.rb b/spec/seeders/root_seeder_standard_edition_spec.rbindex ac12bea516e..79036a434f6 100644--- a/spec/seeders/root_seeder_standard_edition_spec.rb+++ b/spec/seeders/root_seeder_standard_edition_spec.rb@@ -172,16 +172,18 @@ RSpec.describe RootSeeder,'OPENPROJECT_SEED_LOCALE','OPENPROJECT_DEFAULT_LANGUAGE'].each do |env_var_name|- describe "demo data with a non-English language set with #{env_var_name}", :settings_reset do+ describe "demo data with a non-English language set with #{env_var_name}",+ :settings_reset doshared_let(:root_seeder) { described_class.new }before_all do- with_edition('standard') do- stub_const('ENV', { env_var_name => 'de' })- reset(:default_language) # Settings are a pain to reset- root_seeder.seed_data!- ensure- reset(:default_language)+ ClimateControl.modify({ env_var_name => 'de' }) do+ with_edition('standard') do+ reset(:default_language) # Settings are a pain to reset+ root_seeder.seed_data!+ ensure+ reset(:default_language)+ endendenddiff --git a/spec/support/root_seeder_test_helpers.rb b/spec/support/root_seeder_test_helpers.rbindex ddb96af7948..621ae79e186 100644--- a/spec/support/root_seeder_test_helpers.rb+++ b/spec/support/root_seeder_test_helpers.rb@@ -29,12 +29,6 @@#++module RootSeederTestHelpers- def stub_language(locale)- locale = locale.to_s- with_settings(default_language: locale)- stub_const('ENV', { 'OPENPROJECT_SEED_LOCALE' => locale })- end-def with_edition(edition)RSpec::Mocks.with_temporary_scope dowith_config(edition:)