factory_girl 2.5.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals CHANGED
@@ -1,8 +1,3 @@
1
- appraise "2.1" do
2
- gem "test-unit", "~> 2.3.0", :platforms => [:mri_19]
3
- gem "activerecord", "~> 2.1"
4
- end
5
-
6
1
  appraise "2.3" do
7
2
  gem "activerecord", "~> 2.3"
8
3
  end
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ 2.5.2 (February 10, 2012)
2
+ Fix step definitions to use associations defined in parent factories
3
+ Add inline trait support to (build|create)_list
4
+ Update ActiveSupport dependency to >= 2.3.9, which introduced
5
+ class_attribute
6
+
1
7
  2.5.1 (February 3, 2012)
2
8
  Fix attribute evaluation when the attribute isn't defined in the factory but
3
9
  is a private method on Object
data/GETTING_STARTED.md CHANGED
@@ -480,6 +480,24 @@ FactoryGirl.create(:user, :admin, :male, :name => "Jon Snow")
480
480
 
481
481
  This ability works with `build`, `build_stubbed`, `attributes_for`, and `create`.
482
482
 
483
+ `create_list` and `build_list` methods are supported as well. Just remember to pass
484
+ the number of instances to create/build as second parameter, as documented in the
485
+ "Building or Creating Multiple Records" section of this file.
486
+
487
+ ```ruby
488
+ factory :user do
489
+ name "Friendly User"
490
+
491
+ trait :admin do
492
+ admin true
493
+ end
494
+ end
495
+
496
+ # creates 3 admin users with gender "Male" and name "Jon Snow"
497
+ FactoryGirl.create_list(:user, 3, :admin, :male, :name => "Jon Snow")
498
+ ```
499
+
500
+
483
501
  Callbacks
484
502
  ---------
485
503
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (2.5.1)
5
- activesupport
4
+ factory_girl (2.5.2)
5
+ activesupport (>= 2.3.9)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH << File.expand_path("../lib", __FILE__)
2
+ require 'factory_girl/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = %q{factory_girl}
6
+ s.version = FactoryGirl::VERSION
7
+ s.summary = %q{factory_girl provides a framework and DSL for defining and
8
+ using model instance factories.}
9
+ s.description = %q{factory_girl provides a framework and DSL for defining and
10
+ using factories - less error-prone, more explicit, and
11
+ all-around easier to work with than fixtures.}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- Appraisals {spec,features,gemfiles}/*`.split("\n")
15
+
16
+ s.require_paths = ['lib']
17
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
18
+
19
+ s.authors = ["Joe Ferris"]
20
+ s.email = %q{jferris@thoughtbot.com}
21
+ s.homepage = "https://github.com/thoughtbot/factory_girl"
22
+
23
+ s.add_dependency("activesupport", ">= 2.3.9")
24
+
25
+ s.add_development_dependency("rspec", "~> 2.0")
26
+ s.add_development_dependency("cucumber", "~> 1.0.0")
27
+ s.add_development_dependency("timecop")
28
+ s.add_development_dependency("rcov")
29
+ s.add_development_dependency("aruba")
30
+ s.add_development_dependency("mocha")
31
+ s.add_development_dependency("bourne")
32
+ s.add_development_dependency("appraisal", "~> 0.3.8")
33
+ s.add_development_dependency("sqlite3-ruby")
34
+ s.add_development_dependency("yard")
35
+ s.add_development_dependency("bluecloth")
36
+ end
37
+
@@ -60,6 +60,14 @@ Feature: Use step definitions generated by factories
60
60
  | a title | 123 |
61
61
  And there should be 1 user
62
62
 
63
+ Scenario: create a titled post with a new author (inherited association)
64
+ Given the following titled post exists:
65
+ | Title | Author |
66
+ | A Post with a Title | ID: 123 |
67
+ Then I should find the following for the last post:
68
+ | title | author_id |
69
+ | A Post with a Title | 123 |
70
+
63
71
  Scenario: create post with and without a category association
64
72
  Given the following users exist:
65
73
  | ID | Name |
@@ -99,6 +99,10 @@ FactoryGirl.define do
99
99
  category
100
100
  end
101
101
 
102
+ factory :titled_post, :parent => :post do
103
+ title 'A Post with a Title'
104
+ end
105
+
102
106
  factory :tag do
103
107
  post
104
108
  end
@@ -2,7 +2,7 @@ PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
4
  factory_girl (2.5.1)
5
- activesupport
5
+ activesupport (>= 2.3.9)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.5.1)
5
- activesupport
4
+ factory_girl (2.5.2)
5
+ activesupport (>= 2.3.9)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.5.1)
5
- activesupport
4
+ factory_girl (2.5.2)
5
+ activesupport (>= 2.3.9)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.5.1)
5
- activesupport
4
+ factory_girl (2.5.2)
5
+ activesupport (>= 2.3.9)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (2.5.1)
5
- activesupport
4
+ factory_girl (2.5.2)
5
+ activesupport (>= 2.3.9)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
data/lib/factory_girl.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "active_support/core_ext/module/delegation"
2
2
 
3
+ require 'factory_girl/errors'
3
4
  require 'factory_girl/proxy'
4
5
  require 'factory_girl/registry'
5
6
  require 'factory_girl/null_factory'
@@ -29,24 +30,6 @@ if defined?(Rails) && Rails::VERSION::MAJOR == 2
29
30
  end
30
31
 
31
32
  module FactoryGirl
32
- # Raised when a factory is defined that attempts to instantiate itself.
33
- class AssociationDefinitionError < RuntimeError; end
34
-
35
- # Raised when a callback is defined that has an invalid name
36
- class InvalidCallbackNameError < RuntimeError; end
37
-
38
- # Raised when a factory is defined with the same name as a previously-defined factory.
39
- class DuplicateDefinitionError < RuntimeError; end
40
-
41
- # Raised when calling Factory.sequence from a dynamic attribute block
42
- class SequenceAbuseError < RuntimeError; end
43
-
44
- # Raised when defining an invalid attribute:
45
- # * Defining an attribute which has a name ending in "="
46
- # * Defining an attribute with both a static and lazy value
47
- # * Defining an attribute twice in the same factory
48
- class AttributeDefinitionError < RuntimeError; end
49
-
50
33
  def self.factories
51
34
  @factories ||= Registry.new("Factory")
52
35
  end
@@ -0,0 +1,19 @@
1
+ module FactoryGirl
2
+ # Raised when a factory is defined that attempts to instantiate itself.
3
+ class AssociationDefinitionError < RuntimeError; end
4
+
5
+ # Raised when a callback is defined that has an invalid name
6
+ class InvalidCallbackNameError < RuntimeError; end
7
+
8
+ # Raised when a factory is defined with the same name as a previously-defined factory.
9
+ class DuplicateDefinitionError < RuntimeError; end
10
+
11
+ # Raised when calling Factory.sequence from a dynamic attribute block
12
+ class SequenceAbuseError < RuntimeError; end
13
+
14
+ # Raised when defining an invalid attribute:
15
+ # * Defining an attribute which has a name ending in "="
16
+ # * Defining an attribute with both a static and lazy value
17
+ # * Defining an attribute twice in the same factory
18
+ class AttributeDefinitionError < RuntimeError; end
19
+ end
@@ -53,7 +53,7 @@ module FactoryGirl
53
53
  end
54
54
 
55
55
  def associations
56
- attributes.associations
56
+ evaluator_class.attribute_list.associations
57
57
  end
58
58
 
59
59
  # Names for this factory, including aliases.
@@ -90,14 +90,15 @@ module FactoryGirl
90
90
  # The name of the factory to be used.
91
91
  # * amount: +Integer+
92
92
  # number of instances to be built.
93
- # * overrides: +Hash+
94
- # Attributes to overwrite for each instance.
93
+ # * traits_and_overrides: +Array+
94
+ # [+*Array+] Traits to be applied
95
+ # [+Hash+] Attributes to overwrite for this instance.
95
96
  #
96
97
  # Returns: +Array+
97
98
  # An array of instances of the class this factory generates, with generated attributes
98
99
  # assigned.
99
- def build_list(name, amount, overrides = {})
100
- amount.times.map { build(name, overrides) }
100
+ def build_list(name, amount, *traits_and_overrides)
101
+ amount.times.map { build(name, *traits_and_overrides) }
101
102
  end
102
103
 
103
104
  # Creates and returns multiple instances from this factory as an array. Attributes can be
@@ -108,14 +109,15 @@ module FactoryGirl
108
109
  # The name of the factory to be used.
109
110
  # * amount: +Integer+
110
111
  # number of instances to be created.
111
- # * overrides: +Hash+
112
- # Attributes to overwrite for each instance.
112
+ # * traits_and_overrides: +Array+
113
+ # [+*Array+] Traits to be applied
114
+ # [+Hash+] Attributes to overwrite for this instance.
113
115
  #
114
116
  # Returns: +Array+
115
117
  # An array of instances of the class this factory generates, with generated attributes
116
118
  # assigned.
117
- def create_list(name, amount, overrides = {})
118
- amount.times.map { create(name, overrides) }
119
+ def create_list(name, amount, *traits_and_overrides)
120
+ amount.times.map { create(name, *traits_and_overrides) }
119
121
  end
120
122
 
121
123
  # Generates and returns the next value in a sequence.
@@ -1,4 +1,4 @@
1
1
  module FactoryGirl
2
- VERSION = "2.5.1"
2
+ VERSION = "2.5.2"
3
3
  end
4
4
 
@@ -262,6 +262,32 @@ describe "traits added via proxy" do
262
262
  its(:admin) { should be_true }
263
263
  its(:name) { should == "Jack" }
264
264
  end
265
+
266
+ context "adding traits in create_list" do
267
+ subject { FactoryGirl.create_list(:user, 2, :admin, :great, :name => "Joe") }
268
+
269
+ its(:length) { should == 2 }
270
+
271
+ it "creates all the records" do
272
+ subject.each do |record|
273
+ record.admin.should be_true
274
+ record.name.should == "JOE"
275
+ end
276
+ end
277
+ end
278
+
279
+ context "adding traits in build_list" do
280
+ subject { FactoryGirl.build_list(:user, 2, :admin, :great, :name => "Joe") }
281
+
282
+ its(:length) { should == 2 }
283
+
284
+ it "builds all the records" do
285
+ subject.each do |record|
286
+ record.admin.should be_true
287
+ record.name.should == "Joe"
288
+ end
289
+ end
290
+ end
265
291
  end
266
292
 
267
293
  describe "traits and dynamic attributes that are applied simultaneously" do
@@ -48,6 +48,20 @@ describe FactoryGirl::Factory do
48
48
  factory.associations.size.should == 3
49
49
  end
50
50
 
51
+ it "includes associations from the parent factory" do
52
+ association_on_parent = FactoryGirl::Declaration::Association.new(:association_on_parent, {})
53
+ association_on_child = FactoryGirl::Declaration::Association.new(:association_on_child, {})
54
+
55
+ factory = FactoryGirl::Factory.new(:post)
56
+ factory.declare_attribute(association_on_parent)
57
+ FactoryGirl.register_factory(factory)
58
+
59
+ child_factory = FactoryGirl::Factory.new(:child_post, :parent => :post)
60
+ child_factory.declare_attribute(association_on_child)
61
+
62
+ child_factory.associations.map(&:name).should == [:association_on_parent, :association_on_child]
63
+ end
64
+
51
65
  describe "when overriding generated attributes with a hash" do
52
66
  before do
53
67
  @name = :name
@@ -21,7 +21,7 @@ RSpec::Matchers.define :delegate do |delegated_method|
21
21
  stubbed_target = stub('stubbed_target', method_on_target => return_value)
22
22
  @instance.stubs(@target_method => stubbed_target)
23
23
  begin
24
- @instance.send(delegated_method, *@args).should == return_value
24
+ @instance.send(delegated_method, *@args) == return_value
25
25
  rescue NoMethodError
26
26
  false
27
27
  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.1
4
+ version: 2.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-03 00:00:00.000000000 Z
12
+ date: 2012-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70093884307140 !ruby/object:Gem::Requirement
16
+ requirement: &70105304973080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 2.3.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70093884307140
24
+ version_requirements: *70105304973080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70093884306400 !ruby/object:Gem::Requirement
27
+ requirement: &70105304972240 !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: *70093884306400
35
+ version_requirements: *70105304972240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &70093884305300 !ruby/object:Gem::Requirement
38
+ requirement: &70105304971500 !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: *70093884305300
46
+ version_requirements: *70105304971500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: timecop
49
- requirement: &70093884304160 !ruby/object:Gem::Requirement
49
+ requirement: &70105304971040 !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: *70093884304160
57
+ version_requirements: *70105304971040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70093884302020 !ruby/object:Gem::Requirement
60
+ requirement: &70105304970440 !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: *70093884302020
68
+ version_requirements: *70105304970440
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: aruba
71
- requirement: &70093884285960 !ruby/object:Gem::Requirement
71
+ requirement: &70105304969860 !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: *70093884285960
79
+ version_requirements: *70105304969860
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: mocha
82
- requirement: &70093884291240 !ruby/object:Gem::Requirement
82
+ requirement: &70105304969160 !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: *70093884291240
90
+ version_requirements: *70105304969160
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: bourne
93
- requirement: &70093884290600 !ruby/object:Gem::Requirement
93
+ requirement: &70105304968440 !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: *70093884290600
101
+ version_requirements: *70105304968440
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: appraisal
104
- requirement: &70093884288880 !ruby/object:Gem::Requirement
104
+ requirement: &70105304967680 !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: *70093884288880
112
+ version_requirements: *70105304967680
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sqlite3-ruby
115
- requirement: &70093884288420 !ruby/object:Gem::Requirement
115
+ requirement: &70105304967200 !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: *70093884288420
123
+ version_requirements: *70105304967200
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: yard
126
- requirement: &70093884287780 !ruby/object:Gem::Requirement
126
+ requirement: &70105304966580 !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: *70093884287780
134
+ version_requirements: *70105304966580
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: bluecloth
137
- requirement: &70093884286820 !ruby/object:Gem::Requirement
137
+ requirement: &70105304966000 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,9 +142,9 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70093884286820
146
- description: ! "factory_girl provides a framework and DSL for defining and\n using
147
- factories - less error-prone, more explicit, and\n all-around
145
+ version_requirements: *70105304966000
146
+ description: ! "factory_girl provides a framework and DSL for defining and\n using
147
+ factories - less error-prone, more explicit, and\n all-around
148
148
  easier to work with than fixtures."
149
149
  email: jferris@thoughtbot.com
150
150
  executables: []
@@ -156,6 +156,7 @@ files:
156
156
  - .rspec
157
157
  - .travis.yml
158
158
  - .yardopts
159
+ - Appraisals
159
160
  - CONTRIBUTION_GUIDELINES.md
160
161
  - Changelog
161
162
  - GETTING_STARTED.md
@@ -164,6 +165,24 @@ files:
164
165
  - LICENSE
165
166
  - README.md
166
167
  - Rakefile
168
+ - cucumber.yml
169
+ - factory_girl.gemspec
170
+ - features/factory_girl_steps.feature
171
+ - features/find_definitions.feature
172
+ - features/step_definitions/database_steps.rb
173
+ - features/step_definitions/factory_girl_steps.rb
174
+ - features/support/env.rb
175
+ - features/support/factories.rb
176
+ - gemfiles/2.1.gemfile
177
+ - gemfiles/2.1.gemfile.lock
178
+ - gemfiles/2.3.gemfile
179
+ - gemfiles/2.3.gemfile.lock
180
+ - gemfiles/3.0.gemfile
181
+ - gemfiles/3.0.gemfile.lock
182
+ - gemfiles/3.1.gemfile
183
+ - gemfiles/3.1.gemfile.lock
184
+ - gemfiles/3.2.gemfile
185
+ - gemfiles/3.2.gemfile.lock
167
186
  - lib/factory_girl.rb
168
187
  - lib/factory_girl/aliases.rb
169
188
  - lib/factory_girl/attribute.rb
@@ -183,6 +202,7 @@ files:
183
202
  - lib/factory_girl/definition.rb
184
203
  - lib/factory_girl/definition_proxy.rb
185
204
  - lib/factory_girl/deprecated.rb
205
+ - lib/factory_girl/errors.rb
186
206
  - lib/factory_girl/evaluator.rb
187
207
  - lib/factory_girl/evaluator_class_definer.rb
188
208
  - lib/factory_girl/factory.rb
@@ -209,24 +229,6 @@ files:
209
229
  - lib/factory_girl/syntax/vintage.rb
210
230
  - lib/factory_girl/trait.rb
211
231
  - lib/factory_girl/version.rb
212
- - Appraisals
213
- - cucumber.yml
214
- - features/factory_girl_steps.feature
215
- - features/find_definitions.feature
216
- - features/step_definitions/database_steps.rb
217
- - features/step_definitions/factory_girl_steps.rb
218
- - features/support/env.rb
219
- - features/support/factories.rb
220
- - gemfiles/2.1.gemfile
221
- - gemfiles/2.1.gemfile.lock
222
- - gemfiles/2.3.gemfile
223
- - gemfiles/2.3.gemfile.lock
224
- - gemfiles/3.0.gemfile
225
- - gemfiles/3.0.gemfile.lock
226
- - gemfiles/3.1.gemfile
227
- - gemfiles/3.1.gemfile.lock
228
- - gemfiles/3.2.gemfile
229
- - gemfiles/3.2.gemfile.lock
230
232
  - spec/acceptance/aliases_spec.rb
231
233
  - spec/acceptance/attribute_aliases_spec.rb
232
234
  - spec/acceptance/attribute_existing_on_object_spec.rb
@@ -317,7 +319,6 @@ summary: factory_girl provides a framework and DSL for defining and using model
317
319
  factories.
318
320
  test_files:
319
321
  - Appraisals
320
- - cucumber.yml
321
322
  - features/factory_girl_steps.feature
322
323
  - features/find_definitions.feature
323
324
  - features/step_definitions/database_steps.rb