temporary_model 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/temporary_model/test_helper.rb +14 -8
- data/lib/temporary_model/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd5e8e30e23e453616fbc089d73a7b28486e4db679ed908a364dcd6d71e492e6
|
4
|
+
data.tar.gz: b89c1526fe89934da2ddcface1dd3f77be17ea6ff929d3943f2ac6dd595ee030
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 395cc8a44d0a92c42398605c91bc6af03af03361250cf84315bd0d5d04149361b991757640ede015d110d6a5b2566731db0fc9062e13404f9b193d2219ec642a
|
7
|
+
data.tar.gz: d0022a76803e7d469b377fd7e4de8c23142866dd6bed51fc8fdb354fc12e06176571a60e6e5c4b3e3f97b0d15a131a315bacbb5556c8812996e7a60709d299dd
|
@@ -2,13 +2,13 @@ module TemporaryModel::TestHelper
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
def self.
|
6
|
-
@
|
5
|
+
def self.class_definitions
|
6
|
+
@class_definitions ||= {}
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.temporary_model(model_name, &block)
|
10
10
|
raise(ArgumentError, "#{model_name} has already been defined") if Object.const_defined?(model_name)
|
11
|
-
|
11
|
+
class_definitions[model_name] = block
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,16 +16,22 @@ module TemporaryModel::TestHelper
|
|
16
16
|
# FIXME: こんなにループさせんでもできるんじゃないか?
|
17
17
|
# FIXME: テストごとに設定じゃなくてテストクラス全体でできないかな
|
18
18
|
def run
|
19
|
-
self.class.
|
20
|
-
|
21
|
-
|
19
|
+
temporary_classes = self.class.class_definitions.map do |model_name, class_definition|
|
20
|
+
Class.new(TemporaryModel::Record).tap do |temporary_class|
|
21
|
+
# 先に定数に設定しておかないと
|
22
|
+
# https://circleci.com/gh/takeyuwebinc/takeyuweb-rails/83
|
23
|
+
Object.const_set(model_name, temporary_class)
|
24
|
+
temporary_class.class_eval(&class_definition)
|
25
|
+
|
26
|
+
create_temporary_table temporary_class.table_name, &temporary_class.define_table
|
27
|
+
end
|
22
28
|
end
|
23
29
|
super
|
24
30
|
ensure
|
25
31
|
TemporaryModel::Record.connection.disable_referential_integrity do
|
26
|
-
|
32
|
+
temporary_classes.each do |temporary_class|
|
27
33
|
drop_temporary_table temporary_class.table_name
|
28
|
-
Object.send(:remove_const,
|
34
|
+
Object.send(:remove_const, temporary_class.name)
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: temporary_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichi Takeuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.7.
|
76
|
+
rubygems_version: 2.7.6
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: You can define a temporary class and use it in ActiveSupport::TestCase.
|