Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:27:15+00:00 2026-05-22T02:27:15+00:00

I have a Rails 2.x app with no tests. I can write out the

  • 0

I have a Rails 2.x app with no tests. I can write out the tests manually, but is there a way to generate fixtures automatically? It would be nice to not have to type all that out by hand.

I could run script/generate again for all the models, but everything already exists and if I understand generators correctly, I’d still have to type in all the attributes.

I thought about running the Rails console and doing for example…

>> y VendorUser.all.rand

That would give me some YAML with all the attributes, but they’d be out of order and it’s still pretty time-consuming.

Can anyone suggest a more efficient option?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:27:16+00:00Added an answer on May 22, 2026 at 2:27 am

    Here is a rake task to generate fixtures.

    desc "extracting data for fixtures"
    task :extract_fixtures => :environment do
      sql  = "SELECT * FROM %s"
      skip_tables = ["schema_info","schema_migrations"]
      ActiveRecord::Base.establish_connection
      (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
        i = "000"
        File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w' ) do |file|
          data = ActiveRecord::Base.connection.select_all(sql % table_name)
          file.write data.inject({}) { |hash, record|
            hash["#{table_name}_#{i.succ!}"] = record
            hash
          }.to_yaml
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to have capistrano run unit tests on my Rails app
Is there a way to upload an app, but only have it accessible by
I have a rails app that has picked up a bit of traction, but
I have a rails app moving along fairly well, but the fact that I'm
I have a Rails 3rc app on Ruby 1.9.2 that works fine, but Bundler
I'm working on unit tests for my Rails app and have run into the
When working in Ruby (specifically, in Rails), I can automatically run my tests using
I am building an app for cognitive tests in Rails. I have a number
I have a very old and poorly written Rails app. There are about 9000
I have a rails app that I have serving up XML on an infrequent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.