freegenie-factory_girl 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/factory_girl/factory.rb +9 -2
- data/lib/factory_girl/proxy.rb +5 -0
- data/lib/factory_girl/proxy/build.rb +1 -1
- data/test/factory_girl_test.rb +7 -0
- metadata +1 -1
data/lib/factory_girl/factory.rb
CHANGED
@@ -13,6 +13,7 @@ class Factory
|
|
13
13
|
# existing file will be loaded.
|
14
14
|
attr_accessor :definition_file_paths
|
15
15
|
attr_accessor :live_registry
|
16
|
+
attr_accessor :use_find_or_create
|
16
17
|
end
|
17
18
|
|
18
19
|
self.factories = {}
|
@@ -257,7 +258,11 @@ class Factory
|
|
257
258
|
# A saved instance of the class this factory generates, with generated
|
258
259
|
# attributes assigned.
|
259
260
|
def self.create (name, overrides = {})
|
260
|
-
factory_by_name(name).run(Proxy::Create, overrides)
|
261
|
+
just_created = factory_by_name(name).run(Proxy::Create, overrides)
|
262
|
+
if !just_created.nil?
|
263
|
+
live_registry << [name, just_created.class.name, just_created.id]
|
264
|
+
end
|
265
|
+
just_created
|
261
266
|
end
|
262
267
|
|
263
268
|
def self.find_or_create (name, overrides = {})
|
@@ -271,7 +276,9 @@ class Factory
|
|
271
276
|
end
|
272
277
|
if just_created.nil?
|
273
278
|
just_created = factory_by_name(name).run(Proxy::FindOrCreate, overrides)
|
274
|
-
|
279
|
+
if !just_created.nil?
|
280
|
+
live_registry << [name, just_created.class.name, just_created.id]
|
281
|
+
end
|
275
282
|
end
|
276
283
|
just_created
|
277
284
|
end
|
data/lib/factory_girl/proxy.rb
CHANGED
data/test/factory_girl_test.rb
CHANGED
@@ -16,6 +16,13 @@ class FactoryGirlTest < Test::Unit::TestCase
|
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_should_link_instead_of_associate
|
20
|
+
|
21
|
+
john = Factory.create(:john)
|
22
|
+
post = Factory.create(:johns_post)
|
23
|
+
# post = Factory.create(:johns_post)
|
24
|
+
end
|
25
|
+
|
19
26
|
def setup
|
20
27
|
teardown
|
21
28
|
end
|