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 +4 -4
- data/lib/temporary_model/test_helper.rb +8 -7
- data/lib/temporary_model/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 630b4c206db73a2140031839721833e1d06205772c4a162293d40aa48171dc75
|
4
|
+
data.tar.gz: 72b4939a7e14aaf4872d2cb00a6a529f20bdbd9a4238c532ad404fe0ba2bf667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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,
|
28
|
+
Object.send(:remove_const, model_name)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|