factory_girl 1.3.2 → 1.3.3
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.
- data/features/support/test.db +0 -0
- data/lib/factory_girl.rb +1 -1
- data/lib/factory_girl/factory.rb +4 -1
- data/spec/factory_girl/factory_spec.rb +17 -1
- metadata +4 -4
data/features/support/test.db
CHANGED
Binary file
|
data/lib/factory_girl.rb
CHANGED
data/lib/factory_girl/factory.rb
CHANGED
@@ -85,11 +85,14 @@ class Factory
|
|
85
85
|
def inherit_from(parent) #:nodoc:
|
86
86
|
@options[:class] ||= parent.class_name
|
87
87
|
@options[:default_strategy] ||= parent.default_strategy
|
88
|
+
|
89
|
+
new_attributes = []
|
88
90
|
parent.attributes.each do |attribute|
|
89
91
|
unless attribute_defined?(attribute.name)
|
90
|
-
|
92
|
+
new_attributes << attribute.clone
|
91
93
|
end
|
92
94
|
end
|
95
|
+
@attributes.unshift *new_attributes
|
93
96
|
end
|
94
97
|
|
95
98
|
# Adds an attribute that should be assigned on generated instances for this
|
@@ -528,6 +528,22 @@ describe Factory do
|
|
528
528
|
child.attributes.first.should be_kind_of(Factory::Attribute::Dynamic)
|
529
529
|
end
|
530
530
|
|
531
|
+
it "should allow to use parent attributes in defining additional attributes" do
|
532
|
+
User.class_eval { attr_accessor :name, :email }
|
533
|
+
|
534
|
+
parent = Factory.define(:parent, :class => User) do |f|
|
535
|
+
f.name 'value'
|
536
|
+
end
|
537
|
+
|
538
|
+
child = Factory.new(:child)
|
539
|
+
child.add_attribute(:email) {|u| "#{u.name}@example.com" }
|
540
|
+
child.inherit_from(parent)
|
541
|
+
child.attributes.size.should == 2
|
542
|
+
|
543
|
+
result = child.run(Factory::Proxy::Build, {})
|
544
|
+
result.email.should == 'value@example.com'
|
545
|
+
end
|
546
|
+
|
531
547
|
it "inherit all callbacks" do
|
532
548
|
Factory.define(:child, :parent => :object) do |f|
|
533
549
|
f.after_stub {|o| o.name = 'Stubby' }
|
@@ -538,8 +554,8 @@ describe Factory do
|
|
538
554
|
end
|
539
555
|
|
540
556
|
grandchild.attributes.size.should == 3
|
541
|
-
grandchild.attributes.first.should be_kind_of(Factory::Attribute::Callback)
|
542
557
|
grandchild.attributes[1].should be_kind_of(Factory::Attribute::Callback)
|
558
|
+
grandchild.attributes[2].should be_kind_of(Factory::Attribute::Callback)
|
543
559
|
end
|
544
560
|
end
|
545
561
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 3
|
10
|
+
version: 1.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Ferris
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-11 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|