Skip to content

Commit

Permalink
Merge pull request #129 from cupnoodle/cupnoodle-patch-1
Browse files Browse the repository at this point in the history
Fix spec environment and deprecation warning seen with ActiveRecord v 7.1
  • Loading branch information
cupnoodle committed Oct 23, 2023
2 parents 4843475 + 442765f commit 30a52cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/sinatra/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ def self.registered(app)
app.helpers ActiveRecordHelper

# re-connect if database connection dropped (Rails 3 only)
app.before { ActiveRecord::Base.verify_active_connections! if ActiveRecord::Base.respond_to?(:verify_active_connections!) }
app.after { ActiveRecord::Base.clear_active_connections! }
app.before do
if ActiveRecord::VERSION::MAJOR == 3
ActiveRecord::Base.verify_active_connections! if ActiveRecord::Base.respond_to?(:verify_active_connections!)
end
end
app.after do
if ActiveRecord::VERSION::MAJOR < 7
ActiveRecord::Base.clear_active_connections!
else
ActiveRecord::Base.connection_handler.clear_active_connections!
end
end
end

def database_file=(path)
Expand Down
2 changes: 2 additions & 0 deletions spec/sinatra/activerecord/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def invoke(*args)

it "has all the rake tasks working" do
begin
# by default we configure a development database
ENV['RAILS_ENV'] = 'development'
ENV["NAME"] = "create_users"

Rake::Task["db:create"].invoke
Expand Down

0 comments on commit 30a52cf

Please sign in to comment.