Skip to content

Commit

Permalink
Install Puma hook only for Puma 3 and newer
Browse files Browse the repository at this point in the history
Set some limit for our Puma hook so we don't break apps using an older
Puma. Version 2 and 3 have the biggest difference I could find for the
things we rely on so I've set the limit there.
  • Loading branch information
tombruijn committed Aug 30, 2024
1 parent 62c2303 commit 4fab861
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changesets/drop-support-for-puma-2-and-lower.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: remove
---

Drop support for Puma version 2 and lower.
3 changes: 2 additions & 1 deletion lib/appsignal/hooks/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class PumaHook < Appsignal::Hooks::Hook
register :puma

def dependencies_present?
defined?(::Puma)
defined?(::Puma) &&
Gem::Version.new(Puma::Const::VERSION) >= Gem::Version.new("3.0.0")
end

def install
Expand Down
37 changes: 33 additions & 4 deletions spec/lib/appsignal/hooks/puma_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
describe Appsignal::Hooks::PumaHook do
context "with puma" do
before(:context) do
class Puma
let(:puma_version) { "6.0.0" }
before do
class TestPuma
def self.stats
end

def self.cli_config
@cli_config ||= CliConfig.new
end

class Server
end

module Const
end
end
TestPuma::Const::VERSION = puma_version

class CliConfig
attr_accessor :options
Expand All @@ -17,13 +25,34 @@ def initialize
@options = {}
end
end

stub_const("Puma", TestPuma)
end
after(:context) { Object.send(:remove_const, :Puma) }

describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }

it { is_expected.to be_truthy }
context "when Puma present" do
context "when Puma is newer than version 3.0.0" do
let(:puma_version) { "3.0.0" }

it { is_expected.to be_truthy }
end

context "when Puma is older than version 3.0.0" do
let(:puma_version) { "2.9.9" }

it { is_expected.to be_falsey }
end
end

context "when Puma is not present" do
before do
hide_const("Puma")
end

it { is_expected.to be_falsey }
end
end

describe "installation" do
Expand Down

0 comments on commit 4fab861

Please sign in to comment.