View caching working with the schema_plus gem
The schema_plus gem also provides a view method that does not do caching (in line with other connection method like tables). As database_cleaner should not be the provider of such functionality for external usage give the method a gem specific name.
This commit is contained in:
parent
ee83a3b295
commit
500f971049
|
@ -1,5 +1,7 @@
|
|||
== 0.8.x (in git)
|
||||
|
||||
* view caching works with the schema_plus gem loaded
|
||||
* ActiveRecord::ConnectionAdapters::AbstractAdapter#views was renamed to an internal name
|
||||
* ActiveRecord truncation strategy caches the list of tables #130 (Petteri Räty)
|
||||
|
||||
== 0.8.0 2012-06-02
|
||||
|
|
|
@ -9,7 +9,9 @@ module ActiveRecord
|
|||
USE_ARJDBC_WORKAROUND = defined?(ArJdbc)
|
||||
|
||||
class AbstractAdapter
|
||||
def views
|
||||
# used to be called views but that can clash with gems like schema_plus
|
||||
# this gem is not meant to be exposing such an extra interface any way
|
||||
def database_cleaner_view_cache
|
||||
@views ||= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue []
|
||||
end
|
||||
|
||||
|
@ -142,7 +144,7 @@ module DatabaseCleaner::ActiveRecord
|
|||
private
|
||||
|
||||
def tables_to_truncate(connection)
|
||||
(@only || connection.database_cleaner_table_cache) - @tables_to_exclude - connection.views
|
||||
(@only || connection.database_cleaner_table_cache) - @tables_to_exclude - connection.database_cleaner_view_cache
|
||||
end
|
||||
|
||||
# overwritten
|
||||
|
|
|
@ -25,7 +25,7 @@ module DatabaseCleaner
|
|||
|
||||
before(:each) do
|
||||
connection.stub!(:disable_referential_integrity).and_yield
|
||||
connection.stub!(:views).and_return([])
|
||||
connection.stub!(:database_cleaner_view_cache).and_return([])
|
||||
::ActiveRecord::Base.stub!(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
|
@ -64,7 +64,7 @@ module DatabaseCleaner
|
|||
|
||||
it "should not truncate views" do
|
||||
connection.stub!(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
connection.stub!(:views).and_return(["widgets"])
|
||||
connection.stub!(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
|
||||
connection.should_receive(:truncate_tables).with(['dogs'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue