factory_burgers 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/factory_burgers/models/factory.rb +13 -9
- data/lib/factory_burgers/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: 9295f1111fa80d54c0919b4b86286d0e40c08b347e02953600732969b0b884c5
|
4
|
+
data.tar.gz: bbe23568cdca871bf0b876c0c5c3e8600ba9336f1cf100ee2ca5c547e533db2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c38e40099ee535b7c342dc4a57920ed978db06b5d5aa43958d81d170ecd8aa6c080ea57b9039ad3282c1bdb0ebf0d4a868cada2283ea0ae692e3d7c3d4b99960
|
7
|
+
data.tar.gz: 6f01930967401fd63066ea8fff9283fc951d8901fad8649e46983d0f9b7191c6a98b2466fa9916f53be9744683c4d1d3fa7c56dbbeb0e89c4c0dd4d3b8277bef
|
@@ -13,7 +13,8 @@ module FactoryBurgers
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def valid?
|
16
|
-
|
16
|
+
# Non-ActiveRecord factories are not supported; we don't know how to set their columns, persist records, etc.
|
17
|
+
active_record?
|
17
18
|
end
|
18
19
|
|
19
20
|
def to_h
|
@@ -34,12 +35,7 @@ module FactoryBurgers
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def class_name
|
37
|
-
|
38
|
-
if klass.is_a? ActiveRecord::Inheritance::ClassMethods
|
39
|
-
klass.base_class.name
|
40
|
-
else
|
41
|
-
klass.name
|
42
|
-
end
|
38
|
+
active_record? ? build_class.base_class.name : build_class.name
|
43
39
|
end
|
44
40
|
|
45
41
|
def traits
|
@@ -53,13 +49,21 @@ module FactoryBurgers
|
|
53
49
|
private
|
54
50
|
|
55
51
|
def build_class
|
56
|
-
|
52
|
+
return @build_class if defined?(@build_class)
|
53
|
+
|
54
|
+
@build_class = factory.build_class
|
57
55
|
rescue NameError
|
58
56
|
# Some usages of factories include pseudo "abstract" factory parent classes that do not point to a real class
|
59
|
-
nil
|
57
|
+
@build_class = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def active_record?
|
61
|
+
build_class.present? && build_class < ActiveRecord::Base
|
60
62
|
end
|
61
63
|
|
62
64
|
def settable_columns
|
65
|
+
return [] if !active_record?
|
66
|
+
|
63
67
|
factory.build_class.columns.reject { |col| col.name == build_class.primary_key }
|
64
68
|
end
|
65
69
|
|