fabrication 2.14.1 → 2.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +1 -1
- data/lib/fabrication/generator/active_record.rb +37 -3
- data/lib/fabrication/generator/base.rb +8 -2
- data/lib/fabrication/generator/data_mapper.rb +0 -4
- data/lib/fabrication/generator/mongoid.rb +0 -4
- data/lib/fabrication/generator/sequel.rb +0 -4
- data/lib/fabrication/schematic/definition.rb +1 -6
- data/lib/fabrication/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ca83ffb9ee5c148c97f69e49b53abea8a7d6824
|
4
|
+
data.tar.gz: 16786e33e23d47aa85002d4b625d42e48464806d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 499cd61316ffe755dae558da80a46e475d46d5b42a2728666eb952c9e691281feb1d2dd6a49882b5430de2ff3ae1d512c68321c108e3d4aa7f3122c919498252
|
7
|
+
data.tar.gz: 5970658104e0ab9e9572c7f68272ba9e8ff9f8167da59ace22e3053b720cba0056cdebc806fb4561594343c2cbaa90bd2da1243ad294ee4bf4ea344b26036b57
|
data/README.markdown
CHANGED
@@ -6,7 +6,7 @@ Fabrication is an object generation framework for Ruby.
|
|
6
6
|
|
7
7
|
## Compatibility
|
8
8
|
|
9
|
-
Fabrication is tested against Ruby 1.9.3
|
9
|
+
Fabrication is tested against Ruby 1.9.3 and above.
|
10
10
|
|
11
11
|
[![Build Status](https://secure.travis-ci.org/paulelliott/fabrication.png)](http://travis-ci.org/paulelliott/fabrication)
|
12
12
|
[![Code Climate](https://codeclimate.com/github/paulelliott/fabrication.png)](https://codeclimate.com/github/paulelliott/fabrication)
|
@@ -12,10 +12,44 @@ class Fabrication::Generator::ActiveRecord < Fabrication::Generator::Base
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
def build_default_expansion(field_name, params)
|
16
|
+
# When an inverse field is found, we can override this in the fabricator so we
|
17
|
+
# don't run into an endless recursion
|
18
|
+
build_args = {}
|
19
|
+
if inverse_of = inverse_of(field_name)
|
20
|
+
inverse_name = inverse_of.name.to_s
|
21
|
+
if belongs_to_or_has_one?(inverse_of)
|
22
|
+
build_args[inverse_name] = nil
|
23
|
+
else
|
24
|
+
build_args[inverse_name] = []
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if params[:count]
|
29
|
+
fabricator_name = params[:fabricator] || Fabrication::Support.singularize(field_name.to_s)
|
30
|
+
proc { Fabricate.build(params[:fabricator] || fabricator_name, build_args) }
|
31
|
+
else
|
32
|
+
fabricator_name = params[:fabricator] || field_name
|
33
|
+
proc { Fabricate(params[:fabricator] || fabricator_name, build_args) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
16
38
|
|
17
|
-
|
18
|
-
|
39
|
+
# Returns the inverse field name of a given relation
|
40
|
+
def inverse_of(name)
|
41
|
+
reflection = _klass.reflections.fetch(name.to_s, nil) || # >= Rails 4.3
|
42
|
+
_klass.reflections.fetch(name.to_sym, nil) # < Rails 4.3
|
43
|
+
reflection.inverse_of if reflection
|
19
44
|
end
|
20
45
|
|
46
|
+
# Returns true if the reflection is a belongs_to or has_one association
|
47
|
+
def belongs_to_or_has_one?(reflection)
|
48
|
+
if reflection.respond_to?(:macro) # < Rails 4.3
|
49
|
+
return true if reflection.macro == :belongs_to || reflection.macro == :has_one
|
50
|
+
else # >= Rails 5.3
|
51
|
+
return true if reflection.instance_of?(ActiveRecord::Reflection::BelongsToReflection) ||
|
52
|
+
reflection.instance_of?(ActiveRecord::Reflection::HasOneReflection)
|
53
|
+
end
|
54
|
+
end
|
21
55
|
end
|
@@ -19,7 +19,6 @@ class Fabrication::Generator::Base
|
|
19
19
|
def create(attributes=[], callbacks=[])
|
20
20
|
build(attributes, callbacks)
|
21
21
|
execute_callbacks(callbacks[:before_validation])
|
22
|
-
validate_instance
|
23
22
|
execute_callbacks(callbacks[:after_validation])
|
24
23
|
execute_callbacks(callbacks[:before_save])
|
25
24
|
execute_callbacks(callbacks[:before_create])
|
@@ -80,7 +79,14 @@ class Fabrication::Generator::Base
|
|
80
79
|
_attributes[method_name] || super
|
81
80
|
end
|
82
81
|
|
83
|
-
def
|
82
|
+
def build_default_expansion(name, params)
|
83
|
+
if params[:count]
|
84
|
+
name = Fabrication::Support.singularize(name.to_s)
|
85
|
+
proc { Fabricate.build(params[:fabricator] || name) }
|
86
|
+
else
|
87
|
+
proc { Fabricate(params[:fabricator] || name) }
|
88
|
+
end
|
89
|
+
end
|
84
90
|
|
85
91
|
protected
|
86
92
|
|
@@ -105,12 +105,7 @@ class Fabrication::Schematic::Definition
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def generate_value(name, params)
|
108
|
-
|
109
|
-
name = Fabrication::Support.singularize(name.to_s)
|
110
|
-
proc { Fabricate.build(params[:fabricator] || name) }
|
111
|
-
else
|
112
|
-
proc { Fabricate(params[:fabricator] || name) }
|
113
|
-
end
|
108
|
+
generator.new(klass).build_default_expansion(name, params)
|
114
109
|
end
|
115
110
|
|
116
111
|
def merge(overrides={}, &block)
|
data/lib/fabrication/version.rb
CHANGED
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.
|
4
|
+
version: 2.15.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:
|
11
|
+
date: 2016-03-13 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.
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.
|
72
|
+
rubygems_version: 2.5.1
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Implementing the factory pattern in Ruby so you don't have to.
|