Extract method to stub secrets in tests

This commit is contained in:
Javi Martín
2024-10-25 13:38:34 +02:00
parent 6133412ba5
commit 9f38ed6bae
7 changed files with 21 additions and 20 deletions

View File

@@ -5,9 +5,7 @@ describe Account::SignInInfoComponent do
context "Security secret for render last sign in is enabled" do context "Security secret for render last sign in is enabled" do
it "shows a sign in info" do it "shows a sign in info" do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(security: { last_sign_in: true })
security: { last_sign_in: true }
))
render_inline Account::SignInInfoComponent.new(account) render_inline Account::SignInInfoComponent.new(account)

View File

@@ -85,12 +85,12 @@ describe Mailer do
let(:super_settings) { { address: "super.consul.dev", username: "super" } } let(:super_settings) { { address: "super.consul.dev", username: "super" } }
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(
smtp_settings: default_settings, smtp_settings: default_settings,
tenants: { tenants: {
supermailer: { smtp_settings: super_settings } supermailer: { smtp_settings: super_settings }
} }
)) )
end end
it "does not overwrite the settings for the default tenant" do it "does not overwrite the settings for the default tenant" do

View File

@@ -243,10 +243,7 @@ describe Tenant do
describe ".current_secrets" do describe ".current_secrets" do
context "same secrets for all tenants" do context "same secrets for all tenants" do
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(star: "Sun", volume: "Medium")
star: "Sun",
volume: "Medium"
))
end end
it "returns the default secrets for the default tenant" do it "returns the default secrets for the default tenant" do
@@ -266,11 +263,11 @@ describe Tenant do
context "tenant overwriting secrets" do context "tenant overwriting secrets" do
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(
star: "Sun", star: "Sun",
volume: "Medium", volume: "Medium",
tenants: { proxima: { star: "Alpha Centauri" }} tenants: { proxima: { star: "Alpha Centauri" }}
)) )
end end
it "returns the default secrets for the default tenant" do it "returns the default secrets for the default tenant" do

View File

@@ -994,7 +994,7 @@ describe User do
context "when secrets are configured" do context "when secrets are configured" do
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(
security: { security: {
password_complexity: true password_complexity: true
}, },
@@ -1005,7 +1005,7 @@ describe User do
} }
} }
} }
)) )
end end
it "uses the general secrets for the main tenant" do it "uses the general secrets for the main tenant" do
@@ -1027,7 +1027,7 @@ describe User do
context "when secrets are configured" do context "when secrets are configured" do
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(
security: { security: {
lockable: { maximum_attempts: "14" } lockable: { maximum_attempts: "14" }
}, },
@@ -1038,7 +1038,7 @@ describe User do
} }
} }
} }
)) )
end end
it "uses the general secrets for the main tenant" do it "uses the general secrets for the main tenant" do
@@ -1060,7 +1060,7 @@ describe User do
context "when secrets are configured" do context "when secrets are configured" do
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(
security: { security: {
lockable: { unlock_in: "2" } lockable: { unlock_in: "2" }
}, },
@@ -1071,7 +1071,7 @@ describe User do
} }
} }
} }
)) )
end end
it "uses the general secrets for the main tenant" do it "uses the general secrets for the main tenant" do

View File

@@ -14,6 +14,7 @@ module CommonActions
include Polls include Polls
include Proposals include Proposals
include RemoteCensusMock include RemoteCensusMock
include Secrets
include Tags include Tags
include Translations include Translations
include Users include Users

View File

@@ -0,0 +1,7 @@
module Secrets
def stub_secrets(configuration)
allow(Rails.application).to receive(:secrets).and_return(
ActiveSupport::OrderedOptions.new.merge(configuration)
)
end
end

View File

@@ -661,9 +661,7 @@ describe "Users" do
context "Regular authentication with password complexity enabled" do context "Regular authentication with password complexity enabled" do
before do before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge( stub_secrets(security: { password_complexity: true })
security: { password_complexity: true }
))
end end
context "Sign up" do context "Sign up" do