Skip to content

Commit

Permalink
fix: fix specs for rails older than 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 5, 2024
1 parent 854f809 commit b698d28
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@
ActiveRecord::Base.logger = Logger.new($stdout)
end

active_record_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call

ActiveRecord::Base.configurations = {
active_record_env => {
primary: {
adapter: 'sqlite3',
database: '/tmp/esse-active_record.db',
},
secondary: {
adapter: 'sqlite3',
database: '/tmp/esse-active_record.db',
}
}
db_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s
db_path = '/tmp/esse-active_record.db'
db_config = {
adapter: 'sqlite3',
database: db_path,
}
if File.exist?('/tmp/esse-active_record.db')
File.delete('/tmp/esse-active_record.db')

if File.exist?(db_path)
File.delete(db_path)
end

if ::ActiveRecord.gem_version >= Gem::Version.new('6.0.0')
ActiveRecord::Base.configurations = { db_env => { primary: db_config, secondary: db_config } }
ActiveRecord::Base.establish_connection(:primary)
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: :primary, reading: :secondary }
end
else
ActiveRecord::Base.configurations = { db_env => db_config }
ActiveRecord::Base.establish_connection(db_config)
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
end
ActiveRecord::Base.establish_connection(:primary)

ActiveRecord::Schema.define do
self.verbose = false
Expand All @@ -45,14 +52,6 @@
end
end

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

if ::ActiveRecord.gem_version >= Gem::Version.new('6.0.0')
connects_to database: { writing: :primary, reading: :secondary }
end
end

class Animal < ApplicationRecord
end

Expand Down

0 comments on commit b698d28

Please sign in to comment.