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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 237688f22ca51d7ead933c80820903a3066a762090aeb9594485547576a566bf
4
- data.tar.gz: 4f6d30d15f061c99071638fb749f123eb7d6c19e9954971efb9b851a5c2f5484
3
+ metadata.gz: 9295f1111fa80d54c0919b4b86286d0e40c08b347e02953600732969b0b884c5
4
+ data.tar.gz: bbe23568cdca871bf0b876c0c5c3e8600ba9336f1cf100ee2ca5c547e533db2b
5
5
  SHA512:
6
- metadata.gz: c8fa700be432eafc10c64f7aa9f566edff0c9e214906330a5a7c9e235a18194ebb5f300941758377ad1a7c930c02896f39f89794aa4e01cbad56a105ed6c8ab4
7
- data.tar.gz: 9e4fa7fc2d540b74b7dfc4b151e9e28b8490b2329981e94b9309cde49f7312589202d6876867cdf9923e190e9e397ae84841210e2f382472a1cfad9b05c55cfd
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
- build_class.present?
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
- klass = build_class
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
- factory.build_class
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
 
@@ -1,3 +1,3 @@
1
1
  module FactoryBurgers
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_burgers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Schwartz