Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcrumm/req_sandbox
Req plugin for Phoenix Ecto SQL Sandbox
https://github.com/mcrumm/req_sandbox
ecto elixir integration-testing phoenix postgresql
Last synced: 12 days ago
JSON representation
Req plugin for Phoenix Ecto SQL Sandbox
- Host: GitHub
- URL: https://github.com/mcrumm/req_sandbox
- Owner: mcrumm
- License: mit
- Created: 2022-10-22T00:45:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-13T19:17:46.000Z (about 2 months ago)
- Last Synced: 2024-10-13T09:55:54.798Z (26 days ago)
- Topics: ecto, elixir, integration-testing, phoenix, postgresql
- Language: Elixir
- Homepage: https://hexdocs.pm/req_sandbox
- Size: 57.6 KB
- Stars: 25
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# ReqSandbox
![Photo of a toy truck in a sandbox](https://user-images.githubusercontent.com/168677/197939037-750429a1-de19-461b-aa95-1284fe54950e.jpg)
Photo by Takeshi Morisato on Unsplash[![CI](https://github.com/mcrumm/req_sandbox/actions/workflows/ci.yml/badge.svg)](https://github.com/mcrumm/req_sandbox/actions/workflows/ci.yml)
[![Docs](https://img.shields.io/badge/hex.pm-docs-8e7ce6.svg)](https://hexdocs.pm/req_sandbox)
[![Hex pm](http://img.shields.io/hexpm/v/req_sandbox.svg?style=flat&color=blue)](https://hex.pm/packages/req_sandbox)[Req][req] plugin for [Phoenix.Ecto.SQL.Sandbox][plug-sandbox].
ReqSandbox simplifies making concurrent, transactional requests to a
Phoenix server. Just before making a request, the sandbox metadata is
applied via the specified request header. If there is no metadata
available, then ReqSandbox creates a new sandbox session and saves
the metadata for future requests. This is mostly useful in client
test environments to ensure logical isolation between concurrent
tests.## Usage
The [Ecto SQL Sandbox Usage Guide](guides/usage.livemd) contains a full demonstration of the sandbox features.
```elixir
Mix.install([
{:req, "~> 0.4.0"},
{:req_sandbox, "~> 0.2.0"}
])req = Req.new(base_url: "http://localhost:4000" |> ReqSandbox.attach()
Req.post!(req, url: "/api/posts", json: %{"post" => %{"msg" => "Hello, world!"}}).body
#=> %{"data" => %{"id" => 2, "msg" => "Hello, world!"}}ReqSandbox.delete!(req)
#=> "BeamMetadata (g2gCZAACdjF0AAAAA2QABW93bmVyWGQAInZ2ZXMzM2o1LWxpdmVib29...)"
```[req]: https://github.com/wojtekmach/req
[plug-sandbox]: https://github.com/phoenixframework/phoenix_ecto## License
MIT License. Copyright (c) 2022 Michael A. Crumm Jr.