{"id":24698592,"url":"https://github.com/faradayio/hangar","last_synced_at":"2025-05-09T00:10:03.308Z","repository":{"id":17232612,"uuid":"20001683","full_name":"faradayio/hangar","owner":"faradayio","description":"Use Rails/FactoryGirl factories from your frontend tests","archived":false,"fork":false,"pushed_at":"2019-04-12T13:22:55.000Z","size":80,"stargazers_count":55,"open_issues_count":3,"forks_count":15,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-09T00:09:55.857Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faradayio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-20T23:53:25.000Z","updated_at":"2024-02-08T19:53:47.000Z","dependencies_parsed_at":"2022-09-01T19:30:39.925Z","dependency_job_id":null,"html_url":"https://github.com/faradayio/hangar","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Fhangar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Fhangar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Fhangar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Fhangar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faradayio","download_url":"https://codeload.github.com/faradayio/hangar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166521,"owners_count":21864482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-27T04:29:25.590Z","updated_at":"2025-05-09T00:10:03.277Z","avatar_url":"https://github.com/faradayio.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hangar\n\nHangar is a Rails Engine that exposes your [FactoryBot](https://github.com/thoughtbot/factory_girl) factories with a REST API available in the test environment only\n\n## Install\n\nAdd Hangar to your application's Gemfile:\n\n``` ruby\ngem 'hangar', group: :test\n```\n\n## Requirements\n\nYour application must use FactoryBot to manage its factories. Follow [FactoryBot's documentation](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md) to add factories to your application.\n\n## Configuration\n\n### Protecting tables from deletion\n\nYou 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:\n\n``` ruby\n# config/initializers/hangar.rb\n\nHangar.do_not_delete = %w(very_important_things valuable_bitcoin_keys spatial_ref_sys) if defined?(Hangar)\n```\n\n### Specifying DatabaseCleaner deletion strategy\n\nNot all ORMs support the deletion strategy, such as mongoid. You can override the clean strategy being used by the `DELETE /factories` request as follows:\n\n``` ruby\n# config/initializers/hangar.rb\n\nHangar.clean_strategy = :truncation\n```\n\n### Namespace Routes\n\nIn some instances you may want to namespace the routes auto-generated by Hangar.\n\n``` ruby\n# config/initializers/hangar.rb\n\nHangar.route_namespace = :hangar\n```\n\n## Usage\n\nHangar will create two factory routes for each factory registered with FactoryBot. These routes mimic FactoryBot's `create` and `attributes_for` methods, respectively:\n\n```\nPOST /posts\nGET /posts/new\n```\n\nBoth will respond with a JSON representation of the object.\n\nHangar also provides a route to clean the database after each test:\n\n```\nDELETE /\n```\n\nThis returns 204 No Content when successful.\n\n### Overriding Factory Attributes\n\nYou may override factory properties on your GET and POST requests using JSON as follows:\n\n```\n{ \"post\": { \"title\": \"Dolor Sit Amet\" } }\n```\n\n### Specifying Traits\n\nYou may specify factory traits on your GET and POST requests using JSON as follows:\n\n\nTo specify traits POST the JSON as follows:\n\n```\n{ \"traits\": [\"published\"] }\n```\n\n### Specifying Returned JSON Attributes\n\nSpecifying 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.\n\n\nTo include associations POST the JSON as follows:\n\n```\n{ \"include\": \"comments\" }\n```\n\nTo specify which attributes to include on associations, POST the JSON as follows:\n{ \"include\": { \"comments\": { \"only\": \"text\" } } }\n\nIn this case, text is an attribute on our comments model.\n\n### Headers\n\nYou must include the following headers with your requests:\n\n```\nAccept: application/json; charset=utf-8\nContent-Type: application/json\nFactory: hangar\n```\n\n## Security\n\nHangar is designed to run in the *test environment only*. A warning will be displayed if it is loaded in any other environment.\n\n##For Contributors\n\nClone the github repository:\n\n    git clone https://github.com/faradayio/hangar.git\n    cd hangar\n    bundle install\n\nHangar's test suite runs against the included test application. Start that up with\n\n    rake spec\n\n## Corporate support\n\n\u003cp\u003e\u003ca href=\"http://faraday.io\"\u003e\u003cimg src=\"https://s3.amazonaws.com/creative.faraday.io/logo.png\" alt=\"Faraday logo\"/\u003e\u003c/a\u003e\u003c/p\u003e\n\nWe use `hangar` for [marketing analytics at Faraday](http://faraday.io).\n\n## Copyright\n\nCopyright 2014 Andy Rossmeissl\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaradayio%2Fhangar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaradayio%2Fhangar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaradayio%2Fhangar/lists"}