Project

stockpot

0.01
Low commit activity in last 3 years
No release in over a year
Exposes a few end points from your app, easily enabling CRUD actions on your database that you can utilize from things like a standalone test suite to set up state. (think: Cypress, Cucumber, etc.)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.0.6
~> 5.0.2
~> 0.21.2
~> 1.2.3
~> 0.13.0

Runtime

 Project Readme

Stockpot

Stockpot makes setting up test data in your Rails database from an external resource easier.

Gem Version

Stockpot gives you an easy way to expose a number of end points from your app, enabling CRUD actions that you can utilize from things like a standalone test suite to set up state. For instance, rather than going through the entirety of a new user creation flow just to check that users can update their data once registered, simply make a POST call to /stockpot/database_management with your dummy user's data, shortcutting that unnecessary setup and enabling you to go to directly checking the system behavior needed.

Use it in your external Cypress or Cucumber tests, set up a webpage to allow manual testers to set up and get state with an interface fronting the API, etc.

Why the name Stockpot? Keeping with Freshly's food related naming, a stockpot is one of the most common types of cooking pots worldwide, and a stockpot is traditionally use to make stock or broth which can be the basis for cooking more complex recipes. You put ingredients in, do some cooking, and take out a finished product. For this project, think of your database as being the stockpot, putting in test data, doing some action in the system under test, and then pulling out data to use in your assertions of your system's behavior.

Version 0.1.x Notes

Initial development notes: Stockpot is very much a work in progress. The initial implementation is mostly an abstraction of Freshly's current usage of controllers to allow our external Cypress test project to interact with our Rails app's database. The current pie in the sky plan is to genericize things more so that different tools can be used and allow folk's more configuration options.

  • Installation
  • Usage
  • Development
  • Contributing
  • License

Installation

Add this line to your application's Gemfile:

gem 'stockpot'

And then execute:

bundle

Or install it yourself as:

gem install stockpot

Usage


Rails App

!! Warning !!

You should only enable this in environments that are NOT production. If you choose to ignore this warning, do so at your own risk!! Wrap the following in a check for environments with something like Rails.env.test? if you don't have anything else in place.

Add the Stockpot engine to your /config/routes.rb file, changing the base path if you'd like to:

mount Stockpot::Engine, at: "/stockpot"

This will give you the following routes (assuming the default "/stockpot" path):

/stockpot/records

GET

Query for data. Accepts a array of objects that require at least a model name, but can also include additional qualifying data.

[
  { model: "user" },
  { model: "address" }
]
// or
[
  { model: "user", id: "foo"
]

POST

Create new data. Accepts an an array of objects specifying a single model with additional qualifiers.

  • factory (required) - Specify which factory to create a record with.
  • list (optional) - Specify a count of items to create, default: 1
  • traits (optional) - An array of strings specifying any traits you may want to use with your data. Applies to all records created.
  • attributes (optional) - An array of objects allowing for the specification of data to be used when creating records. Array position matches with list order if multiple records are desired.
[{
  factory: "user",
  traits: ["having_address"],
  attributes: [{
    email: "foo@bar.com",
    password: "baz",
    first_name: "Foo",
    last_name: "Bar"
  }]
}]

DELETE

Remove data. Accepts the same type of input as GET

PUT

Update data Accepts an array of objects with each object specifying the model type to be updated along with the data to update. Input is uses the same base as GET and DELETE, but also accepts an update object allowing for the specification of the data to be updated.

[
  {
    model: "user",
    user_id: "123",
    update: {
      status: "active",
      email: "foo@bar.com"
    }
  }
]

/stockpot/clean_database

DELETE

Clears Rails & Redis caches and truncates Active Records databases. No body required.

/stockpot/redis

GET

Query for data. Accepts key or field to use to search cache for record.

{
  key: "123",
  field: "foo"
}

GET - Keys

Query for all keys within data. No body or argument required.

POST - Create new data

Accepts an object specifying a key, field, and value to be inserted into Redis cache.

{
  key: "123",
  field: "foo",
  value: "bar"
}

Cypress/External Suite Examples

We utilize Cypress commands to abstract out helpers for setting up state such as

Cypress.Commands.add("getRecords", args => {
  cy.request({
    method: "GET",
    url: "stockpot/records",
    body: {
      models: args
    }
  })
})

Our tests can then call this command like this

cy.getRecords([{ model: "user", id: user.id }])
  .then(res => {
    expect(newEmail).to.eql(res.body.users[0].email)
  })

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. To install this gem onto your local machine, run bundle exec rake install.

See the next section on contributing for more info.

Contributing

This Open Source is supported by Freshly, a company committed to quality code and delicious food.

We're basically always hiring.

Come join us in our New York City, Phoenix, or Minsk offices and write some awesome software!

Community support is always appreciated! Bug reports and pull requests are welcome on GitHub.

Please read our CONTRIBUTING doc for more information!

License

The gem is available as open source under the terms of the MIT License.