factory_girl 2.5.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.travis.yml +0 -1
  2. data/Changelog +6 -0
  3. data/GETTING_STARTED.md +52 -7
  4. data/Gemfile.lock +1 -1
  5. data/gemfiles/2.3.gemfile.lock +1 -1
  6. data/gemfiles/3.0.gemfile.lock +1 -1
  7. data/gemfiles/3.1.gemfile.lock +1 -1
  8. data/gemfiles/3.2.gemfile.lock +1 -1
  9. data/lib/factory_girl.rb +2 -1
  10. data/lib/factory_girl/association_runner.rb +50 -0
  11. data/lib/factory_girl/definition_proxy.rb +1 -1
  12. data/lib/factory_girl/evaluator.rb +12 -1
  13. data/lib/factory_girl/factory.rb +5 -5
  14. data/lib/factory_girl/strategy.rb +32 -0
  15. data/lib/factory_girl/{proxy → strategy}/attributes_for.rb +5 -2
  16. data/lib/factory_girl/strategy/build.rb +15 -0
  17. data/lib/factory_girl/{proxy → strategy}/create.rb +6 -2
  18. data/lib/factory_girl/{proxy → strategy}/stub.rb +4 -5
  19. data/lib/factory_girl/syntax/generate.rb +3 -3
  20. data/lib/factory_girl/syntax/make.rb +2 -2
  21. data/lib/factory_girl/syntax/methods.rb +6 -6
  22. data/lib/factory_girl/version.rb +1 -1
  23. data/spec/acceptance/build_spec.rb +2 -2
  24. data/spec/acceptance/create_list_spec.rb +41 -0
  25. data/spec/acceptance/create_spec.rb +39 -10
  26. data/spec/acceptance/stub_spec.rb +40 -13
  27. data/spec/acceptance/syntax/vintage_spec.rb +10 -10
  28. data/spec/acceptance/traits_spec.rb +1 -1
  29. data/spec/acceptance/transient_attributes_spec.rb +2 -2
  30. data/spec/factory_girl/association_runner_spec.rb +31 -0
  31. data/spec/factory_girl/attribute/association_spec.rb +0 -1
  32. data/spec/factory_girl/attribute_spec.rb +0 -1
  33. data/spec/factory_girl/declaration/implicit_spec.rb +0 -1
  34. data/spec/factory_girl/factory_spec.rb +16 -16
  35. data/spec/factory_girl/{proxy → strategy}/attributes_for_spec.rb +2 -2
  36. data/spec/factory_girl/strategy/build_spec.rb +7 -0
  37. data/spec/factory_girl/{proxy → strategy}/create_spec.rb +3 -3
  38. data/spec/factory_girl/{proxy → strategy}/stub_spec.rb +4 -4
  39. data/spec/factory_girl/strategy_spec.rb +21 -0
  40. data/spec/support/shared_examples/strategy.rb +112 -0
  41. metadata +47 -48
  42. data/gemfiles/2.1.gemfile +0 -8
  43. data/gemfiles/2.1.gemfile.lock +0 -74
  44. data/lib/factory_girl/proxy.rb +0 -64
  45. data/lib/factory_girl/proxy/build.rb +0 -27
  46. data/spec/factory_girl/proxy/build_spec.rb +0 -7
  47. data/spec/factory_girl/proxy_spec.rb +0 -19
  48. data/spec/support/shared_examples/proxy.rb +0 -90
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe FactoryGirl::Strategy::Build do
4
+ it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create
5
+ it_should_behave_like "strategy with callbacks", :after_build
6
+ it_should_behave_like "strategy with :strategy => :build", FactoryGirl::Strategy::Build
7
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FactoryGirl::Proxy::Create do
4
- it_should_behave_like "proxy with association support", FactoryGirl::Proxy::Create
5
- it_should_behave_like "proxy with callbacks", :after_build, :after_create
3
+ describe FactoryGirl::Strategy::Create do
4
+ it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create
5
+ it_should_behave_like "strategy with callbacks", :after_build, :after_create
6
6
 
7
7
  it "runs a custom create block" do
8
8
  block_run = false
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FactoryGirl::Proxy::Stub do
4
- it_should_behave_like "proxy with association support", FactoryGirl::Proxy::Stub
5
- it_should_behave_like "proxy with callbacks", :after_stub
6
- it_should_behave_like "proxy with :method => :build", FactoryGirl::Proxy::Stub
3
+ describe FactoryGirl::Strategy::Stub do
4
+ it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Stub
5
+ it_should_behave_like "strategy with callbacks", :after_stub
6
+ it_should_behave_like "strategy with :strategy => :build", FactoryGirl::Strategy::Stub
7
7
 
8
8
  context "asking for a result" do
9
9
  before { Timecop.freeze(Time.now) }
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Strategy do
4
+ it "raises an error when asking for the result" do
5
+ expect { subject.result(stub("assigner"), lambda {|instance| instance }) }.to raise_error(NotImplementedError, "Strategies must return a result")
6
+ end
7
+
8
+ it "raises an error when asking for the association" do
9
+ expect { subject.association(stub("runner")) }.to raise_error(NotImplementedError, "Strategies must return an association")
10
+ end
11
+ end
12
+
13
+ describe FactoryGirl::Strategy, ".ensure_strategy_exists!" do
14
+ it "raises when passed a nonexistent strategy" do
15
+ expect { FactoryGirl::Strategy.ensure_strategy_exists!(:nonexistent) }.to raise_error(ArgumentError, "Unknown strategy: nonexistent")
16
+ end
17
+
18
+ it "doesn't raise when passed a valid strategy" do
19
+ expect { FactoryGirl::Strategy.ensure_strategy_exists!(:create) }.to_not raise_error
20
+ end
21
+ end
@@ -0,0 +1,112 @@
1
+ shared_examples_for "strategy without association support" do
2
+ let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
3
+
4
+ def association_named(name, overrides)
5
+ runner = FactoryGirl::AssociationRunner.new(name, :build, overrides)
6
+ subject.association(runner)
7
+ end
8
+
9
+ it "returns nil when accessing an association" do
10
+ association_named(:user, {}).should be_nil
11
+ end
12
+
13
+ it "does not attempt to look up the factory when accessing the association" do
14
+ FactoryGirl.stubs(:factory_by_name)
15
+ association_named(:awesome, {})
16
+ FactoryGirl.should have_received(:factory_by_name).never
17
+ end
18
+ end
19
+
20
+ shared_examples_for "strategy with association support" do |factory_girl_strategy_class|
21
+ let(:factory) { stub("associate_factory") }
22
+
23
+ def association_named(name, strategy, overrides)
24
+ runner = FactoryGirl::AssociationRunner.new(name, strategy, overrides)
25
+ subject.association(runner)
26
+ end
27
+
28
+ before do
29
+ FactoryGirl.stubs(:factory_by_name => factory)
30
+ factory.stubs(:run)
31
+ end
32
+
33
+ it "runs the factory with the correct overrides" do
34
+ association_named(:author, factory_girl_strategy_class, :great => "value")
35
+ factory.should have_received(:run).with(factory_girl_strategy_class, :great => "value")
36
+ end
37
+
38
+ it "finds the factory with the correct factory name" do
39
+ association_named(:author, factory_girl_strategy_class, :great => "value")
40
+ FactoryGirl.should have_received(:factory_by_name).with(:author)
41
+ end
42
+ end
43
+
44
+ shared_examples_for "strategy with :strategy => :build" do |factory_girl_strategy_class|
45
+ let(:factory) { stub("associate_factory") }
46
+
47
+ def association_named(name, overrides)
48
+ strategy = overrides[:strategy] || overrides[:method]
49
+ runner = FactoryGirl::AssociationRunner.new(name, strategy, overrides.except(:strategy, :method))
50
+ subject.association(runner)
51
+ end
52
+
53
+ before do
54
+ FactoryGirl.stubs(:factory_by_name => factory)
55
+ factory.stubs(:run)
56
+ end
57
+
58
+ it "runs the factory with the correct overrides" do
59
+ association_named(:author, :strategy => :build, :great => "value")
60
+ factory.should have_received(:run).with(factory_girl_strategy_class, { :great => "value" })
61
+ end
62
+
63
+ it "finds the factory with the correct factory name" do
64
+ association_named(:author, :strategy => :build, :great => "value")
65
+ FactoryGirl.should have_received(:factory_by_name).with(:author)
66
+ end
67
+
68
+ it "runs the factory with the correct overrides with :method" do
69
+ association_named(:author, :method => :build, :great => "value")
70
+ factory.should have_received(:run).with(factory_girl_strategy_class, { :great => "value" })
71
+ end
72
+
73
+ it "finds the factory with the correct factory name with :method" do
74
+ association_named(:author, :method => :build, :great => "value")
75
+ FactoryGirl.should have_received(:factory_by_name).with(:author)
76
+ end
77
+ end
78
+
79
+ shared_examples_for "strategy with callbacks" do |*callback_names|
80
+ let(:callback_observer) do
81
+ define_class("CallbackObserver") do
82
+ attr_reader :callbacks_called
83
+
84
+ def initialize
85
+ @callbacks_called = []
86
+ end
87
+
88
+ def update(callback_name, assigner)
89
+ @callbacks_called << [callback_name, assigner]
90
+ end
91
+ end.new
92
+ end
93
+
94
+ let(:result_instance) do
95
+ define_class("ResultInstance") do
96
+ attr_accessor :id
97
+ end.new
98
+ end
99
+
100
+ let(:assigner) { stub("attribute assigner", :object => result_instance) }
101
+
102
+ before { subject.add_observer(callback_observer) }
103
+
104
+ it "runs the callbacks #{callback_names} with the assigner's object" do
105
+ subject.result(assigner, lambda {|instance| instance })
106
+ callback_observer.callbacks_called.should == callback_names.map {|name| [name, assigner.object] }
107
+ end
108
+
109
+ it "returns the object from the assigner" do
110
+ subject.result(assigner, lambda {|instance| instance }).should == assigner.object
111
+ end
112
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.6.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-02-10 00:00:00.000000000 Z
12
+ date: 2012-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70105304973080 !ruby/object:Gem::Requirement
16
+ requirement: &70097037615520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70105304973080
24
+ version_requirements: *70097037615520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70105304972240 !ruby/object:Gem::Requirement
27
+ requirement: &70097037615000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70105304972240
35
+ version_requirements: *70097037615000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &70105304971500 !ruby/object:Gem::Requirement
38
+ requirement: &70097037614460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70105304971500
46
+ version_requirements: *70097037614460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: timecop
49
- requirement: &70105304971040 !ruby/object:Gem::Requirement
49
+ requirement: &70097037614020 !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: *70105304971040
57
+ version_requirements: *70097037614020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70105304970440 !ruby/object:Gem::Requirement
60
+ requirement: &70097037613320 !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: *70105304970440
68
+ version_requirements: *70097037613320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: aruba
71
- requirement: &70105304969860 !ruby/object:Gem::Requirement
71
+ requirement: &70097037612640 !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: *70105304969860
79
+ version_requirements: *70097037612640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: mocha
82
- requirement: &70105304969160 !ruby/object:Gem::Requirement
82
+ requirement: &70097037611900 !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: *70105304969160
90
+ version_requirements: *70097037611900
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: bourne
93
- requirement: &70105304968440 !ruby/object:Gem::Requirement
93
+ requirement: &70097037611440 !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: *70105304968440
101
+ version_requirements: *70097037611440
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: appraisal
104
- requirement: &70105304967680 !ruby/object:Gem::Requirement
104
+ requirement: &70097037610900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.3.8
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70105304967680
112
+ version_requirements: *70097037610900
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sqlite3-ruby
115
- requirement: &70105304967200 !ruby/object:Gem::Requirement
115
+ requirement: &70097037610400 !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: *70105304967200
123
+ version_requirements: *70097037610400
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: yard
126
- requirement: &70105304966580 !ruby/object:Gem::Requirement
126
+ requirement: &70097037609600 !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: *70105304966580
134
+ version_requirements: *70097037609600
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: bluecloth
137
- requirement: &70105304966000 !ruby/object:Gem::Requirement
137
+ requirement: &70097037608540 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70105304966000
145
+ version_requirements: *70097037608540
146
146
  description: ! "factory_girl provides a framework and DSL for defining and\n using
147
147
  factories - less error-prone, more explicit, and\n all-around
148
148
  easier to work with than fixtures."
@@ -173,8 +173,6 @@ files:
173
173
  - features/step_definitions/factory_girl_steps.rb
174
174
  - features/support/env.rb
175
175
  - features/support/factories.rb
176
- - gemfiles/2.1.gemfile
177
- - gemfiles/2.1.gemfile.lock
178
176
  - gemfiles/2.3.gemfile
179
177
  - gemfiles/2.3.gemfile.lock
180
178
  - gemfiles/3.0.gemfile
@@ -185,6 +183,7 @@ files:
185
183
  - gemfiles/3.2.gemfile.lock
186
184
  - lib/factory_girl.rb
187
185
  - lib/factory_girl/aliases.rb
186
+ - lib/factory_girl/association_runner.rb
188
187
  - lib/factory_girl/attribute.rb
189
188
  - lib/factory_girl/attribute/association.rb
190
189
  - lib/factory_girl/attribute/dynamic.rb
@@ -209,16 +208,16 @@ files:
209
208
  - lib/factory_girl/find_definitions.rb
210
209
  - lib/factory_girl/null_factory.rb
211
210
  - lib/factory_girl/null_object.rb
212
- - lib/factory_girl/proxy.rb
213
- - lib/factory_girl/proxy/attributes_for.rb
214
- - lib/factory_girl/proxy/build.rb
215
- - lib/factory_girl/proxy/create.rb
216
- - lib/factory_girl/proxy/stub.rb
217
211
  - lib/factory_girl/rails2.rb
218
212
  - lib/factory_girl/registry.rb
219
213
  - lib/factory_girl/reload.rb
220
214
  - lib/factory_girl/sequence.rb
221
215
  - lib/factory_girl/step_definitions.rb
216
+ - lib/factory_girl/strategy.rb
217
+ - lib/factory_girl/strategy/attributes_for.rb
218
+ - lib/factory_girl/strategy/build.rb
219
+ - lib/factory_girl/strategy/create.rb
220
+ - lib/factory_girl/strategy/stub.rb
222
221
  - lib/factory_girl/syntax.rb
223
222
  - lib/factory_girl/syntax/blueprint.rb
224
223
  - lib/factory_girl/syntax/default.rb
@@ -260,6 +259,7 @@ files:
260
259
  - spec/acceptance/traits_spec.rb
261
260
  - spec/acceptance/transient_attributes_spec.rb
262
261
  - spec/factory_girl/aliases_spec.rb
262
+ - spec/factory_girl/association_runner_spec.rb
263
263
  - spec/factory_girl/attribute/association_spec.rb
264
264
  - spec/factory_girl/attribute/dynamic_spec.rb
265
265
  - spec/factory_girl/attribute/sequence_spec.rb
@@ -277,13 +277,13 @@ files:
277
277
  - spec/factory_girl/find_definitions_spec.rb
278
278
  - spec/factory_girl/null_factory_spec.rb
279
279
  - spec/factory_girl/null_object_spec.rb
280
- - spec/factory_girl/proxy/attributes_for_spec.rb
281
- - spec/factory_girl/proxy/build_spec.rb
282
- - spec/factory_girl/proxy/create_spec.rb
283
- - spec/factory_girl/proxy/stub_spec.rb
284
- - spec/factory_girl/proxy_spec.rb
285
280
  - spec/factory_girl/registry_spec.rb
286
281
  - spec/factory_girl/sequence_spec.rb
282
+ - spec/factory_girl/strategy/attributes_for_spec.rb
283
+ - spec/factory_girl/strategy/build_spec.rb
284
+ - spec/factory_girl/strategy/create_spec.rb
285
+ - spec/factory_girl/strategy/stub_spec.rb
286
+ - spec/factory_girl/strategy_spec.rb
287
287
  - spec/factory_girl_spec.rb
288
288
  - spec/spec_helper.rb
289
289
  - spec/support/macros/define_constant.rb
@@ -291,7 +291,7 @@ files:
291
291
  - spec/support/matchers/declaration.rb
292
292
  - spec/support/matchers/delegate.rb
293
293
  - spec/support/matchers/trait.rb
294
- - spec/support/shared_examples/proxy.rb
294
+ - spec/support/shared_examples/strategy.rb
295
295
  homepage: https://github.com/thoughtbot/factory_girl
296
296
  licenses: []
297
297
  post_install_message:
@@ -312,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  version: '0'
313
313
  requirements: []
314
314
  rubyforge_project:
315
- rubygems_version: 1.8.15
315
+ rubygems_version: 1.8.16
316
316
  signing_key:
317
317
  specification_version: 3
318
318
  summary: factory_girl provides a framework and DSL for defining and using model instance
@@ -325,8 +325,6 @@ test_files:
325
325
  - features/step_definitions/factory_girl_steps.rb
326
326
  - features/support/env.rb
327
327
  - features/support/factories.rb
328
- - gemfiles/2.1.gemfile
329
- - gemfiles/2.1.gemfile.lock
330
328
  - gemfiles/2.3.gemfile
331
329
  - gemfiles/2.3.gemfile.lock
332
330
  - gemfiles/3.0.gemfile
@@ -366,6 +364,7 @@ test_files:
366
364
  - spec/acceptance/traits_spec.rb
367
365
  - spec/acceptance/transient_attributes_spec.rb
368
366
  - spec/factory_girl/aliases_spec.rb
367
+ - spec/factory_girl/association_runner_spec.rb
369
368
  - spec/factory_girl/attribute/association_spec.rb
370
369
  - spec/factory_girl/attribute/dynamic_spec.rb
371
370
  - spec/factory_girl/attribute/sequence_spec.rb
@@ -383,13 +382,13 @@ test_files:
383
382
  - spec/factory_girl/find_definitions_spec.rb
384
383
  - spec/factory_girl/null_factory_spec.rb
385
384
  - spec/factory_girl/null_object_spec.rb
386
- - spec/factory_girl/proxy/attributes_for_spec.rb
387
- - spec/factory_girl/proxy/build_spec.rb
388
- - spec/factory_girl/proxy/create_spec.rb
389
- - spec/factory_girl/proxy/stub_spec.rb
390
- - spec/factory_girl/proxy_spec.rb
391
385
  - spec/factory_girl/registry_spec.rb
392
386
  - spec/factory_girl/sequence_spec.rb
387
+ - spec/factory_girl/strategy/attributes_for_spec.rb
388
+ - spec/factory_girl/strategy/build_spec.rb
389
+ - spec/factory_girl/strategy/create_spec.rb
390
+ - spec/factory_girl/strategy/stub_spec.rb
391
+ - spec/factory_girl/strategy_spec.rb
393
392
  - spec/factory_girl_spec.rb
394
393
  - spec/spec_helper.rb
395
394
  - spec/support/macros/define_constant.rb
@@ -397,5 +396,5 @@ test_files:
397
396
  - spec/support/matchers/declaration.rb
398
397
  - spec/support/matchers/delegate.rb
399
398
  - spec/support/matchers/trait.rb
400
- - spec/support/shared_examples/proxy.rb
399
+ - spec/support/shared_examples/strategy.rb
401
400
  has_rdoc: