Skip to content

Commit

Permalink
Fix configure call without env when it has config (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombruijn authored Jul 30, 2024
1 parent cf08125 commit 65d5428
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changesets/fix-configure-config-reuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: fix
---

Fix `Appsignal.configure` call without `env` argument not reusing the previously configured configuration.
2 changes: 1 addition & 1 deletion lib/appsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def configure(env = nil)
return
end

if config && config.env == env.to_s
if config && (env.nil? || config.env == env.to_s)
config
else
@config = Config.new(
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/appsignal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
end

context "with config but not started" do
it "reuses the already loaded config if no env arg is given" do
Appsignal._config = Appsignal::Config.new(
project_fixture_path,
:my_env,
:ignore_actions => ["My action"]
)

Appsignal.configure do |config|
expect(config.env).to eq("my_env")
expect(config.ignore_actions).to eq(["My action"])

config.active = true
config.name = "My app"
config.push_api_key = "key"
end
expect(Appsignal.config.valid?).to be(true)
expect(Appsignal.config.env).to eq("my_env")
expect(Appsignal.config[:name]).to eq("My app")
expect(Appsignal.config[:push_api_key]).to eq("key")
expect(Appsignal.config[:ignore_actions]).to eq(["My action"])
end

it "reuses the already loaded config if the env is the same" do
Appsignal._config = Appsignal::Config.new(
project_fixture_path,
Expand Down

0 comments on commit 65d5428

Please sign in to comment.