Skip to content

Commit

Permalink
Merge pull request #689 from blaet/robustify-rails-version-checks
Browse files Browse the repository at this point in the history
Robustify Rails version checks
  • Loading branch information
danielmorrison committed Jan 11, 2024
2 parents e361f02 + e163219 commit 4606723
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/audited/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Audit < ::ActiveRecord::Base
cattr_accessor :audited_class_names
self.audited_class_names = Set.new

if Rails.version >= "7.1"
if Rails.gem_version >= Gem::Version.new("7.1")
serialize :audited_changes, coder: YAMLIfTextColumnType
else
serialize :audited_changes, YAMLIfTextColumnType
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/audited/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def next_migration_number(dirname) # :nodoc:
private

def timestamped_migrations?
(Rails.version >= "7.0") ?
(Rails.gem_version >= Gem::Version.new("7.0")) ?
::ActiveRecord.timestamped_migrations :
::ActiveRecord::Base.timestamped_migrations
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Application < Rails::Application
ActiveSupport::TimeWithZone ActiveSupport::TimeZone ActiveSupport::HashWithIndifferentAccess]
end

if Rails.version >= "7.1"
if Rails.gem_version >= Gem::Version.new("7.1")
config.active_support.cache_format_version = 7.1
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/support/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Models
module ActiveRecord
class User < ::ActiveRecord::Base
audited except: :password
attribute :non_column_attr if Rails.version >= "5.1"
attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1")
attr_protected :logins if respond_to?(:attr_protected)
enum status: {active: 0, reliable: 1, banned: 2}

if Rails.version >= "7.1"
if Rails.gem_version >= Gem::Version.new("7.1")
serialize :phone_numbers, type: Array
else
serialize :phone_numbers, Array
Expand All @@ -27,7 +27,7 @@ class UserExceptPassword < ::ActiveRecord::Base

class UserOnlyPassword < ::ActiveRecord::Base
self.table_name = :users
attribute :non_column_attr if Rails.version >= "5.1"
attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1")
audited only: :password
end

Expand Down

0 comments on commit 4606723

Please sign in to comment.