Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version to Integration #483

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/ddtrace/contrib/active_record/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ class Integration

register_as :active_record, auto_patch: false

def self.version
Gem.loaded_specs['activerecord'] && Gem.loaded_specs['activerecord'].version
end

def self.present?
super && defined?(::ActiveRecord)
end

def self.compatible?
super \
&& RUBY_VERSION >= '1.9.3' \
&& Gem.loaded_specs['activerecord'] \
&& Gem.loaded_specs['activerecord'].version >= Gem::Version.new('3.0') \
&& defined?(::ActiveRecord)
super && version >= Gem::Version.new('3.0')
end

def default_configuration
Expand Down
10 changes: 9 additions & 1 deletion lib/ddtrace/contrib/patchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ def self.included(base)

# Class methods for integrations
module ClassMethods
def version
nil
end

def present?
!version.nil?
end

def compatible?
RUBY_VERSION >= '1.9.3'
RUBY_VERSION >= '1.9.3' && present?
end
end

Expand Down
10 changes: 9 additions & 1 deletion lib/ddtrace/contrib/sequel/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ class Integration

register_as :sequel, auto_patch: false

def self.version
Gem.loaded_specs['sequel'] && Gem.loaded_specs['sequel'].version
end

def self.present?
super && defined?(::Sequel)
end

def self.compatible?
RUBY_VERSION >= '2.0.0' && defined?(::Sequel)
super && RUBY_VERSION >= '2.0.0'
end

def default_configuration
Expand Down
34 changes: 33 additions & 1 deletion spec/ddtrace/contrib/patchable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,42 @@
end

describe 'class behavior' do
describe '#version' do
subject(:compatible) { patchable_class.version }
it { is_expected.to be nil }
end

describe '#present?' do
subject(:compatible) { patchable_class.present? }

context 'when version' do
context 'is defined' do
let(:version) { double('version') }
before(:each) { allow(patchable_class).to receive(:version).and_return(version) }
it { is_expected.to be true }
end

context 'is not defined' do
it { is_expected.to be false }
end
end
end

describe '#compatible?' do
subject(:compatible) { patchable_class.compatible? }
let(:expected_compatibility) { RUBY_VERSION >= '1.9.3' ? true : false }
it { is_expected.to be expected_compatibility }

context 'when version' do
context 'is defined' do
let(:version) { double('version') }
before(:each) { allow(patchable_class).to receive(:version).and_return(version) }
it { is_expected.to be expected_compatibility }
end

context 'is not defined' do
it { is_expected.to be false }
end
end
end
end

Expand Down