Ruby on Rails: access to production database data for testing

With Ruby on Rails, is there a way to dump my production database into a form that the Rails test part can access?

I’m thinking about turning a production database into fixtures, or a way to transfer data from a production database to a test database that Rails will not regularly clean up.

I would like to use this data for various tests, but first of all, I use real data with performance tests so that I can get a realistic understanding of load time.

+5
source share
3

, helper rspec, ( , ) .

:

require 'yaml'

def accounts
  @accounts ||= lambda {
    config = YAML.load_file("#{Rails.root}/config/database.yml")['production']

    dbh = Mysql.real_connect(config['host'], config['username'], config['password'], config['database'])

    accounts = []
    result = dbh.query("SELECT `accounts`.* FROM `accounts`")
    while row = result.fetch_hash do
      row.delete("id")
      accounts << Account.make(row)
    end

    dbh.close

    return accounts
  }.call
end
+2

seed.rb db, . Railscasts : http://railscasts.com/episodes?search=seed

, . !

0

All Articles