GithubHelp home page GithubHelp logo

bookingbug / hangar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from faradayio/hangar

0.0 45.0 0.0 153 KB

Use Rails/FactoryGirl factories from your frontend tests

License: MIT License

Ruby 95.52% JavaScript 2.09% CSS 2.39%

hangar's Introduction

Hangar

Hangar is a Rails Engine that exposes your FactoryGirl factories with a REST API available in the test environment only

Install

Add Hangar to your application's Gemfile:

gem 'hangar', group: :test

Requirements

Your application must use FactoryGirl to manage its factories. Follow FactoryGirl's documentation to add factories to your application.

Configuration

Protecting tables from deletion

You may have special tables in your test database that should not be cleared by Hangar after a DELETE / request (see below in Usage). In this case, create an initializer in your app as follows:

# config/initializers/hangar.rb

Hangar.do_not_delete = %w(very_important_things valuable_bitcoin_keys spatial_ref_sys) if defined?(Hangar)

Specifying DatabaseCleaner deletion strategy

Not all ORMs support the deletion strategy, such as mongoid. You can override the clean strategy being used by the DELETE / request as follows:

# config/initializers/hangar.rb

Hangar.clean_strategy = :truncation

Usage

Hangar will create two factory routes for each factory registered with FactoryGirl. These routes mimic FactoryGirl's create and attributes_for methods, respectively:

POST /posts
GET /posts/new

Both will respond with a JSON representation of the object.

Hangar also provides a route to clean the database after each test:

DELETE /

This returns 204 No Content when successful.

Overriding Factory Attributes

You may override factory properties on your GET and POST requests using JSON as follows:

{ "post": { "title": "Dolor Sit Amet" } }

Specifying Returned JSON Attributes

Specifying JSON attributes to return is the same as the ActiveModel::Serializer's as_json() include option. In the below examples, comments is a has_many association of our model.

To include associations POST the JSON as follows:

{ "include": "comments" }

To specify which attributes to include on associations, POST the JSON as follows: { "include": { "comments": { "only": "text" } } }

In this case, text is an attribute on our comments model.

Headers

You must include the following headers with your requests:

Accept: application/json; charset=utf-8
Content-Type: application/json    
Factory: hangar

Security

Hangar is designed to run in the test environment only. A warning will be displayed if it is loaded in any other environment.

Corporate support

Faraday logo

We use hangar for marketing analytics at Faraday.

Copyright

Copyright 2014 Andy Rossmeissl

hangar's People

Contributors

rossmeissl avatar ihough avatar felixfortis avatar seamusabshere avatar

Watchers

Glenn avatar Greg Bock avatar Fawad avatar James Williamson avatar Chris Maximin avatar  avatar Niall Giggins avatar Richard Kettle avatar Edward Clements avatar Daniel O Farrow avatar Nicholas Lowman avatar Damian Pudlo avatar James Cloos avatar DJ Patterson avatar Gwe Limpalaer avatar António Pacheco avatar Antonia H. avatar Carlos avatar Alan Bennett avatar Luke Ferguson avatar Jakub Adler avatar Terrance Mutizwa avatar  avatar James avatar Bank Lee avatar Nuno Costa avatar Flavio Tulino avatar GoodViber avatar Richard avatar  avatar Nicolas Klein avatar Piotr Siatkowski avatar Dean Palmer avatar  avatar Andy Wingrave avatar  avatar  avatar jack fenton avatar  avatar  avatar Sergiu Merticariu avatar  avatar Joel avatar Thao Vo avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.