Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keygen-sh/temporary_tables
Create temporary tables and models in RSpec tests.
https://github.com/keygen-sh/temporary_tables
Last synced: about 1 month ago
JSON representation
Create temporary tables and models in RSpec tests.
- Host: GitHub
- URL: https://github.com/keygen-sh/temporary_tables
- Owner: keygen-sh
- License: mit
- Created: 2024-04-03T03:02:14.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-08-15T17:43:20.000Z (about 1 month ago)
- Last Synced: 2024-08-15T19:54:44.255Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 14.6 KB
- Stars: 19
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# temporary_tables
[![CI](https://github.com/keygen-sh/temporary_tables/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/temporary_tables/actions)
[![Gem Version](https://badge.fury.io/rb/temporary_tables.svg)](https://badge.fury.io/rb/temporary_tables)Use `temporary_tables` to create temporary tables and models in RSpec specs,
rather than create and maintain a dummy Rails application or messy block-level
constants.This gem was extracted from [Keygen](https://keygen.sh).
Sponsored by:
_A fair source software licensing and distribution API._
## Installation
Add this line to your application's `Gemfile`:
```ruby
gem 'temporary_tables'
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install temporary_tables
```## Usage
### `temporary_table`
To define a temporary table:
```ruby
describe Example do
temporary_table :users do |t|
t.string :email
t.string :first_name
t.string :last_name
t.index :email, unique: true
endit 'should define a table' do
expect(ActiveRecord::Base.connection.table_exists?(:users)).to be true
end
end
```The full Active Record schema API is available.
### `temporary_model`
To define an Active Record:
```ruby
describe Example do
temporary_model :user do
has_many :posts
endit 'should define a record' do
expect(const_defined?(:User)).to be true
end
end
```To define an Active Model:
```ruby
describe Example do
temporary_model :guest_user, table_name: nil, base_class: nil do
include ActiveModel::Model
endit 'should define a model' do
expect(const_defined?(:GuestUser)).to be true
end
end
```To define a PORO:
```ruby
describe Example do
temporary_model :null_user, table_name: nil, base_class: nil do
# ...
endit 'should define a PORO' do
expect(const_defined?(:NullUser)).to be true
end
end
```## Future
Right now, the gem only supports RSpec, but we're open to pull requests that
extend the functionality to other testing frameworks.## Supported Rubies
**`temporary_tables` supports Ruby 3.1 and above.** We encourage you to upgrade
if you're on an older version. Ruby 3 provides a lot of great features, like
better pattern matching and a new shorthand hash syntax.## Is it any good?
Yes.
## Contributing
If you have an idea, or have discovered a bug, please open an issue or create a
pull request.## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).