Skip to content

afast/factory_fixtures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FactoryFixtures

FactoryFixtures is a Rails engine that provides an easier integration with Factory Girl.

Because Factory Girl it's not a direct reaplacement for yaml fixtures, this gem allows us to use factory_girl features when writing fixtures.

It currently offers one feature:

  • Load fixtures written with factory girl syntax
  • has_and_belongs_to_many associations
  • Fixtures load when executing tests

And it's planned to support this features:

  • Polymorphic associations

Supported ORMs:

  • ActiveRecord

Usage

Invoke the task factory_fixtures:load $ rake factory_fixtures:load

This task will load the defined fixtures into the database

Files

Given an Account model create a file named test/factory_fixtures/accounts.rb

Defining factories

define :verified_account do |a| a.is_verified true a.address { |a| "#{rand 100} - #{a.company}" } a.zip { "#{rand 10}" * 5 } end

Creating fixtures based on previously defined factories

create :test_poc, :verified_account do company 'test_poc' end

If the factory is not specified it will use a default factory with empty default values.

Fidding associations

create :super_account, :verified_account do company 'super' distributor F(:distributor_mega) end

Invoke F method to fed up associations. :distributor_mega it's the name of a fixture, so distributor F(:distributor_mega) will set the column distributor_id to the identifier of the object :distributor_mega.

Loading fixtures on rails unit tests

The unit tests classes must inherit FactoryFixtures::Unit::TestCase

class UserTest < FactoryFixtures::Unit::TestCase end

In the test methods users returns a hash with the fixtures' names as keys and the fixtures as values

factory_fixtures :accounts, :users, :devices

factory_fixtures loads the specified fixtures files and creates method whose names are the fixtures' names.

License

Copyright (c) 2010 "snmgian" / "mooveit", released under LGPL v3 license.

Contact

Contact at: snmgian at gmail dot com, gian.zas at moove-it dot com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages