Skip to content

Commit

Permalink
Fix ActiveRecord version check in Rails 4.0
Browse files Browse the repository at this point in the history
Rails 4.0 does not have the `ActiveRecord.gem_version` method, so this
check will fail there. However, we know that if `gem_version` is not
available, we are not dealing with Rails >= 5.0, so this will work in
both cases.

See paper-trail-gem#956 for an equivalent case elsewhere in the codebase.
  • Loading branch information
magnusvk authored and aried3r committed Dec 14, 2020
1 parent d3fd67f commit 4fd0f5c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/paper_trail/version_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module VersionConcern
extend ::ActiveSupport::Concern

included do
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
if ::ActiveRecord.respond_to?(:gem_version) &&
::ActiveRecord.gem_version >= Gem::Version.new("5.0")
belongs_to :item, polymorphic: true, optional: true
else
belongs_to :item, polymorphic: true
Expand Down

0 comments on commit 4fd0f5c

Please sign in to comment.