On Sep 20, 2008, at 8:53 PM, Ben Mabey wrote:

Ben Mabey wrote:
Scott Taylor wrote:

On Sep 20, 2008, at 7:18 PM, Ben Mabey wrote:


Todd Tyree wrote:

Ok, here's what I've come up with on the spur of the moment (goes in
spec_helper.rb):

config.after(:each) do
  result = ActiveRecord::Base.connection.execute('SHOW TABLES;')
  while table = result.fetch_row
    # Or whatever you think is appropriate.
next if table.index('schema_migrations') or table.index('roles')
    ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
  end
end


I've used a similar method before.. However, your 'SHOW TABLES' and next
is not needed:


(ActiveRecord::Base.connection.tables - %w{schema_migrations}).each do
|table_name|

Yeah, that's just a cleaner way of doing it - I'm sure if you tailed
your logs you'd find a 'SHOW TABLES'


Yeah, depending on the rails environment it probably and caching it
probably would.


English FAIL.  I meant to say:

Yeah, depending on the rails environment and caching settings it probably would.

Does ActiveRecord cache table names? I'm well aware of it caching table columns:

http://github.com/smtlaissezfaire/smt_migration_fixes/tree/master/lib/smt/migration_fixes.rb

Scott

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to