DatabaseCleaner::RemoteApi
Simply creates an HTTP API for cleaning your database to be used by client tests.
Tested against ruby-head, ruby 2.0.0, ruby 1.9.3, jruby-19mode, jruby-head, and rbx-19mode
Installation
Add this line to your application's Gemfile:
gem 'database_cleaner-remote_api', '~> 0.0.1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install database_cleaner-remote_api
Then mount as an engine in your config/routes.rb file.
Rails.application.routes.draw do
...
mount DatabaseCleaner::RemoteApi::Engine => '/database_cleaner' if Rails.env.test?
...
end
Usage
First install DatabaseCleaner.
To use with a client application, start rails in the test
environment (or whichever environment mounted the engine).
$ rails server -e test
Then you can clean the database remotely via /mount_path/clean
Example
Given a user in the database:
User.count #=> 1
When you clean the database via any client:
$ curl http://localhost:3000/database_cleaner/clean
Then the users have been removed:
User.count #=> 0
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request