Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lcmen/testy_cookie
TestyCookie provides a helper to access plain, permanent, signed and encrypted cookies in Rails controller / integration / request tests.
https://github.com/lcmen/testy_cookie
minitest rails rspec
Last synced: 26 days ago
JSON representation
TestyCookie provides a helper to access plain, permanent, signed and encrypted cookies in Rails controller / integration / request tests.
- Host: GitHub
- URL: https://github.com/lcmen/testy_cookie
- Owner: lcmen
- License: mit
- Created: 2024-02-22T18:38:24.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-06-05T02:03:13.000Z (5 months ago)
- Last Synced: 2024-09-30T03:41:05.874Z (about 1 month ago)
- Topics: minitest, rails, rspec
- Language: Ruby
- Homepage: https://rubygems.org/gems/testy_cookie
- Size: 58.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# TestyCookie
`TestyCookie` gem provides a helper for accessing plain, permanent, signed, and encrypted cookies in Rails controller, integration, and request tests.
## Why do I need a custom helper?
In Rails, `ActionDispatch::IntegrationTest` based tests and RSpec request specs do not provide `encrypted`, `permanent` and `signed` stores when the default `cookies` helper is used (it returns `Rack::Test::CookieJar` instance). `TestyCookie` resolves this limitation by initializing a proper `ActionDispatch::Cookies::CookieJar` instance which support these stores. The included helper also propagates any changes back to the original `Rack::Test::CookieJar` instance making them correctly read in application controllers.
In `ActionController::TestCase` tests and RSpec controller specs, `cookie_jar` serves as an alias for the default `cookies` method which returns `ActionDispatch::Cookies::CookieJar` instance correctly.
## Usage
Inside your controller / integration / request test, call `cookie_jar` helper to access cookies:
```ruby
cookie_jar.encrypted[:key]
cookie_jar.signed[:key] = value
cookie_jar.signed.encrypted.permanent[:key] = value
```## Installation
Add this line to your application's Gemfile:
```ruby
gem "testy_cookie"
```And then execute:
```bash
$ bundle
```## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).