Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify which tables should be emptied #1

Open
jfahrenkrug opened this issue May 20, 2009 · 0 comments
Open

Specify which tables should be emptied #1

jfahrenkrug opened this issue May 20, 2009 · 0 comments

Comments

@jfahrenkrug
Copy link

Using dataset erased all data from all tables in the test db. In my case, working with a legacy database that only needs to be read from, this is a Bad Thing. This monkey patch at the bottom of spec_helper.rb helps:


module Dataset
  module Database # :nodoc:
    
    # Provides Dataset a way to clear, dump and load databases.
    class Base
      include FileUtils
      
      def clear
        connection = ActiveRecord::Base.connection
        ActiveRecord::Base.silence do
          connection.tables.each do |table_name|
            unless %w{table_to_keep another_table even_another_table}.include? (table_name)
              puts "Emptying #{table_name}"
              connection.delete "DELETE FROM #{connection.quote_table_name(table_name)}",
                "Dataset::Database#clear" unless table_name == ActiveRecord::Migrator.schema_migrations_table_name
            else
              puts "Skipping #{table_name}"
            end
          end
        end
      end
    end
  end
end

It would be great to have a setting in dataset that lets me specify either which tables NOT to empty and/or which tables TO empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant