temporary_model 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +27 -0
- data/lib/tasks/temporary_model_tasks.rake +4 -0
- data/lib/temporary_model/record.rb +11 -0
- data/lib/temporary_model/test_helper.rb +46 -0
- data/lib/temporary_model/version.rb +3 -0
- data/lib/temporary_model.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a1dd9e5df7a2d28a160b195643174d4a196ca06e0e60c8da2d3888033e27249a
|
4
|
+
data.tar.gz: b1d709cc0f71716ee2e139de14f4e4c3d91222b905b83c15b7e11c2470998a2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42d762e3ff3585c3b5860af4db223b0c94c45054666915bc759c4c933838377922b7cd9d462daeab17125c692dc15ae0970e84a7df95c58ad8b82985531b4cd1
|
7
|
+
data.tar.gz: 0b66e0d9587d61941fa82a496328820b43324a52b5287560b1d2e01d342f31aab3e16570798878bab18a77cbaf8161e0f2c561a05bd16e380bb04099b3cb787b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Yuichi Takeuchi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# TemporaryModel
|
2
|
+
You can define a temporary class and use it in ActiveSupport::TestCase.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
class YourTest < ActiveSupport::TestCase
|
8
|
+
include TemporaryModel::TestHelper # 1 of 2
|
9
|
+
|
10
|
+
# 2 of 2
|
11
|
+
temporary_model 'Post' do
|
12
|
+
define_table do |t|
|
13
|
+
t.string :title, default: '', null: false
|
14
|
+
end
|
15
|
+
|
16
|
+
has_many :taggings, as: :taggable, dependent: :destroy
|
17
|
+
has_many :tags, through: :taggings, source: :tag
|
18
|
+
|
19
|
+
validates :title, presence: true
|
20
|
+
|
21
|
+
# You can use custom validators
|
22
|
+
validates_with YourCustomValidator
|
23
|
+
|
24
|
+
# You can use Active Storage
|
25
|
+
has_one_attached :doc
|
26
|
+
has_many_attached :docs
|
27
|
+
|
28
|
+
def tag_names
|
29
|
+
tags.pluck(:name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'truthy' do
|
34
|
+
post = Post.create!(title: 'Hello')
|
35
|
+
assert 'Hello', post.title
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Please check test/*test.rb
|
41
|
+
|
42
|
+
## Installation
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'temporary_model'
|
47
|
+
```
|
48
|
+
|
49
|
+
And then execute:
|
50
|
+
```bash
|
51
|
+
$ bundle
|
52
|
+
```
|
53
|
+
|
54
|
+
Or install it yourself as:
|
55
|
+
```bash
|
56
|
+
$ gem install temporary_model
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
Contribution directions go here.
|
61
|
+
|
62
|
+
## License
|
63
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'TemporaryModel'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module TemporaryModel::TestHelper
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
def self.temporary_classes
|
6
|
+
@temporary_classes ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.temporary_model(model_name, &block)
|
10
|
+
raise(ArgumentError, "#{model_name} has already been defined") if Object.const_defined?(model_name)
|
11
|
+
klass = Class.new(TemporaryModel::Record, &block)
|
12
|
+
Object.const_set(model_name, klass)
|
13
|
+
temporary_classes.push(klass)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Override ActiveSupport::TestCase#run
|
18
|
+
def run
|
19
|
+
self.class.temporary_classes.each do |temporary_class|
|
20
|
+
create_temporary_table temporary_class.table_name, &temporary_class.define_table
|
21
|
+
end
|
22
|
+
super
|
23
|
+
ensure
|
24
|
+
TemporaryModel::Record.connection.disable_referential_integrity do
|
25
|
+
self.class.temporary_classes.each do |temporary_class|
|
26
|
+
drop_temporary_table temporary_class.table_name
|
27
|
+
Object.send(:remove_const, temporary_class.name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def create_temporary_table(table_name, &block)
|
35
|
+
migration = ActiveRecord::Migration::Current.new
|
36
|
+
migration.verbose = false
|
37
|
+
migration.create_table(table_name, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def drop_temporary_table(table_name)
|
41
|
+
migration = ActiveRecord::Migration::Current.new
|
42
|
+
migration.verbose = false
|
43
|
+
migration.drop_table(table_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: temporary_model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuichi Takeuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: You can define a temporary class and use it in ActiveSupport::TestCase.
|
42
|
+
email:
|
43
|
+
- yuichi.takeuchi@takeyuweb.co.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/tasks/temporary_model_tasks.rake
|
52
|
+
- lib/temporary_model.rb
|
53
|
+
- lib/temporary_model/record.rb
|
54
|
+
- lib/temporary_model/test_helper.rb
|
55
|
+
- lib/temporary_model/version.rb
|
56
|
+
homepage: https://github.com/takeyuweb/temporary_model
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.7.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: You can define a temporary class and use it in ActiveSupport::TestCase.
|
80
|
+
test_files: []
|