Skip to content

ORM::Factory

The latest version of this documentation lives at https://gdonald.github.io/ORM-Factory/.

The homepage for ORM::Factory is https://github.com/gdonald/ORM-Factory.

Synopsis

ORM::Factory is a definition DSL for building test objects (with or without persistence) so your specs stay declarative.

It is ORM-agnostic at its core. With ORM::ActiveRecord installed and auto-detected, create persists through the model's save-bang with validations, callbacks, and timestamps intact. With no ORM loaded, factories still build plain objects, and the to-create / initialize-with hooks let you target any persistence layer.

Example usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
use ORM::Factory;

define {
  .factory: 'user', {
    .fname: 'Greg';
    .lname: 'Donald';
    .email: { 'user@example.com' };

    .variant: 'admin', {
      .role: 'admin';
    };
  };
};

Install

ORM::Factory can be installed using the zef module installation tool:

1
zef install --/test ORM::Factory

--/test is suggested because the full suite exercises every supported adapter (PostgreSQL, MySQL, SQLite). The library itself has no runtime dependencies; ORM::ActiveRecord is a test-depends and is auto-detected at runtime when installed.

Where to go next

  • Getting started — define and use your first factory.
  • DSL design — the rationale behind the topic-$_ + FALLBACK DSL surface.
  • Tests — running the suite, the t/specs/ mirror convention, and the db/ vs unit layout.