No commit activity in last 3 years
No release in over 3 years
A Rails engine for mainpulating factories via API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.10
~> 1.3

Runtime

 Project Readme

factory_girl_api Gem Version

The factory_girl_api gem is a Rails Engine that integrates with factory_girl to add API routes for manipulating factories that can be used for context setup in frontend tests.

It cooperates with angular-factory-girl-api, which provides an Angular service that will make the proper requests to your server during tests.

Installation

Add factory_girl_api to your Gemfile:

group :test do
  gem 'factory_girl_api'
end

Then mount the engine in your routes file:

Rails.application.routes.draw do
  mount FactoryGirlApi::Engine => '/api/v1/test_helpers' if Rails.env.test?
end

Routes Added

The factory_girl_api gem adds three routes at the location it is mounted at.

Method Route Description
POST /factories Calls FactoryGirl.create and returns the result
POST /database Sets up the database
DELETE /database Rolls back the database to a clean state

POST /factories

This is the primary endpoint installed by the gem. It accepts the following parameters:

{
  factory: {
    name: 'string',
    attributes: { object ... },
    traits: [ array ... ]
  }
}

The name parameter is required. All other parameters are optional. When used, this calls FactoryGirl.create with the provided options, then renders the resulting model as JSON.

Since this calls FactoryGirl.create, it will modify the database, so it should be surrounded by calls to /database to control database cleanup.

POST /database

This endpoint does nothing on its own. Each usage of this endpoint should be paired with a call to DELETE /database, which will delete all records created in the database between the two calls.

DELETE /database

Uses DatabaseCleaner to delete all records created since the previous call to POST /database. This can be used to clean up DB context after creating records with factories.