temporary_model 0.1.0 → 0.2.0

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: a1dd9e5df7a2d28a160b195643174d4a196ca06e0e60c8da2d3888033e27249a
4
- data.tar.gz: b1d709cc0f71716ee2e139de14f4e4c3d91222b905b83c15b7e11c2470998a2b
3
+ metadata.gz: 630b4c206db73a2140031839721833e1d06205772c4a162293d40aa48171dc75
4
+ data.tar.gz: 72b4939a7e14aaf4872d2cb00a6a529f20bdbd9a4238c532ad404fe0ba2bf667
5
5
  SHA512:
6
- metadata.gz: 42d762e3ff3585c3b5860af4db223b0c94c45054666915bc759c4c933838377922b7cd9d462daeab17125c692dc15ae0970e84a7df95c58ad8b82985531b4cd1
7
- data.tar.gz: 0b66e0d9587d61941fa82a496328820b43324a52b5287560b1d2e01d342f31aab3e16570798878bab18a77cbaf8161e0f2c561a05bd16e380bb04099b3cb787b
6
+ metadata.gz: 6fb34bee99a0323b765506ea04382ecf6b8aaaae64c32c8dd141e973b6f8b5705f956d40ece9d756479f66e159cccb1662e4fba8a492badd692fc20d072907ce
7
+ data.tar.gz: fd3790a3958adb022e85f347218e83b28f8187bc5039855d9c6c2e1bf25a74d0008ad13283e99d139264545682f7ad11a48e10cdeefbc36afd46f2955e9c925a
@@ -3,28 +3,29 @@ module TemporaryModel::TestHelper
3
3
 
4
4
  included do
5
5
  def self.temporary_classes
6
- @temporary_classes ||= []
6
+ @temporary_classes ||= {}
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
- klass = Class.new(TemporaryModel::Record, &block)
12
- Object.const_set(model_name, klass)
13
- temporary_classes.push(klass)
11
+ temporary_classes[model_name] = Class.new(TemporaryModel::Record, &block)
14
12
  end
15
13
  end
16
14
 
17
15
  # Override ActiveSupport::TestCase#run
16
+ # FIXME: こんなにループさせんでもできるんじゃないか?
17
+ # FIXME: テストごとに設定じゃなくてテストクラス全体でできないかな
18
18
  def run
19
- self.class.temporary_classes.each do |temporary_class|
19
+ self.class.temporary_classes.each do |model_name, temporary_class|
20
+ Object.const_set(model_name, temporary_class)
20
21
  create_temporary_table temporary_class.table_name, &temporary_class.define_table
21
22
  end
22
23
  super
23
24
  ensure
24
25
  TemporaryModel::Record.connection.disable_referential_integrity do
25
- self.class.temporary_classes.each do |temporary_class|
26
+ self.class.temporary_classes.each do |model_name, temporary_class|
26
27
  drop_temporary_table temporary_class.table_name
27
- Object.send(:remove_const, temporary_class.name)
28
+ Object.send(:remove_const, model_name)
28
29
  end
29
30
  end
30
31
  end
@@ -1,3 +1,3 @@
1
1
  module TemporaryModel
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporary_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichi Takeuchi