fabrication 2.17.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f77d2a10a03e1420c0e2e5ec08f156c990a088d8
4
- data.tar.gz: 75d2e8a00f8cc4916c6a8837f518e6de90e9daf0
3
+ metadata.gz: b16cf8ca405caaf21ab076cd40a2ea7d8c2be30a
4
+ data.tar.gz: b785f882534a6d5139ca43bca6c8240dcd43efdb
5
5
  SHA512:
6
- metadata.gz: 25cfb81ca168bab05a52c1921738dc6243f59b2a95da01f699058bd734ff10c21b893ec3a018ebee6f1b033dcd2ee7d2601dffd3700b2975998554c5c32f6a62
7
- data.tar.gz: 5992742810af94e0f92496fdbc666479aacbf96ff308e0bc009a2dac68171af9662f63e080f49cddae6686b48bb87a415a501b1fdbc713da72cd3a44b36448f0
6
+ metadata.gz: edb17b2fe50e6b6076b921576039e25e8aee00ffcce70f0ffdde721912617d5e26db164cd8bb1d291adc578dd1a420fbc4e7304586a46ec8695803eec908b657
7
+ data.tar.gz: 984e757e5f90514b95cab7d32ad776d0a9b04a0550773e28b74732059d27ff39ae71d3feb3b379183f61a4b90629b970c159fce75fb15eb1d106fb6af3cc3adf
@@ -12,6 +12,7 @@ module Fabrication
12
12
  autoload :UnfabricatableError, 'fabrication/errors/unfabricatable_error'
13
13
  autoload :UnknownFabricatorError, 'fabrication/errors/unknown_fabricator_error'
14
14
  autoload :MisplacedFabricateError, 'fabrication/errors/misplaced_fabricate_error'
15
+ autoload :InfiniteRecursionError, 'fabrication/errors/infinite_recursion_error'
15
16
 
16
17
  module Schematic
17
18
  autoload :Attribute, 'fabrication/schematic/attribute'
@@ -53,5 +53,8 @@ module Fabrication
53
53
  def generator_for(default_generators, klass)
54
54
  (generators + default_generators).detect { |gen| gen.supports?(klass) }
55
55
  end
56
+
57
+ def recursion_limit; @recursion_limit ||= 20 end
58
+ def recursion_limit=(limit); @recursion_limit = limit end
56
59
  end
57
60
  end
@@ -0,0 +1,5 @@
1
+ class Fabrication::InfiniteRecursionError < StandardError
2
+ def initialize(name)
3
+ super("You appear to have infinite recursion with the `#{name}` fabricator")
4
+ end
5
+ end
@@ -54,11 +54,12 @@ class Fabrication::Schematic::Definition
54
54
  end
55
55
 
56
56
  def build(overrides={}, &block)
57
+ Fabrication.manager.prevent_recursion!
57
58
  if Fabrication.manager.to_params_stack.any?
58
59
  to_params(overrides, &block)
59
60
  else
60
61
  begin
61
- Fabrication.manager.build_stack << self
62
+ Fabrication.manager.build_stack << name
62
63
  merge(overrides, &block).instance_eval do
63
64
  generator.new(klass).build(sorted_attributes, callbacks)
64
65
  end
@@ -69,19 +70,26 @@ class Fabrication::Schematic::Definition
69
70
  end
70
71
 
71
72
  def fabricate(overrides={}, &block)
73
+ Fabrication.manager.prevent_recursion!
72
74
  if Fabrication.manager.build_stack.any?
73
75
  build(overrides, &block)
74
76
  elsif Fabrication.manager.to_params_stack.any?
75
77
  to_params(overrides, &block)
76
78
  else
77
- merge(overrides, &block).instance_eval do
78
- generator.new(klass).create(sorted_attributes, callbacks)
79
+ begin
80
+ Fabrication.manager.create_stack << name
81
+ merge(overrides, &block).instance_eval do
82
+ generator.new(klass).create(sorted_attributes, callbacks)
83
+ end
84
+ ensure
85
+ Fabrication.manager.create_stack.pop
79
86
  end
80
87
  end
81
88
  end
82
89
 
83
90
  def to_params(overrides={}, &block)
84
- Fabrication.manager.to_params_stack << self
91
+ Fabrication.manager.prevent_recursion!
92
+ Fabrication.manager.to_params_stack << name
85
93
  merge(overrides, &block).instance_eval do
86
94
  generator.new(klass).to_params(sorted_attributes)
87
95
  end
@@ -33,6 +33,10 @@ class Fabrication::Schematic::Manager
33
33
  schematics[name.to_sym]
34
34
  end
35
35
 
36
+ def create_stack
37
+ @create_stack ||= []
38
+ end
39
+
36
40
  def build_stack
37
41
  @build_stack ||= []
38
42
  end
@@ -56,6 +60,12 @@ class Fabrication::Schematic::Manager
56
60
  freeze
57
61
  end
58
62
 
63
+ def prevent_recursion!
64
+ (create_stack + build_stack + to_params_stack).group_by(&:to_sym).each do |name, values|
65
+ raise Fabrication::InfiniteRecursionError.new(name) if values.length > Fabrication::Config.recursion_limit
66
+ end
67
+ end
68
+
59
69
  protected
60
70
 
61
71
  def raise_if_registered(name)
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.17.0'
2
+ VERSION = '2.18.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrication
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.0
4
+ version: 2.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Elliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-07 00:00:00.000000000 Z
11
+ date: 2017-10-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fabrication is an object generation framework for ActiveRecord, Mongoid,
14
14
  DataMapper, Sequel, or any other Ruby object.
@@ -26,6 +26,7 @@ files:
26
26
  - lib/fabrication/config.rb
27
27
  - lib/fabrication/cucumber/step_fabricator.rb
28
28
  - lib/fabrication/errors/duplicate_fabricator_error.rb
29
+ - lib/fabrication/errors/infinite_recursion_error.rb
29
30
  - lib/fabrication/errors/misplaced_fabricate_error.rb
30
31
  - lib/fabrication/errors/unfabricatable_error.rb
31
32
  - lib/fabrication/errors/unknown_fabricator_error.rb
@@ -62,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
63
  requirements:
63
64
  - - ">="
64
65
  - !ruby/object:Gem::Version
65
- version: 1.9.3
66
+ version: 2.2.0
66
67
  required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  requirements:
68
69
  - - ">="