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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 630b4c206db73a2140031839721833e1d06205772c4a162293d40aa48171dc75
4
- data.tar.gz: 72b4939a7e14aaf4872d2cb00a6a529f20bdbd9a4238c532ad404fe0ba2bf667
3
+ metadata.gz: bd5e8e30e23e453616fbc089d73a7b28486e4db679ed908a364dcd6d71e492e6
4
+ data.tar.gz: b89c1526fe89934da2ddcface1dd3f77be17ea6ff929d3943f2ac6dd595ee030
5
5
  SHA512:
6
- metadata.gz: 6fb34bee99a0323b765506ea04382ecf6b8aaaae64c32c8dd141e973b6f8b5705f956d40ece9d756479f66e159cccb1662e4fba8a492badd692fc20d072907ce
7
- data.tar.gz: fd3790a3958adb022e85f347218e83b28f8187bc5039855d9c6c2e1bf25a74d0008ad13283e99d139264545682f7ad11a48e10cdeefbc36afd46f2955e9c925a
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.temporary_classes
6
- @temporary_classes ||= {}
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
- temporary_classes[model_name] = Class.new(TemporaryModel::Record, &block)
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.temporary_classes.each do |model_name, temporary_class|
20
- Object.const_set(model_name, temporary_class)
21
- create_temporary_table temporary_class.table_name, &temporary_class.define_table
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
- self.class.temporary_classes.each do |model_name, temporary_class|
32
+ temporary_classes.each do |temporary_class|
27
33
  drop_temporary_table temporary_class.table_name
28
- Object.send(:remove_const, model_name)
34
+ Object.send(:remove_const, temporary_class.name)
29
35
  end
30
36
  end
31
37
  end
@@ -1,3 +1,3 @@
1
1
  module TemporaryModel
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  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.0
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-03-09 00:00:00.000000000 Z
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.3
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.