Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #2404: FK_constraint_cleanup.diff

File FK_constraint_cleanup.diff, 1.7 kB (added by anonymous, 3 years ago)

creates nuke_fixtures and adds it to teardown

  • vendor/rails/activerecord/lib/active_record/fixtures.rb

    old new  
    219219  cattr_accessor :all_loaded_fixtures 
    220220  self.all_loaded_fixtures = {} 
    221221 
     222  def self.nuke_fixtures(fixtures_directory, *table_names) 
     223    connection = block_given? ? yield : ActiveRecord::Base.connection 
     224    old_logger_level = ActiveRecord::Base.logger.level 
     225 
     226    begin 
     227      ActiveRecord::Base.logger.level = Logger::ERROR 
     228 
     229      connection.transaction do 
     230        table_names.reverse.each do |table_name| 
     231          connection.delete "DELETE FROM #{table_name}", 'Fixture Delete' 
     232        end 
     233      end 
     234       
     235      reset_sequences(connection, table_names) if connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) 
     236    ensure 
     237      ActiveRecord::Base.logger.level = old_logger_level 
     238    end 
     239  end 
     240 
    222241  def self.create_fixtures(fixtures_directory, *table_names) 
    223242    connection = block_given? ? yield : ActiveRecord::Base.connection 
    224243    old_logger_level = ActiveRecord::Base.logger.level 
     
    491510          ActiveRecord::Base.connection.rollback_db_transaction 
    492511          ActiveRecord::Base.unlock_mutex 
    493512        end 
     513        nuke_fixtures 
    494514      end 
    495515 
    496516      alias_method :teardown, :teardown_with_fixtures 
     
    517537      end 
    518538 
    519539      private 
     540        def nuke_fixtures 
     541          Fixtures.nuke_fixtures(fixture_path, *fixture_table_names)  
     542        end 
     543 
    520544        def load_fixtures 
    521545          @loaded_fixtures = {} 
    522546          fixtures = Fixtures.create_fixtures(fixture_path, fixture_table_names)