Skip to content

Fix support for running without Rails #761

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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.gem_version >= Gem::Version.new("7.1")
if ::ActiveRecord.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/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def filter_attr_values(audited_changes: {}, attrs: [], placeholder: "[FILTERED]"
end

def rails_below?(rails_version)
Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new(rails_version)
::ActiveRecord.version < Gem::Version.new(rails_version)
end

def audits_to(version = nil)
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.gem_version >= Gem::Version.new("7.0")) ?
(::ActiveRecord.version >= Gem::Version.new("7.0")) ?
::ActiveRecord.timestamped_migrations :
::ActiveRecord::Base.timestamped_migrations
end
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

RSpec.configure do |config|
config.include AuditedSpecHelpers
config.use_transactional_fixtures = false if Rails.version.start_with?("4.")
config.use_transactional_tests = false if config.respond_to?(:use_transactional_tests=)
end

12 changes: 6 additions & 6 deletions spec/support/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ module Models
module ActiveRecord
class User < ::ActiveRecord::Base
audited except: :password
attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1")
attribute :non_column_attr if ::ActiveRecord.version >= Gem::Version.new("5.1")
attr_protected :logins if respond_to?(:attr_protected)

if Rails.gem_version >= Gem::Version.new("7.2")
if ::ActiveRecord.version >= Gem::Version.new("7.2")
enum :status, {active: 0, reliable: 1, banned: 2}
else
enum status: {active: 0, reliable: 1, banned: 2}
end

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

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

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

Expand Down Expand Up @@ -148,7 +148,7 @@ class Owner < ::ActiveRecord::Base
has_many :companies, class_name: "OwnedCompany", dependent: :destroy
accepts_nested_attributes_for :companies

if Rails.gem_version >= Gem::Version.new("7.2")
if ::ActiveRecord.version >= Gem::Version.new("7.2")
enum :status, {active: 0, reliable: 1, banned: 2}
else
enum status: {active: 0, reliable: 1, banned: 2}
Expand Down
2 changes: 1 addition & 1 deletion spec/support/active_record/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "logger"

begin
if ActiveRecord.version >= Gem::Version.new("6.1.0")
if ::ActiveRecord.version >= Gem::Version.new("6.1.0")
db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first
ActiveRecord::Tasks::DatabaseTasks.create(db_config)
else
Expand Down