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
it "shows a sign in info" do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
security: { last_sign_in: true }
))
stub_secrets(security: { last_sign_in: true })
render_inline Account::SignInInfoComponent.new(account)

View File

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

View File

@@ -243,10 +243,7 @@ describe Tenant do
describe ".current_secrets" do
context "same secrets for all tenants" do
before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
star: "Sun",
volume: "Medium"
))
stub_secrets(star: "Sun", volume: "Medium")
end
it "returns the default secrets for the default tenant" do
@@ -266,11 +263,11 @@ describe Tenant do
context "tenant overwriting secrets" do
before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
stub_secrets(
star: "Sun",
volume: "Medium",
tenants: { proxima: { star: "Alpha Centauri" }}
))
)
end
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
before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
stub_secrets(
security: {
password_complexity: true
},
@@ -1005,7 +1005,7 @@ describe User do
}
}
}
))
)
end
it "uses the general secrets for the main tenant" do
@@ -1027,7 +1027,7 @@ describe User do
context "when secrets are configured" do
before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
stub_secrets(
security: {
lockable: { maximum_attempts: "14" }
},
@@ -1038,7 +1038,7 @@ describe User do
}
}
}
))
)
end
it "uses the general secrets for the main tenant" do
@@ -1060,7 +1060,7 @@ describe User do
context "when secrets are configured" do
before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
stub_secrets(
security: {
lockable: { unlock_in: "2" }
},
@@ -1071,7 +1071,7 @@ describe User do
}
}
}
))
)
end
it "uses the general secrets for the main tenant" do

View File

@@ -14,6 +14,7 @@ module CommonActions
include Polls
include Proposals
include RemoteCensusMock
include Secrets
include Tags
include Translations
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
before do
allow(Rails.application).to receive(:secrets).and_return(ActiveSupport::OrderedOptions.new.merge(
security: { password_complexity: true }
))
stub_secrets(security: { password_complexity: true })
end
context "Sign up" do