FactoryGirl
, and DB testing in general in unit-testing is intended for internal representation of the DB for the test you are running, and provide no assurances about changing the state the DB outside the test.
Your architecture as you describe it calls a REST call inside the test. This is very discouraged in respc:
Requests to external services during test runs can cause several issues:
- Tests failing intermittently due to connectivity issues.
- Dramatically slower test suites.
- Hitting API rate limits on 3rd party sites (e.g. Twitter).
- Service may not exist yet (only documentation for it).
- Service doesn't have a sandbox or staging server.
IMHO, you should not test it as a DB use-case, but as a RestClient
use-case, since your code does not directly call the database, but rather calls the REST API.
Write one test which stubs the REST API for the client side of the test, and another, setting the DB, to test the server-side of the REST API (testing that the REST call receives the expected result).