factory_girl 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -21,7 +21,7 @@ def Factory (name, attrs = {})
21
21
  end
22
22
 
23
23
  class Factory
24
- VERSION = "1.3.2"
24
+ VERSION = "1.3.3"
25
25
  end
26
26
 
27
27
  if defined?(Rails) && Rails::VERSION::MAJOR == 2
@@ -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
- @attributes << attribute.clone
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 2
10
- version: 1.3.2
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: 2010-08-03 00:00:00 -04:00
18
+ date: 2011-01-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency