factory_girl 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Changelog +25 -0
  2. data/GETTING_STARTED.md +10 -3
  3. data/Gemfile.lock +1 -1
  4. data/README.md +1 -1
  5. data/gemfiles/2.1.gemfile.lock +1 -1
  6. data/gemfiles/2.3.gemfile.lock +1 -1
  7. data/gemfiles/3.0.gemfile.lock +1 -1
  8. data/gemfiles/3.1.gemfile.lock +1 -1
  9. data/lib/factory_girl.rb +9 -0
  10. data/lib/factory_girl/attribute.rb +2 -6
  11. data/lib/factory_girl/attribute/association.rb +1 -1
  12. data/lib/factory_girl/attribute/dynamic.rb +8 -3
  13. data/lib/factory_girl/attribute/sequence.rb +8 -3
  14. data/lib/factory_girl/attribute/static.rb +7 -3
  15. data/lib/factory_girl/attribute_list.rb +5 -4
  16. data/lib/factory_girl/declaration.rb +5 -5
  17. data/lib/factory_girl/declaration/association.rb +1 -1
  18. data/lib/factory_girl/declaration/dynamic.rb +3 -3
  19. data/lib/factory_girl/declaration/implicit.rb +3 -3
  20. data/lib/factory_girl/declaration/static.rb +3 -3
  21. data/lib/factory_girl/definition_proxy.rb +14 -11
  22. data/lib/factory_girl/factory.rb +71 -79
  23. data/lib/factory_girl/proxy.rb +6 -1
  24. data/lib/factory_girl/proxy/attributes_for.rb +2 -6
  25. data/lib/factory_girl/proxy/build.rb +2 -7
  26. data/lib/factory_girl/proxy/stub.rb +2 -6
  27. data/lib/factory_girl/step_definitions.rb +3 -2
  28. data/lib/factory_girl/syntax/default.rb +1 -9
  29. data/lib/factory_girl/syntax/methods.rb +16 -8
  30. data/lib/factory_girl/syntax/vintage.rb +0 -3
  31. data/lib/factory_girl/version.rb +1 -1
  32. data/spec/acceptance/attribute_existing_on_object.rb +21 -0
  33. data/spec/acceptance/attributes_for_spec.rb +17 -0
  34. data/spec/acceptance/build_spec.rb +17 -0
  35. data/spec/acceptance/build_stubbed_spec.rb +18 -0
  36. data/spec/acceptance/create_spec.rb +18 -0
  37. data/spec/acceptance/define_child_before_parent_spec.rb +21 -0
  38. data/spec/acceptance/syntax/blueprint_spec.rb +2 -2
  39. data/spec/acceptance/syntax/generate_spec.rb +9 -9
  40. data/spec/acceptance/syntax/make_spec.rb +6 -6
  41. data/spec/acceptance/syntax/sham_spec.rb +3 -3
  42. data/spec/acceptance/syntax/vintage_spec.rb +30 -29
  43. data/spec/acceptance/transient_attributes_spec.rb +45 -3
  44. data/spec/factory_girl/attribute/dynamic_spec.rb +5 -5
  45. data/spec/factory_girl/attribute/sequence_spec.rb +1 -1
  46. data/spec/factory_girl/attribute/static_spec.rb +3 -3
  47. data/spec/factory_girl/attribute_list_spec.rb +9 -24
  48. data/spec/factory_girl/attribute_spec.rb +3 -3
  49. data/spec/factory_girl/definition_proxy_spec.rb +23 -42
  50. data/spec/factory_girl/factory_spec.rb +26 -95
  51. data/spec/factory_girl/find_definitions_spec.rb +1 -1
  52. data/spec/support/shared_examples/proxy.rb +1 -1
  53. metadata +119 -122
data/Changelog CHANGED
@@ -1,3 +1,28 @@
1
+ 2.2.0 (October 14, 2011)
2
+ Clean up RSpec suite to not use 'should'
3
+ Use create_list in step definitions
4
+ Syntax methods that deal with ORM interaction (attributes_for, build, build_stubbed,
5
+ and create) now accept a block that yields the result. This results in a
6
+ more convenient way to interact with the result than using Object.tap.
7
+ Standardize deprecation warnings
8
+ Update transient attribute syntax to use blocks instead of calling ignore on
9
+ each attribute declaration
10
+ Parents can be defined after children because factories are evaluated when
11
+ they're used; this means breaking up factories across multiple files will
12
+ behave as expected
13
+ Large internal refactoring, including changing access modifiers for a
14
+ handful of methods for a more clearly defined API
15
+
16
+ 2.1.2 (September 23, 2011)
17
+ Bugfix: Vintage syntax fixed after bug introduced in 2.1.1
18
+ Introduce dependency on activesupport to remove code from Factory class
19
+
20
+ 2.1.1 (September 23, 2011) (yanked)
21
+ Bugfix: Parent object callbacks are run before child object callbacks
22
+ Declarations: allow overriding/modification of individual traits in child factories
23
+ Callbacks refactored to not be attributes
24
+ Updating documentation for formatting and clarity (incl. new specificity for cucumber)
25
+
1
26
  2.1.0 (September 02, 2011)
2
27
  Bugfix: created_at now defined for stubbed models
3
28
  Gemspec updated for use with Rails 3.1
@@ -69,7 +69,12 @@ factory\_girl supports several different build strategies: build, create, attrib
69
69
  attrs = FactoryGirl.attributes_for(:user)
70
70
 
71
71
  # Returns an object with all defined attributes stubbed out
72
- stub = FactoryGirl.build_stubbed(:user)
72
+ stub = FactoryGirl.build_stubbed(:user
73
+
74
+ # Passing a block to any of the methods above will yield the return object
75
+ FactoryGirl.create(:user) do |user|
76
+ user.posts.create(attributes_for(:post))
77
+ end
73
78
 
74
79
  No matter which strategy is used, it's possible to override the defined attributes by passing a hash:
75
80
 
@@ -159,8 +164,10 @@ Transient Attributes
159
164
  There may be times where your code can be DRYed up by passing in transient attributes to factories.
160
165
 
161
166
  factory :user do
162
- rockstar(true).ignore
163
- upcased { false }.ignore
167
+ ignore do
168
+ rockstar true
169
+ upcased { false }
170
+ end
164
171
 
165
172
  name { "John Doe#{" - Rockstar" if rockstar}" }
166
173
  email { "#{name.downcase}@example.com" }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (2.1.2)
4
+ factory_girl (2.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -10,7 +10,7 @@ Documentation
10
10
 
11
11
  You should find the documentation for your version of factory_girl on [Rubygems](http://rubygems.org/gems/factory_girl).
12
12
 
13
- See [GETTING_STARTED.md](http://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md) for information on defining and using factories.
13
+ See {file:GETTING_STARTED.md} for information on defining and using factories.
14
14
 
15
15
  Install
16
16
  --------
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.1.2)
4
+ factory_girl (2.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.1.2)
4
+ factory_girl (2.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.1.2)
4
+ factory_girl (2.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.1.2)
4
+ factory_girl (2.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -34,6 +34,15 @@ if defined?(Rails) && Rails::VERSION::MAJOR == 2
34
34
  end
35
35
 
36
36
  module FactoryGirl
37
+ # Raised when a factory is defined that attempts to instantiate itself.
38
+ class AssociationDefinitionError < RuntimeError; end
39
+
40
+ # Raised when a callback is defined that has an invalid name
41
+ class InvalidCallbackNameError < RuntimeError; end
42
+
43
+ # Raised when a factory is defined with the same name as a previously-defined factory.
44
+ class DuplicateDefinitionError < RuntimeError; end
45
+
37
46
  def self.factories
38
47
  @factories ||= Registry.new
39
48
  end
@@ -12,16 +12,12 @@ module FactoryGirl
12
12
 
13
13
  attr_reader :name, :ignored
14
14
 
15
- def initialize(name)
15
+ def initialize(name, ignored)
16
16
  @name = name.to_sym
17
- @ignored = false
17
+ @ignored = ignored
18
18
  ensure_non_attribute_writer!
19
19
  end
20
20
 
21
- def ignore
22
- @ignored = true
23
- end
24
-
25
21
  def add_to(proxy)
26
22
  end
27
23
 
@@ -4,7 +4,7 @@ module FactoryGirl
4
4
  attr_reader :factory
5
5
 
6
6
  def initialize(name, factory, overrides)
7
- super(name)
7
+ super(name, false)
8
8
  @factory = factory
9
9
  @overrides = overrides
10
10
  end
@@ -1,8 +1,8 @@
1
1
  module FactoryGirl
2
2
  class Attribute #:nodoc:
3
3
  class Dynamic < Attribute #:nodoc:
4
- def initialize(name, block)
5
- super(name)
4
+ def initialize(name, ignored, block)
5
+ super(name, ignored)
6
6
  @block = block
7
7
  end
8
8
 
@@ -11,7 +11,12 @@ module FactoryGirl
11
11
  if FactoryGirl::Sequence === value
12
12
  raise SequenceAbuseError
13
13
  end
14
- proxy.set(name, value, @ignored)
14
+
15
+ if @ignored
16
+ proxy.set_ignored(name, value)
17
+ else
18
+ proxy.set(name, value)
19
+ end
15
20
  end
16
21
  end
17
22
  end
@@ -2,13 +2,18 @@ module FactoryGirl
2
2
  class Attribute
3
3
 
4
4
  class Sequence < Attribute
5
- def initialize(name, sequence)
6
- super(name)
5
+ def initialize(name, sequence, ignored)
6
+ super(name, ignored)
7
7
  @sequence = sequence
8
8
  end
9
9
 
10
10
  def add_to(proxy)
11
- proxy.set(name, FactoryGirl.generate(@sequence))
11
+ value = FactoryGirl.generate(@sequence)
12
+ if @ignored
13
+ proxy.set_ignored(name, value)
14
+ else
15
+ proxy.set(name, value)
16
+ end
12
17
  end
13
18
  end
14
19
 
@@ -5,13 +5,17 @@ module FactoryGirl
5
5
 
6
6
  attr_reader :value
7
7
 
8
- def initialize(name, value)
9
- super(name)
8
+ def initialize(name, value, ignored)
9
+ super(name, ignored)
10
10
  @value = value
11
11
  end
12
12
 
13
13
  def add_to(proxy)
14
- proxy.set(name, @value, @ignored)
14
+ if @ignored
15
+ proxy.set_ignored(name, @value)
16
+ else
17
+ proxy.set(name, @value)
18
+ end
15
19
  end
16
20
 
17
21
  def priority
@@ -13,6 +13,7 @@ module FactoryGirl
13
13
 
14
14
  def declare_attribute(declaration)
15
15
  @declarations << declaration
16
+ declaration
16
17
  end
17
18
 
18
19
  def define_attribute(attribute)
@@ -31,10 +32,6 @@ module FactoryGirl
31
32
  flattened_attributes.each(&block)
32
33
  end
33
34
 
34
- def attribute_defined?(attribute_name)
35
- !!find_attribute(attribute_name)
36
- end
37
-
38
35
  def apply_attributes(attributes_to_apply)
39
36
  attributes_to_apply.callbacks.reverse.each { |callback| prepend_callback(callback) }
40
37
  new_attributes = []
@@ -93,6 +90,10 @@ module FactoryGirl
93
90
  end.flatten
94
91
  end
95
92
 
93
+ def attribute_defined?(attribute_name)
94
+ !!find_attribute(attribute_name)
95
+ end
96
+
96
97
  def find_attribute(attribute_name)
97
98
  @attributes.values.flatten.detect do |attribute|
98
99
  attribute.name == attribute_name
@@ -2,18 +2,18 @@ module FactoryGirl
2
2
  class Declaration
3
3
  attr_reader :name
4
4
 
5
- def initialize(name)
6
- @name = name
5
+ def initialize(name, ignored = false)
6
+ @name = name
7
+ @ignored = ignored
7
8
  end
8
9
 
9
10
  def ignore
11
+ $stderr.puts "DEPRECATION WARNING: Use ignore block syntax instead of calling #ignore"
10
12
  @ignored = true
11
13
  end
12
14
 
13
15
  def to_attributes
14
- build.tap do |attributes|
15
- attributes.each(&:ignore) if @ignored
16
- end
16
+ build
17
17
  end
18
18
  end
19
19
  end
@@ -2,7 +2,7 @@ module FactoryGirl
2
2
  class Declaration
3
3
  class Association < Declaration
4
4
  def initialize(name, options)
5
- super(name)
5
+ super(name, false)
6
6
  @options = options
7
7
  end
8
8
 
@@ -1,15 +1,15 @@
1
1
  module FactoryGirl
2
2
  class Declaration
3
3
  class Dynamic < Declaration
4
- def initialize(name, block)
5
- super(name)
4
+ def initialize(name, ignored = false, block = nil)
5
+ super(name, ignored)
6
6
  @block = block
7
7
  end
8
8
 
9
9
  private
10
10
 
11
11
  def build
12
- [Attribute::Dynamic.new(name, @block)]
12
+ [Attribute::Dynamic.new(name, @ignored, @block)]
13
13
  end
14
14
  end
15
15
  end
@@ -1,8 +1,8 @@
1
1
  module FactoryGirl
2
2
  class Declaration
3
3
  class Implicit < Declaration
4
- def initialize(name, factory = nil)
5
- super(name)
4
+ def initialize(name, factory = nil, ignored = false)
5
+ super(name, ignored)
6
6
  @factory = factory
7
7
  end
8
8
 
@@ -12,7 +12,7 @@ module FactoryGirl
12
12
  if FactoryGirl.factories.registered?(name)
13
13
  [Attribute::Association.new(name, name, {})]
14
14
  elsif FactoryGirl.sequences.registered?(name)
15
- [Attribute::Sequence.new(name, name)]
15
+ [Attribute::Sequence.new(name, name, @ignored)]
16
16
  else
17
17
  trait_root = @factory || FactoryGirl
18
18
  trait_root.trait_by_name(name).attributes.to_a
@@ -1,15 +1,15 @@
1
1
  module FactoryGirl
2
2
  class Declaration
3
3
  class Static < Declaration
4
- def initialize(name, value)
5
- super(name)
4
+ def initialize(name, value, ignored = false)
5
+ super(name, ignored)
6
6
  @value = value
7
7
  end
8
8
 
9
9
  private
10
10
 
11
11
  def build
12
- [Attribute::Static.new(name, @value)]
12
+ [Attribute::Static.new(name, @value, @ignored)]
13
13
  end
14
14
  end
15
15
  end
@@ -8,8 +8,9 @@ module FactoryGirl
8
8
 
9
9
  attr_reader :child_factories
10
10
 
11
- def initialize(factory)
12
- @factory = factory
11
+ def initialize(factory, ignore = false)
12
+ @factory = factory
13
+ @ignore = ignore
13
14
  @child_factories = []
14
15
  end
15
16
 
@@ -32,18 +33,20 @@ module FactoryGirl
32
33
  # * value: +Object+
33
34
  # If no block is given, this value will be used for this attribute.
34
35
  def add_attribute(name, value = nil, &block)
35
- if block_given?
36
- if value
37
- raise AttributeDefinitionError, "Both value and block given"
38
- else
39
- declaration = Declaration::Dynamic.new(name, block)
40
- end
36
+ raise AttributeDefinitionError, "Both value and block given" if value && block_given?
37
+
38
+ declaration = if block_given?
39
+ Declaration::Dynamic.new(name, @ignore, block)
41
40
  else
42
- declaration = FactoryGirl::Declaration::Static.new(name, value)
41
+ Declaration::Static.new(name, value, @ignore)
43
42
  end
44
43
 
45
44
  @factory.declare_attribute(declaration)
46
- declaration
45
+ end
46
+
47
+ def ignore(&block)
48
+ proxy = DefinitionProxy.new(@factory, true)
49
+ proxy.instance_eval(&block)
47
50
  end
48
51
 
49
52
  # Calls add_attribute using the missing method name as the name of the
@@ -79,7 +82,7 @@ module FactoryGirl
79
82
  # are equivalent.
80
83
  def method_missing(name, *args, &block)
81
84
  if args.empty? && block.nil?
82
- @factory.declare_attribute(Declaration::Implicit.new(name, @factory))
85
+ @factory.declare_attribute(Declaration::Implicit.new(name, @factory, @ignore))
83
86
  elsif args.first.is_a?(Hash) && args.first.has_key?(:factory)
84
87
  association(name, *args)
85
88
  else
@@ -2,28 +2,25 @@ require "active_support/core_ext/hash/keys"
2
2
  require "active_support/inflector"
3
3
 
4
4
  module FactoryGirl
5
- # Raised when a factory is defined that attempts to instantiate itself.
6
- class AssociationDefinitionError < RuntimeError
7
- end
8
-
9
- # Raised when a callback is defined that has an invalid name
10
- class InvalidCallbackNameError < RuntimeError
11
- end
12
-
13
- # Raised when a factory is defined with the same name as a previously-defined factory.
14
- class DuplicateDefinitionError < RuntimeError
15
- end
16
-
17
5
  class Factory
18
6
  attr_reader :name #:nodoc:
19
7
 
20
- def factory_name
21
- puts "WARNING: factory.factory_name is deprecated. Use factory.name instead."
22
- name
8
+ def initialize(name, options = {}) #:nodoc:
9
+ assert_valid_options(options)
10
+ @name = name.to_s.underscore.to_sym
11
+ @parent = options[:parent]
12
+ @aliases = options[:aliases] || []
13
+ @traits = options[:traits] || []
14
+ @class_name = options[:class]
15
+ @default_strategy = options[:default_strategy]
16
+ @defined_traits = []
17
+ @attribute_list = AttributeList.new
18
+ @compiled = false
23
19
  end
24
20
 
25
- def class_name #:nodoc:
26
- @options[:class] || name
21
+ def factory_name
22
+ $stderr.puts "DEPRECATION WARNING: factory.factory_name is deprecated; use factory.name instead."
23
+ name
27
24
  end
28
25
 
29
26
  def build_class #:nodoc:
@@ -31,23 +28,11 @@ module FactoryGirl
31
28
  end
32
29
 
33
30
  def default_strategy #:nodoc:
34
- @options[:default_strategy] || :create
35
- end
36
-
37
- def initialize(name, options = {}) #:nodoc:
38
- assert_valid_options(options)
39
- @name = name.to_s.underscore.to_sym
40
- @parent = options[:parent]
41
- @parent_factory = nil
42
- @options = options
43
- @defined_traits = []
44
- @traits = []
45
- @children = []
46
- @attribute_list = AttributeList.new
47
- @compiled = false
31
+ @default_strategy || (parent && parent.default_strategy) || :create
48
32
  end
49
33
 
50
34
  def allow_overrides
35
+ @compiled = false
51
36
  @attribute_list.overridable
52
37
  self
53
38
  end
@@ -56,24 +41,6 @@ module FactoryGirl
56
41
  @attribute_list.overridable?
57
42
  end
58
43
 
59
- def inherit_factory(parent) #:nodoc:
60
- @options[:class] ||= parent.class_name
61
- @options[:default_strategy] ||= parent.default_strategy
62
-
63
- allow_overrides if parent.allow_overrides?
64
- parent.add_child(self)
65
-
66
- @parent_factory = parent
67
- end
68
-
69
- def add_child(factory)
70
- @children << factory unless @children.include?(factory)
71
- end
72
-
73
- def inherit_traits(traits)
74
- @traits = traits
75
- end
76
-
77
44
  def define_trait(trait)
78
45
  @defined_traits << trait
79
46
  end
@@ -82,19 +49,8 @@ module FactoryGirl
82
49
  @attribute_list.add_callback(Callback.new(name, block))
83
50
  end
84
51
 
85
- def attributes
52
+ def run(proxy_class, overrides, &block) #:nodoc:
86
53
  ensure_compiled
87
- AttributeList.new.tap do |list|
88
- @traits.reverse.map { |name| trait_by_name(name) }.each do |trait|
89
- list.apply_attributes(trait.attributes)
90
- end
91
-
92
- list.apply_attributes(@attribute_list)
93
- list.apply_attributes(@parent_factory.attributes) if @parent_factory
94
- end
95
- end
96
-
97
- def run(proxy_class, overrides) #:nodoc:
98
54
  proxy = proxy_class.new(build_class)
99
55
  callbacks.each { |callback| proxy.add_callback(callback) }
100
56
  overrides = overrides.symbolize_keys
@@ -104,11 +60,21 @@ module FactoryGirl
104
60
  if factory_overrides.empty?
105
61
  attribute.add_to(proxy)
106
62
  else
107
- factory_overrides.each { |attr, val| proxy.set(attr, val, attribute.ignored); overrides.delete(attr) }
63
+ factory_overrides.each do |attr, val|
64
+ if attribute.ignored
65
+ proxy.set_ignored(attr, val)
66
+ else
67
+ proxy.set(attr, val)
68
+ end
69
+
70
+ overrides.delete(attr)
71
+ end
108
72
  end
109
73
  end
110
74
  overrides.each { |attr, val| proxy.set(attr, val) }
111
- proxy.result(@to_create_block)
75
+ result = proxy.result(@to_create_block)
76
+
77
+ block ? block.call(result) : result
112
78
  end
113
79
 
114
80
  def human_names
@@ -122,8 +88,8 @@ module FactoryGirl
122
88
  def trait_by_name(name)
123
89
  if existing_attribute = trait_for(name)
124
90
  existing_attribute
125
- elsif @parent
126
- FactoryGirl.factory_by_name(@parent).trait_by_name(name)
91
+ elsif parent
92
+ parent.trait_by_name(name)
127
93
  else
128
94
  FactoryGirl.trait_by_name(name)
129
95
  end
@@ -155,47 +121,72 @@ module FactoryGirl
155
121
  # FactoryGirl.create(:post).author.class
156
122
  # # => User
157
123
  def names
158
- [name] + (@options[:aliases] || [])
124
+ [name] + @aliases
159
125
  end
160
126
 
161
127
  def to_create(&block)
162
128
  @to_create_block = block
163
129
  end
164
130
 
131
+ def ensure_compiled
132
+ compile unless @compiled
133
+ end
134
+
135
+ def declare_attribute(declaration)
136
+ @attribute_list.declare_attribute(declaration)
137
+ end
138
+
139
+ protected
140
+
141
+ def class_name #:nodoc:
142
+ @class_name || (parent && parent.class_name) || name
143
+ end
144
+
145
+ def attributes
146
+ ensure_compiled
147
+ AttributeList.new.tap do |list|
148
+ @traits.reverse.map { |name| trait_by_name(name) }.each do |trait|
149
+ list.apply_attributes(trait.attributes)
150
+ end
151
+
152
+ list.apply_attributes(@attribute_list)
153
+ list.apply_attributes(parent.attributes) if parent
154
+ end
155
+ end
156
+
157
+ private
158
+
165
159
  def callbacks
166
160
  attributes.callbacks
167
161
  end
168
162
 
169
163
  def compile
164
+ inherit_factory(parent) if parent
165
+
170
166
  declarations.each do |declaration|
171
167
  declaration.to_attributes.each do |attribute|
172
168
  define_attribute(attribute)
173
169
  end
174
170
  end
171
+
175
172
  @compiled = true
176
173
  end
177
174
 
178
- def declare_attribute(declaration)
179
- @attribute_list.declare_attribute(declaration)
175
+ def inherit_factory(parent) #:nodoc:
176
+ parent.ensure_compiled
177
+ allow_overrides if parent.allow_overrides?
180
178
  end
181
179
 
182
- private
183
-
184
180
  def declarations
185
181
  @attribute_list.declarations
186
182
  end
187
183
 
188
- def update_children
189
- @children.each { |child| child.inherit_factory(self) }
190
- end
191
-
192
184
  def define_attribute(attribute)
193
185
  if attribute.respond_to?(:factory) && attribute.factory == self.name
194
186
  raise AssociationDefinitionError, "Self-referencing association '#{attribute.name}' in factory '#{self.name}'"
195
187
  end
196
188
 
197
189
  @attribute_list.define_attribute(attribute)
198
- update_children if allow_overrides?
199
190
  end
200
191
 
201
192
  def assert_valid_options(options)
@@ -203,8 +194,8 @@ module FactoryGirl
203
194
 
204
195
  if options[:default_strategy]
205
196
  assert_valid_strategy(options[:default_strategy])
206
- puts "WARNING: default_strategy is deprecated."
207
- puts "Override to_create if you need to prevent a call to #save!."
197
+ $stderr.puts "DEPRECATION WARNING: default_strategy is deprecated."
198
+ $stderr.puts "Override to_create if you need to prevent a call to #save!."
208
199
  end
209
200
  end
210
201
 
@@ -218,8 +209,9 @@ module FactoryGirl
218
209
  @defined_traits.detect {|trait| trait.name == name }
219
210
  end
220
211
 
221
- def ensure_compiled
222
- compile unless @compiled
212
+ def parent
213
+ return unless @parent
214
+ FactoryGirl.factory_by_name(@parent)
223
215
  end
224
216
  end
225
217
  end