Skip to content

Commit

Permalink
Merge pull request #68 from sinsoku/fix_an_issue_that_finding_wrong_c…
Browse files Browse the repository at this point in the history
…leaner

Fix an issue recording table names to wrong cleaner
  • Loading branch information
amatsuda authored Jan 16, 2025
2 parents 29fe702 + 60e1b7c commit 13943a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/database_rewinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ def cleaners
def record_inserted_table(connection, sql)
config = connection.instance_variable_get(:'@config')
database = config[:database]
host = config[:host]
#NOTE What's the best way to get the app dir besides Rails.root? I know Dir.pwd here might not be the right solution, but it should work in most cases...
root_dir = defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : Dir.pwd
cleaner = cleaners.detect do |c|
if (config[:adapter] == 'sqlite3') && (config[:database] != ':memory:')
File.expand_path(c.db, root_dir) == File.expand_path(database, root_dir)
else
c.db == database
c.db == database && c.host == host
end
end or return

Expand Down
4 changes: 4 additions & 0 deletions lib/database_rewinder/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def db
config['database']
end

def host
config['host']
end

def clean(multiple: true)
return if !pool || inserted_tables.empty?

Expand Down

0 comments on commit 13943a3

Please sign in to comment.