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

Robustify Rails version checks #689

Merged
merged 1 commit into from
Jan 11, 2024
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
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