fabrication 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fabrication.rb +11 -27
- data/lib/fabrication/config.rb +20 -5
- data/lib/fabrication/cucumber/step_fabricator.rb +3 -1
- data/lib/fabrication/fabricator.rb +18 -4
- data/lib/fabrication/generator/active_record.rb +2 -6
- data/lib/fabrication/generator/base.rb +65 -46
- data/lib/fabrication/generator/data_mapper.rb +8 -6
- data/lib/fabrication/generator/mongoid.rb +4 -14
- data/lib/fabrication/generator/sequel.rb +6 -2
- data/lib/fabrication/schematic/attribute.rb +14 -2
- data/lib/fabrication/schematic/definition.rb +42 -38
- data/lib/fabrication/schematic/manager.rb +15 -0
- data/lib/fabrication/support.rb +2 -2
- data/lib/fabrication/version.rb +1 -1
- data/lib/rails/generators/fabrication/cucumber_steps/templates/fabrication_steps.rb +6 -1
- data/lib/rails/generators/fabrication/model/templates/fabricator.rb +1 -1
- metadata +33 -33
data/lib/fabrication.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Fabrication
|
2
|
-
|
3
2
|
autoload :DuplicateFabricatorError, 'fabrication/errors/duplicate_fabricator_error'
|
4
3
|
autoload :UnfabricatableError, 'fabrication/errors/unfabricatable_error'
|
5
4
|
autoload :UnknownFabricatorError, 'fabrication/errors/unknown_fabricator_error'
|
@@ -17,9 +16,7 @@ module Fabrication
|
|
17
16
|
autoload :Support, 'fabrication/support'
|
18
17
|
autoload :Transform, 'fabrication/transform'
|
19
18
|
|
20
|
-
|
21
|
-
autoload :StepFabricator, 'fabrication/cucumber/step_fabricator'
|
22
|
-
end
|
19
|
+
autoload :Cucumber, 'fabrication/cucumber/step_fabricator'
|
23
20
|
|
24
21
|
module Generator
|
25
22
|
autoload :ActiveRecord, 'fabrication/generator/active_record'
|
@@ -38,18 +35,9 @@ module Fabrication
|
|
38
35
|
Fabrication::Config.configure(&block)
|
39
36
|
end
|
40
37
|
|
41
|
-
def self.initializing=(value)
|
42
|
-
@initializing = value
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.initializing?
|
46
|
-
@initializing
|
47
|
-
end
|
48
|
-
|
49
38
|
def self.schematics
|
50
39
|
@schematics ||= Fabrication::Schematic::Manager.new
|
51
40
|
end
|
52
|
-
|
53
41
|
end
|
54
42
|
|
55
43
|
def Fabricator(name, options={}, &block)
|
@@ -57,30 +45,26 @@ def Fabricator(name, options={}, &block)
|
|
57
45
|
end
|
58
46
|
|
59
47
|
def Fabricate(name, overrides={}, &block)
|
60
|
-
raise Fabrication::MisplacedFabricateError.new(name) if Fabrication.initializing?
|
61
|
-
Fabrication::Fabricator.
|
62
|
-
|
63
|
-
|
48
|
+
raise Fabrication::MisplacedFabricateError.new(name) if Fabrication.schematics.initializing?
|
49
|
+
Fabrication::Fabricator.fabricate(name, overrides, &block).tap do |object|
|
50
|
+
Fabrication::Cucumber::Fabrications[name] = object if Fabrication::Config.register_with_steps?
|
51
|
+
end
|
64
52
|
end
|
65
53
|
|
66
54
|
class Fabricate
|
67
|
-
|
68
|
-
|
69
|
-
Fabrication::Fabricator.generate(name, {
|
70
|
-
:save => false, :attributes => true
|
71
|
-
}, options, &block)
|
55
|
+
def self.attributes_for(name, overrides={}, &block)
|
56
|
+
Fabrication::Fabricator.to_attributes(name, overrides, &block)
|
72
57
|
end
|
73
58
|
|
74
|
-
def self.build(name,
|
75
|
-
Fabrication::Fabricator.
|
76
|
-
|
77
|
-
|
59
|
+
def self.build(name, overrides={}, &block)
|
60
|
+
Fabrication::Fabricator.build(name, overrides, &block).tap do |object|
|
61
|
+
Fabrication::Cucumber::Fabrications[name] = object if Fabrication::Config.register_with_steps?
|
62
|
+
end
|
78
63
|
end
|
79
64
|
|
80
65
|
def self.sequence(name=Fabrication::Sequencer::DEFAULT, start=0, &block)
|
81
66
|
Fabrication::Sequencer.sequence(name, start, &block)
|
82
67
|
end
|
83
|
-
|
84
68
|
end
|
85
69
|
|
86
70
|
module FabricationMethods
|
data/lib/fabrication/config.rb
CHANGED
@@ -6,23 +6,38 @@ module Fabrication
|
|
6
6
|
yield self
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
OPTIONS[:
|
9
|
+
def fabricator_path
|
10
|
+
OPTIONS[:fabricator_path]
|
11
11
|
end
|
12
|
+
alias fabricator_dir fabricator_path
|
12
13
|
|
13
|
-
def
|
14
|
-
OPTIONS[:
|
14
|
+
def fabricator_path=(folders)
|
15
|
+
OPTIONS[:fabricator_path] = (Array.new << folders).flatten
|
15
16
|
end
|
17
|
+
alias fabricator_dir= fabricator_path=
|
16
18
|
|
17
19
|
def reset_defaults
|
18
20
|
OPTIONS.clear
|
19
21
|
OPTIONS.merge!(DEFAULTS)
|
20
22
|
end
|
21
23
|
|
24
|
+
def active_support?
|
25
|
+
@active_support ||= defined?(ActiveSupport)
|
26
|
+
end
|
27
|
+
|
28
|
+
def register_with_steps?
|
29
|
+
OPTIONS[:register_with_steps]
|
30
|
+
end
|
31
|
+
|
32
|
+
def register_with_steps=(register)
|
33
|
+
OPTIONS[:register_with_steps] = register
|
34
|
+
end
|
35
|
+
|
22
36
|
private
|
23
37
|
|
24
38
|
DEFAULTS = {
|
25
|
-
:
|
39
|
+
fabricator_path: ['test/fabricators', 'spec/fabricators'],
|
40
|
+
register_with_steps: false
|
26
41
|
}
|
27
42
|
OPTIONS = {}.merge!(DEFAULTS)
|
28
43
|
end
|
@@ -54,7 +54,9 @@ module Fabrication
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def schematic
|
57
|
-
Fabrication.schematics[@fabricator]
|
57
|
+
Fabrication.schematics[@fabricator].tap do |schematic|
|
58
|
+
raise Fabrication::UnknownFabricatorError, "No Fabricator defined for '#{@model}'" unless schematic
|
59
|
+
end
|
58
60
|
end
|
59
61
|
|
60
62
|
def dehumanize(string)
|
@@ -1,10 +1,24 @@
|
|
1
1
|
class Fabrication::Fabricator
|
2
2
|
|
3
|
-
def self.
|
3
|
+
def self.build(name, overrides={}, &block)
|
4
|
+
schematic(name).build(overrides, &block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.fabricate(name, overrides={}, &block)
|
8
|
+
schematic(name).fabricate(overrides, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.to_attributes(name, overrides={}, &block)
|
12
|
+
schematic(name).to_attributes(overrides, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.schematic(name)
|
4
18
|
Fabrication::Support.find_definitions if Fabrication.schematics.empty?
|
5
|
-
|
6
|
-
|
7
|
-
|
19
|
+
Fabrication.schematics[name].tap do |schematic|
|
20
|
+
raise Fabrication::UnknownFabricatorError, "No Fabricator defined for '#{name}'" unless schematic
|
21
|
+
end
|
8
22
|
end
|
9
23
|
|
10
24
|
end
|
@@ -4,12 +4,8 @@ class Fabrication::Generator::ActiveRecord < Fabrication::Generator::Base
|
|
4
4
|
defined?(ActiveRecord) && klass.ancestors.include?(ActiveRecord::Base)
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def association?(method_name)
|
12
|
-
associations.include?(method_name.to_sym)
|
7
|
+
def build_instance
|
8
|
+
self.__instance = __klass.new(__attributes)
|
13
9
|
end
|
14
10
|
|
15
11
|
end
|
@@ -2,59 +2,61 @@ class Fabrication::Generator::Base
|
|
2
2
|
|
3
3
|
def self.supports?(__klass); true end
|
4
4
|
|
5
|
-
def
|
5
|
+
def build(attributes=[], callbacks={})
|
6
|
+
process_attributes(attributes)
|
7
|
+
|
6
8
|
if callbacks[:on_init]
|
7
|
-
|
9
|
+
build_instance_with_init_callback(callbacks[:on_init])
|
8
10
|
else
|
9
|
-
|
11
|
+
build_instance
|
10
12
|
end
|
11
13
|
|
12
|
-
process_attributes(attributes)
|
13
|
-
|
14
14
|
callbacks[:after_build].each { |callback| callback.call(__instance) } if callbacks[:after_build]
|
15
|
-
after_generation(options)
|
16
|
-
callbacks[:after_create].each { |callback| callback.call(__instance) } if callbacks[:after_create] && options[:save]
|
17
15
|
|
18
16
|
__instance
|
19
17
|
end
|
20
18
|
|
19
|
+
def create(attributes=[], callbacks=[])
|
20
|
+
build(attributes, callbacks)
|
21
|
+
persist
|
22
|
+
callbacks[:after_create].each { |callback| callback.call(__instance) } if callbacks[:after_create]
|
23
|
+
__instance
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash(attributes=[], callbacks=[])
|
27
|
+
process_attributes(attributes)
|
28
|
+
(Fabrication::Config.active_support? ? HashWithIndifferentAccess.new : {}).tap do |hash|
|
29
|
+
__attributes.map do |name, value|
|
30
|
+
if value && value.respond_to?(:id)
|
31
|
+
hash["#{name}_id"] = value.id
|
32
|
+
else
|
33
|
+
hash[name] = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_instance_with_init_callback(callback)
|
40
|
+
self.__instance = __klass.new(*callback.call)
|
41
|
+
__attributes.each do |k,v|
|
42
|
+
__instance.send("#{k}=", v)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_instance
|
47
|
+
self.__instance = __klass.new
|
48
|
+
__attributes.each do |k,v|
|
49
|
+
__instance.send("#{k}=", v)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
21
53
|
def initialize(klass)
|
22
54
|
self.__klass = klass
|
23
55
|
end
|
24
56
|
|
25
|
-
def association?(method_name); false end
|
26
|
-
|
27
57
|
def method_missing(method_name, *args, &block)
|
28
58
|
if block_given?
|
29
|
-
|
30
|
-
if !options[:force] && association?(method_name)
|
31
|
-
method_name = method_name.to_s
|
32
|
-
count = options[:count] || 0
|
33
|
-
|
34
|
-
# copy the original getter
|
35
|
-
__instance.instance_variable_set("@__#{method_name}_original", __instance.method(method_name))
|
36
|
-
|
37
|
-
# store the block for lazy generation
|
38
|
-
__instance.instance_variable_set("@__#{method_name}_block", block)
|
39
|
-
|
40
|
-
# redefine the getter
|
41
|
-
__instance.instance_eval %<
|
42
|
-
def #{method_name}
|
43
|
-
original_value = @__#{method_name}_original.call
|
44
|
-
if @__#{method_name}_block
|
45
|
-
if #{count} \>= 1
|
46
|
-
original_value = #{method_name}= (1..#{count}).map { |i| @__#{method_name}_block.call(self, i) }
|
47
|
-
else
|
48
|
-
original_value = #{method_name}= @__#{method_name}_block.call(self)
|
49
|
-
end
|
50
|
-
@__#{method_name}_block = nil
|
51
|
-
end
|
52
|
-
original_value
|
53
|
-
end
|
54
|
-
>
|
55
|
-
else
|
56
|
-
assign(method_name, options, &block)
|
57
|
-
end
|
59
|
+
assign(method_name, args.first || {}, &block)
|
58
60
|
else
|
59
61
|
assign(method_name, {}, args.first)
|
60
62
|
end
|
@@ -64,31 +66,48 @@ class Fabrication::Generator::Base
|
|
64
66
|
|
65
67
|
attr_accessor :__klass, :__instance
|
66
68
|
|
67
|
-
def
|
68
|
-
|
69
|
+
def __attributes
|
70
|
+
@__attributes ||= {}
|
71
|
+
end
|
72
|
+
|
73
|
+
def persist
|
74
|
+
__instance.save! if __instance.respond_to?(:save!)
|
69
75
|
end
|
70
76
|
|
71
|
-
def assign(method_name, options,
|
77
|
+
def assign(method_name, options, value=nil, &block)
|
72
78
|
if options.has_key?(:count)
|
73
|
-
|
74
|
-
block_given? ? yield(__instance, i) : raw_value
|
75
|
-
end
|
79
|
+
assign_collection(method_name, options[:count], value, &block)
|
76
80
|
else
|
77
|
-
value
|
81
|
+
assign_field(method_name, value, &block)
|
78
82
|
end
|
79
|
-
|
83
|
+
end
|
84
|
+
|
85
|
+
def assign_field(field_name, value, &block)
|
86
|
+
__attributes[field_name] = block_given? ? yield(__attributes) : value
|
87
|
+
end
|
88
|
+
|
89
|
+
def assign_collection(field_name, count, value, &block)
|
90
|
+
__attributes[field_name] = block_given? ?
|
91
|
+
(1..count).map { |i| yield(__attributes, i) } :
|
92
|
+
value * count
|
80
93
|
end
|
81
94
|
|
82
95
|
def post_initialize; end
|
83
96
|
|
84
97
|
def process_attributes(attributes)
|
85
98
|
attributes.each do |attribute|
|
99
|
+
__transient_fields << attribute.name if attribute.transient?
|
86
100
|
if Proc === attribute.value
|
87
101
|
method_missing(attribute.name, attribute.params, &attribute.value)
|
88
102
|
else
|
89
103
|
method_missing(attribute.name, attribute.value)
|
90
104
|
end
|
91
105
|
end
|
106
|
+
__attributes.reject! { |k| __transient_fields.include?(k) }
|
107
|
+
end
|
108
|
+
|
109
|
+
def __transient_fields
|
110
|
+
@__transient_fields ||= []
|
92
111
|
end
|
93
112
|
|
94
113
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
class Fabrication::Generator::DataMapper < Fabrication::Generator::Base
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def self.supports?(klass)
|
4
|
+
defined?(DataMapper) && klass.ancestors.include?(DataMapper::Hook)
|
5
|
+
end
|
6
|
+
|
7
|
+
def build_instance
|
8
|
+
self.__instance = __klass.new(__attributes)
|
7
9
|
end
|
8
10
|
|
9
11
|
protected
|
10
12
|
|
11
|
-
def
|
12
|
-
__instance.save
|
13
|
+
def persist
|
14
|
+
__instance.save
|
13
15
|
end
|
14
16
|
end
|
@@ -1,21 +1,11 @@
|
|
1
1
|
class Fabrication::Generator::Mongoid < Fabrication::Generator::Base
|
2
|
+
|
2
3
|
def self.supports?(klass)
|
3
4
|
defined?(Mongoid) && klass.ancestors.include?(Mongoid::Document)
|
4
5
|
end
|
5
6
|
|
6
|
-
def
|
7
|
-
|
8
|
-
value = (1..options[:count]).map do |i|
|
9
|
-
block_given? ? yield(__instance, i) : raw_value
|
10
|
-
end
|
11
|
-
else
|
12
|
-
value = block_given? ? yield(__instance) : raw_value
|
13
|
-
end
|
14
|
-
|
15
|
-
if Mongoid.allow_dynamic_fields && !__instance.respond_to?("#{method_name}=")
|
16
|
-
__instance[method_name] = value
|
17
|
-
else
|
18
|
-
__instance.send("#{method_name}=", value)
|
19
|
-
end
|
7
|
+
def build_instance
|
8
|
+
self.__instance = __klass.new(__attributes)
|
20
9
|
end
|
10
|
+
|
21
11
|
end
|
@@ -4,8 +4,12 @@ class Fabrication::Generator::Sequel < Fabrication::Generator::Base
|
|
4
4
|
defined?(Sequel) && klass.ancestors.include?(Sequel::Model)
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
__instance
|
7
|
+
def build_instance
|
8
|
+
self.__instance = __klass.new(__attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def persist
|
12
|
+
__instance.save
|
9
13
|
end
|
10
14
|
|
11
15
|
end
|
@@ -2,10 +2,22 @@ class Fabrication::Schematic::Attribute
|
|
2
2
|
|
3
3
|
attr_accessor :name, :params, :value
|
4
4
|
|
5
|
-
def initialize(name, params,
|
5
|
+
def initialize(name, value, params={}, &block)
|
6
6
|
self.name = name
|
7
7
|
self.params = params
|
8
|
-
self.value = value
|
8
|
+
self.value = value.nil? ? block : value
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
@params ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def transient!
|
16
|
+
params[:transient] = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def transient?
|
20
|
+
params[:transient]
|
9
21
|
end
|
10
22
|
|
11
23
|
end
|
@@ -8,10 +8,9 @@ class Fabrication::Schematic::Definition
|
|
8
8
|
Fabrication::Generator::Base
|
9
9
|
]
|
10
10
|
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :klass
|
12
12
|
def initialize(klass, &block)
|
13
13
|
self.klass = klass
|
14
|
-
self.generator = GENERATORS.detect { |gen| gen.supports?(klass) }
|
15
14
|
instance_eval(&block) if block_given?
|
16
15
|
end
|
17
16
|
|
@@ -29,8 +28,10 @@ class Fabrication::Schematic::Definition
|
|
29
28
|
attributes.select { |a| a.name == name }.first
|
30
29
|
end
|
31
30
|
|
32
|
-
def append_or_update_attribute(
|
31
|
+
def append_or_update_attribute(attribute_name, value, params={}, &block)
|
32
|
+
attribute = Fabrication::Schematic::Attribute.new(attribute_name, value, params, &block)
|
33
33
|
if index = attributes.index { |a| a.name == attribute.name }
|
34
|
+
attribute.transient! if attributes[index].transient?
|
34
35
|
attributes[index] = attribute
|
35
36
|
else
|
36
37
|
attributes << attribute
|
@@ -47,14 +48,30 @@ class Fabrication::Schematic::Definition
|
|
47
48
|
@callbacks ||= {}
|
48
49
|
end
|
49
50
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def generator
|
52
|
+
@generator ||= GENERATORS.detect { |gen| gen.supports?(klass) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def build(overrides={}, &block)
|
56
|
+
Fabrication.schematics.build_stack << self
|
57
|
+
merge(overrides, &block).instance_eval do
|
58
|
+
generator.new(klass).build(attributes, callbacks)
|
59
|
+
end.tap { Fabrication.schematics.build_stack.pop }
|
60
|
+
end
|
61
|
+
|
62
|
+
def fabricate(overrides={}, &block)
|
63
|
+
if Fabrication.schematics.build_stack.empty?
|
64
|
+
merge(overrides, &block).instance_eval do
|
65
|
+
generator.new(klass).create(attributes, callbacks)
|
57
66
|
end
|
67
|
+
else
|
68
|
+
build(overrides, &block)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_attributes(overrides={}, &block)
|
73
|
+
merge(overrides, &block).instance_eval do
|
74
|
+
generator.new(klass).to_hash(attributes, callbacks)
|
58
75
|
end
|
59
76
|
end
|
60
77
|
|
@@ -72,40 +89,41 @@ class Fabrication::Schematic::Definition
|
|
72
89
|
end
|
73
90
|
|
74
91
|
def merge(overrides={}, &block)
|
92
|
+
return self unless overrides.any? or block_given?
|
75
93
|
clone.tap do |schematic|
|
76
94
|
schematic.instance_eval(&block) if block_given?
|
77
95
|
overrides.each do |name, value|
|
78
|
-
schematic.append_or_update_attribute(
|
96
|
+
schematic.append_or_update_attribute(name.to_sym, value)
|
79
97
|
end
|
80
98
|
end
|
81
99
|
end
|
82
100
|
|
83
101
|
def method_missing(method_name, *args, &block)
|
84
|
-
method_name = parse_method_name(method_name
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
params = {}
|
90
|
-
value = args.first
|
91
|
-
end
|
92
|
-
|
93
|
-
append_or_update_attribute(Fabrication::Schematic::Attribute.new(method_name, params, value))
|
102
|
+
method_name = parse_method_name(method_name)
|
103
|
+
params = args.extract_options!
|
104
|
+
value = args.first
|
105
|
+
block = generate_value(method_name, params) if args.empty? && !block_given?
|
106
|
+
append_or_update_attribute(method_name, value, params, &block)
|
94
107
|
end
|
95
108
|
|
96
109
|
def on_init(&block)
|
97
110
|
callbacks[:on_init] = block
|
98
111
|
end
|
99
112
|
|
100
|
-
def parse_method_name(method_name
|
113
|
+
def parse_method_name(method_name)
|
101
114
|
if method_name.to_s.end_with?("!")
|
115
|
+
warn("DEPRECATION WARNING: Using the \"!\" in Fabricators is no longer supported. Please remove all occurrances")
|
102
116
|
method_name = method_name.to_s.chomp("!").to_sym
|
103
|
-
args[0] ||= {}
|
104
|
-
args[0][:force] = true
|
105
117
|
end
|
106
118
|
method_name
|
107
119
|
end
|
108
120
|
|
121
|
+
def transient(*field_names)
|
122
|
+
field_names.each do |field_name|
|
123
|
+
append_or_update_attribute(field_name, nil, transient: true)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
109
127
|
def sequence(name=Fabrication::Sequencer::DEFAULT, start=0, &block)
|
110
128
|
name = "#{self.klass.to_s.downcase.gsub(/::/, '_')}_#{name}"
|
111
129
|
Fabrication::Sequencer.sequence(name, start, &block)
|
@@ -119,18 +137,4 @@ class Fabrication::Schematic::Definition
|
|
119
137
|
params[:count] ||= 1 if !params[:count] && name != name.to_s
|
120
138
|
Proc.new { Fabricate(params[:fabricator] || name.to_sym) }
|
121
139
|
end
|
122
|
-
|
123
|
-
def to_hash(object)
|
124
|
-
(defined?(HashWithIndifferentAccess) ? HashWithIndifferentAccess.new : {}).tap do |hash|
|
125
|
-
attributes.map do |attribute|
|
126
|
-
value = object.send(attribute.name)
|
127
|
-
if value && value.respond_to?(:id)
|
128
|
-
hash["#{attribute.name}_id"] = value.id
|
129
|
-
else
|
130
|
-
hash[attribute.name] = value
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
140
|
end
|
@@ -1,5 +1,16 @@
|
|
1
1
|
class Fabrication::Schematic::Manager
|
2
2
|
|
3
|
+
def preinitialize
|
4
|
+
@initializing = true
|
5
|
+
clear
|
6
|
+
end
|
7
|
+
|
8
|
+
def initializing?; @initializing end
|
9
|
+
|
10
|
+
def freeze
|
11
|
+
@initializing = false
|
12
|
+
end
|
13
|
+
|
3
14
|
def clear
|
4
15
|
schematics.clear
|
5
16
|
end
|
@@ -22,6 +33,10 @@ class Fabrication::Schematic::Manager
|
|
22
33
|
@schematics ||= {}
|
23
34
|
end
|
24
35
|
|
36
|
+
def build_stack
|
37
|
+
@build_stack ||= []
|
38
|
+
end
|
39
|
+
|
25
40
|
protected
|
26
41
|
|
27
42
|
def raise_if_registered(name)
|
data/lib/fabrication/support.rb
CHANGED
@@ -23,14 +23,14 @@ class Fabrication::Support
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def find_definitions
|
26
|
-
Fabrication.
|
26
|
+
Fabrication.schematics.preinitialize
|
27
27
|
path_prefix = defined?(Rails) ? Rails.root : "."
|
28
28
|
Fabrication::Config.fabricator_dir.each do |folder|
|
29
29
|
Dir.glob(File.join(path_prefix, folder, '**', '*.rb')).sort.each do |file|
|
30
30
|
load file
|
31
31
|
end
|
32
32
|
end
|
33
|
-
Fabrication.
|
33
|
+
Fabrication.schematics.freeze
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
data/lib/fabrication/version.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
World(FabricationMethods)
|
2
2
|
|
3
|
+
Fabrication::Config.register_with_steps = true
|
4
|
+
|
3
5
|
def with_ivars(fabricator)
|
4
6
|
@they = yield fabricator
|
5
|
-
|
7
|
+
model = @they.last.class.to_s.underscore
|
8
|
+
instance_variable_set("@#{model.pluralize}", @they)
|
9
|
+
instance_variable_set("@#{model.singularize}", @they.last)
|
10
|
+
Fabrication::Cucumber::Fabrications[model.singularize.gsub(/\W+/,'_').downcase] = @they.last
|
6
11
|
end
|
7
12
|
|
8
13
|
Given /^(\d+) ([^"]*)$/ do |count, model_name|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70125484404120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70125484404120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bson_ext
|
27
|
-
requirement: &
|
27
|
+
requirement: &70125484403700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70125484403700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &70125484403280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70125484403280
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &70125484402860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70125484402860
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: dm-active_model
|
60
|
-
requirement: &
|
60
|
+
requirement: &70125484402440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70125484402440
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: dm-core
|
71
|
-
requirement: &
|
71
|
+
requirement: &70125484402020 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70125484402020
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: dm-migrations
|
82
|
-
requirement: &
|
82
|
+
requirement: &70125484401600 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70125484401600
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: dm-sqlite-adapter
|
93
|
-
requirement: &
|
93
|
+
requirement: &70125484401180 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70125484401180
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: turnip
|
104
|
-
requirement: &
|
104
|
+
requirement: &70125484400660 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0.3'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70125484400660
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: ffaker
|
115
|
-
requirement: &
|
115
|
+
requirement: &70125484400240 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70125484400240
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: mongoid
|
126
|
-
requirement: &
|
126
|
+
requirement: &70125484399780 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70125484399780
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: pry
|
137
|
-
requirement: &
|
137
|
+
requirement: &70125484399360 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70125484399360
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: rake
|
148
|
-
requirement: &
|
148
|
+
requirement: &70125484398940 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70125484398940
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: rspec
|
159
|
-
requirement: &
|
159
|
+
requirement: &70125484398520 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,10 +164,10 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70125484398520
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: sequel
|
170
|
-
requirement: &
|
170
|
+
requirement: &70125484398100 !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
173
|
- - ! '>='
|
@@ -175,9 +175,9 @@ dependencies:
|
|
175
175
|
version: '0'
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
|
-
version_requirements: *
|
178
|
+
version_requirements: *70125484398100
|
179
179
|
description: Fabrication is an object generation framework for ActiveRecord, Mongoid,
|
180
|
-
|
180
|
+
DataMapper, Sequel, or any other Ruby object.
|
181
181
|
email:
|
182
182
|
- paul@hashrocket.com
|
183
183
|
executables: []
|