temporary_tables 0.0.3 → 1.0.0.pre.rc.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c43f851f217e3f173721b157cb9d6f08850df57a1c8191fa2774fe5016846fc
4
- data.tar.gz: 48bf725f9b6bde13104111609caec90f8f79362029522c13cedb6d29a0db6e60
3
+ metadata.gz: b076b68e10ebc3f6e5056afcda995811517b45614f9b426bada1858e3a981d4c
4
+ data.tar.gz: cc5d5f520f59c3d7b500fc7b1471b14e5c69d2c3abdb3922ecf722f78ad6674f
5
5
  SHA512:
6
- metadata.gz: beaea096078ff40b70010239fc76c9d70de57738ad863f944defc49c8a875051add1e16e9eb711d9c2ae2649b28ecf34318af7e0c80be7ef8fa3ea49bd1b1966
7
- data.tar.gz: 13f409529c9b291653d83284e8d7a4919e8895496ac76aee5ff78164fffd1a1a4e055ef8a40e5395e68143143bd69526784825b62e687198811958a16a3dc205
6
+ metadata.gz: a6c0305a909d90c0306ddc946a04bd39d94b7622c4e9ac96b6b2b152463a7a4be3c29a8097ea054fa4eba281a8a3c91146fcf485e75d41e78e419045071f1ab8
7
+ data.tar.gz: aca45573a8544c6bfb2467d07e12c6035d7afb76917077b5b67bc3cde4354dd9768422ec7ce6ae2ec3777b8208ca2b912a0187f625fc0a9d7180c443cad8f823
data/README.md CHANGED
@@ -1,31 +1,131 @@
1
- # TemporaryTables
1
+ # temporary_tables
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![CI](https://github.com/keygen-sh/temporary_tables/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/temporary_tables/actions)
4
+ [![Gem Version](https://badge.fury.io/rb/temporary_tables.svg)](https://badge.fury.io/rb/temporary_tables)
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/temporary_tables`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ Use `temporary_tables` to create temporary tables and models in RSpec specs,
7
+ rather than create and maintain a dummy Rails application or messy block-level
8
+ constants.
9
+
10
+ This gem was extracted from [Keygen](https://keygen.sh).
11
+
12
+ Sponsored by:
13
+
14
+ <a href="https://keygen.sh?ref=temporary_tables">
15
+ <div>
16
+ <img src="https://keygen.sh/images/logo-pill.png" width="200" alt="Keygen">
17
+ </div>
18
+ </a>
19
+
20
+ _A fair source software licensing and distribution API._
6
21
 
7
22
  ## Installation
8
23
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
24
+ Add this line to your application's `Gemfile`:
25
+
26
+ ```ruby
27
+ gem 'temporary_tables'
28
+ ```
10
29
 
11
- Install the gem and add to the application's Gemfile by executing:
30
+ And then execute:
12
31
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
32
+ ```bash
33
+ $ bundle
34
+ ```
14
35
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
36
+ Or install it yourself as:
16
37
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
38
+ ```bash
39
+ $ gem install temporary_tables
40
+ ```
18
41
 
19
42
  ## Usage
20
43
 
21
- TODO: Write usage instructions here
44
+ ### `temporary_table`
45
+
46
+ To define a temporary table:
47
+
48
+ ```ruby
49
+ describe Example do
50
+ temporary_table :user do |t|
51
+ t.string :email
52
+ t.string :first_name
53
+ t.string :last_name
54
+ t.index :email, unique: true
55
+ end
56
+
57
+ it 'should define a table' do
58
+ expect(ActiveRecord::Base.connection.table_exists?(:user)).to be true
59
+ end
60
+ end
61
+ ```
62
+
63
+ The full Active Record schema API is available.
64
+
65
+ ### `temporary_model`
66
+
67
+ To define an Active Record:
68
+
69
+ ```ruby
70
+ describe Example do
71
+ temporary_model :user do
72
+ has_many :posts
73
+ end
22
74
 
23
- ## Development
75
+ it 'should define a record' do
76
+ expect(const_defined?(:User)).to be true
77
+ end
78
+ end
79
+ ```
24
80
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+ To define an Active Model:
26
82
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+ ```ruby
84
+ describe Example do
85
+ temporary_model :guest_user, table_name: nil, base_class: nil do
86
+ include ActiveModel::Model
87
+ end
88
+
89
+ it 'should define a model' do
90
+ expect(const_defined?(:GuestUser)).to be true
91
+ end
92
+ end
93
+ ```
94
+
95
+ To define a PORO:
96
+
97
+ ```ruby
98
+ describe Example do
99
+ temporary_model :null_user, table_name: nil, base_class: nil do
100
+ # ...
101
+ end
102
+
103
+ it 'should define a PORO' do
104
+ expect(const_defined?(:NullUser)).to be true
105
+ end
106
+ end
107
+ ```
108
+
109
+ ## Future
110
+
111
+ Right now, the gem only supports RSpec, but we're open to pull requests that
112
+ extend the functionality to other testing frameworks.
113
+
114
+ ## Supported Rubies
115
+
116
+ **`temporary_tables` supports Ruby 3.1 and above.** We encourage you to upgrade
117
+ if you're on an older version. Ruby 3 provides a lot of great features, like
118
+ better pattern matching and a new shorthand hash syntax.
119
+
120
+ ## Is it any good?
121
+
122
+ Yes.
28
123
 
29
124
  ## Contributing
30
125
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/temporary_tables.
126
+ If you have an idea, or have discovered a bug, please open an issue or create a
127
+ pull request.
128
+
129
+ ## License
130
+
131
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TemporaryTables
4
+ module Methods
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def temporary_table(name, ...)
9
+ table_name = name.to_s.pluralize
10
+
11
+ before do
12
+ ActiveRecord::Migration.suppress_messages do
13
+ ActiveRecord::Migration.create_table(table_name, ...)
14
+ end
15
+ end
16
+
17
+ after do
18
+ ActiveRecord::Migration.suppress_messages do
19
+ ActiveRecord::Migration.drop_table(table_name, if_exists: true)
20
+ end
21
+ end
22
+ end
23
+
24
+ def temporary_model(name, table_name: name.to_s.pluralize, base_class: ActiveRecord::Base, &extension)
25
+ class_name = name.to_s.classify
26
+
27
+ before do |example|
28
+ base_class = base_class.to_s.constantize if base_class in String | Symbol
29
+ klass = Class.new *base_class do
30
+ define_singleton_method(:table_name) { table_name.to_s } unless table_name.nil?
31
+ define_singleton_method(:name) { class_name }
32
+ end
33
+
34
+ unless extension.nil?
35
+ # pass in an example context so that vars can be accessed
36
+ context = Class.new do
37
+ define_method(:respond_to_missing?) do |method_name|
38
+ example.instance_exec { respond_to?(method_name) }
39
+ end
40
+
41
+ define_method(:method_missing) do |method_name|
42
+ example.instance_exec { send(method_name) }
43
+ end
44
+ end
45
+
46
+ klass.module_exec(context.new, &extension)
47
+ end
48
+
49
+ stub_const(class_name, klass)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TemporaryTables
4
- VERSION = '0.0.3'
4
+ VERSION = '1.0.0-rc.2'
5
5
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_record'
4
+
5
+ require_relative 'temporary_tables/methods'
3
6
  require_relative 'temporary_tables/version'
4
7
 
5
- module TemporaryTables
6
- end
8
+ module TemporaryTables; end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporary_tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0.pre.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-11 00:00:00.000000000 Z
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec-rails
28
+ name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.4'
41
41
  description: Create temporary tables for Rspec tests.
42
42
  email:
43
43
  - oss@keygen.sh
@@ -51,6 +51,7 @@ files:
51
51
  - README.md
52
52
  - SECURITY.md
53
53
  - lib/temporary_tables.rb
54
+ - lib/temporary_tables/methods.rb
54
55
  - lib/temporary_tables/version.rb
55
56
  homepage: https://github.com/keygen-sh/temporary_tables
56
57
  licenses:
@@ -67,9 +68,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
68
  version: '3.1'
68
69
  required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  requirements:
70
- - - ">="
71
+ - - ">"
71
72
  - !ruby/object:Gem::Version
72
- version: '0'
73
+ version: 1.3.1
73
74
  requirements: []
74
75
  rubygems_version: 3.4.13
75
76
  signing_key: