Comments (1)
A quick (ie, no proper tests, bad me) edit suggests something like this solves the STDERR
warnings we're seeing on tests with no DB interaction:
diff --git a/lib/database_plumber/leak_finder.rb b/lib/database_plumber/leak_finder.rb
index b6e230a..8f5ca1c 100644
--- a/lib/database_plumber/leak_finder.rb
+++ b/lib/database_plumber/leak_finder.rb
@@ -3,12 +3,12 @@ module DatabasePlumber
IGNORED_AR_INTERNALS = [ActiveRecord::SchemaMigration]
private_constant :IGNORED_AR_INTERNALS
- def self.inspect(options={})
- self.new(options).inspect
+ def self.inspect(options = {})
+ new(options).inspect
end
def initialize(options)
- @ignored_models = ( options[:ignored_models] || [] ) + IGNORED_AR_INTERNALS
+ @ignored_models = (options[:ignored_models] || []) + IGNORED_AR_INTERNALS
@ignored_adapters = options[:ignored_adapters] || []
end
@@ -29,11 +29,11 @@ module DatabasePlumber
return 0 if no_table?(model)
model.count
rescue ActiveRecord::StatementInvalid
- fail InvalidModelError, "#{model} does not have a valid table definition"
+ raise InvalidModelError, "#{model} does not have a valid table definition"
end
def mop_up(model)
- model.destroy_all
+ model.destroy_all unless model.name =~ /^HABTM_/
end
def no_table?(model)
@@ -48,6 +48,8 @@ module DatabasePlumber
def model_space
ActiveRecord::Base.descendants
+ rescue ActiveRecord::StatementInvalid
+ []
end
end
end
diff --git a/spec/lib/database_plumber/leak_finder_spec.rb b/spec/lib/database_plumber/leak_finder_spec.rb
index fca9b6e..6136f6c 100644
--- a/spec/lib/database_plumber/leak_finder_spec.rb
+++ b/spec/lib/database_plumber/leak_finder_spec.rb
@@ -2,11 +2,11 @@ RSpec.describe DatabasePlumber::LeakFinder do
let(:normal_connection) { double(:connection, adapter_name: 'NotSQLite') }
let(:ignored_connection) { double(:connection, adapter_name: 'SQLite' ) }
- let(:happy_model) { double(:happy, abstract_class?: nil, connection: normal_connection, count: 0) }
- let(:leaky_model) { double(:leaky, abstract_class?: nil, connection: normal_connection, count: 1) }
- let(:abstract_model) { double(:abstract, abstract_class?: true, connection: normal_connection, count: 2) }
- let(:ignored_model) { double(:ignored, abstract_class?: nil, connection: normal_connection, count: 3) }
- let(:ignored_adapter_model) { double(:anon, abstract_class?: nil, connection: ignored_connection, count: 4) }
+ let(:happy_model) { double(:happy, abstract_class?: nil, connection: normal_connection, count: 0, name: 'Happy') }
+ let(:leaky_model) { double(:leaky, abstract_class?: nil, connection: normal_connection, count: 1, name: 'Leaky') }
+ let(:abstract_model) { double(:abstract, abstract_class?: true, connection: normal_connection, count: 2, name: 'Abstract') }
+ let(:ignored_model) { double(:ignored, abstract_class?: nil, connection: normal_connection, count: 3, name: 'Ignored') }
+ let(:ignored_adapter_model) { double(:anon, abstract_class?: nil, connection: ignored_connection, count: 4, name: 'Anon') }
let(:globally_ignored_models) { [ActiveRecord::SchemaMigration] }
from database_plumber.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from database_plumber.