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

Ticket #10742 (closed enhancement: fixed)

Opened 4 months ago

Last modified 4 months ago

[PATCH] Cleanup ActiveRecord test infrastructure

Reported by: jbarnette Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc:

Description

I've had a few problems easily finding/organizing things as I've worked on a full Fixtures refactoring. This patch separates unit tests, migrations, schema, fixtures, fixture models, and assets into separate directories. When applied, the test directory structure should look like this (diffing won't capture the directories properly):

activerecord/
  test/
    active_record/   # all the unit tests
    support/
      assets/        # test files for binary fixtures, etc
      connections/   # the test connection adapters
      fixtures/      # the YAML and CSV fixtures
      migrations/    # the various test migration sets
      models/        # the test models, most matching fixtures
      schema/        # the schema for the test databases
    test_helper.rb   # a cleaned-up version of abstract_unit.rb

This patch also takes AR most of the way to a setup where it'll be easy to run a single test file as a Ruby script, sans Rake.

This is a first cut. Assuming we want to go this direction, it may take a revision or two.

Change History

01/09/08 01:13:52 changed by jbarnette

Because this is a ridiculously large patch, you can find it here: http://geeksomnia.com/downloads/cleanup-test-infrastructure.diff

(follow-up: ↓ 3 ) 01/09/08 01:23:03 changed by chuyeow

I really like the way this is going. It's true, the current organization of the test/ directory is rather haphazard, and though eventually one should be able to wrap your head around it, having an nice hierarchy like what you are proposing is great.

I haven't applied your patch to verify it (can you attach it to the ticket too or does Trac reject it?).

(in reply to: ↑ 2 ) 01/09/08 01:34:13 changed by jbarnette

Yup, Trac has a (reasonable) size limit on attachments. I've linked it above for the moment.

01/09/08 03:19:28 changed by nzkoz

I definitely like the idea of tidying up those files, in addition to directory changes, they can probably do with some busting up too.

The active_record directory seems completely redundant though, what's with that?

01/09/08 04:24:49 changed by jbarnette

Yeah, I'd love to refactor a bunch of the files as well. I figured that getting the big, chunky changes done first would probably be best.

I pulled out the test/active_record directory because I was looking for a way to avoid directory conflicts: the fixtures directory, for example, was conflicting with a fixtures subdirectory I wanted to add for a bunch of refactored fixtures testcases.

With that in mind, and thinking that test/test sucked, having a test/active_record seemed nicely complementary to lib/active_record. Did you have something else in mind?

01/09/08 06:16:19 changed by bitsweat

test/cases maybe?

01/09/08 06:20:56 changed by jbarnette

Sold! :)

01/10/08 03:15:12 changed by bitsweat

I recently removed all the absolute abstract_unit requires in favor of using a consistent load path and a simple require 'abstract_unit' everywhere. This goes back to absolute requires of test_helper; could you update?

01/10/08 04:25:53 changed by jbarnette

All interested, work towards this ticket is available from http://git.geeksomnia.com/rails, in the ar-test-cleanup branch. The current directory structure differs slightly from what's above:

activerecord/
  test/
    assets/        # test files for binary fixtures, etc
    cases/         # all the unit tests, plus...
      helper.rb    # a cleaned-up version of abstract_unit.rb
    config.rb      # various test-related paths, also used by Rakefile
    connections/   # the test connection adapters
    fixtures/      # the YAML and CSV fixtures
    migrations/    # the various test migration sets
    models/        # the test models, most matching fixtures
    schema/        # the schema for the test databases

01/18/08 07:31:55 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [8662]) Organize and clean up the Active Record test suite. Closes #10742.