factory_girl 3.0.0.rc1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,15 @@
1
+ 3.0.0 (March 23, 2012)
2
+ Deprecate the vintage syntax
3
+ Remove Rails 2.x support
4
+ Remove Ruby 1.8 support
5
+ Remove deprecated features, including default_strategy, factory_name,
6
+ :method for defining default strategy, ignore on individual attributes, and
7
+ interacting with Factory the way you would FactoryGirl
8
+
9
+ 2.6.4 (March 16, 2012)
10
+ Do not ignore names of transient attributes
11
+ Ensure attributes set on instance are calculated uniquely
12
+
1
13
  2.6.3 (March 9, 2012)
2
14
  Fix issue with traits not being present the first time a factory is accessed
3
15
  Update available Cucumber step definitions to not require a trialing colon
@@ -7,13 +7,13 @@ Update Your Gemfile
7
7
  If you're using Rails, you'll need to change the required version of `factory_girl_rails`:
8
8
 
9
9
  ```ruby
10
- gem "factory_girl_rails", "~> 1.2"
10
+ gem "factory_girl_rails", "~> 2.0"
11
11
  ```
12
12
 
13
13
  If you're *not* using Rails, you'll just have to change the required version of `factory_girl`:
14
14
 
15
15
  ```ruby
16
- gem "factory_girl", "~> 2.1.0"
16
+ gem "factory_girl", "~> 3.0"
17
17
  ```
18
18
 
19
19
  Once your Gemfile is updated, you'll want to update your bundle.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (3.0.0.rc1)
4
+ factory_girl (3.0.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
4
4
 
5
- If you want to use factory_girl with Rails 3, see
5
+ If you want to use factory_girl with Rails, see
6
6
  [factory_girl_rails](https://github.com/thoughtbot/factory_girl_rails).
7
7
 
8
8
  Documentation
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.0.0.rc1)
4
+ factory_girl (3.0.0)
5
5
  activesupport (>= 3.0.0)
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 (3.0.0.rc1)
4
+ factory_girl (3.0.0)
5
5
  activesupport (>= 3.0.0)
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 (3.0.0.rc1)
4
+ factory_girl (3.0.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -26,10 +26,6 @@ require 'factory_girl/find_definitions'
26
26
  require 'factory_girl/reload'
27
27
  require 'factory_girl/version'
28
28
 
29
- if defined?(Rails) && Rails::VERSION::MAJOR == 2
30
- require 'factory_girl/rails2'
31
- end
32
-
33
29
  module FactoryGirl
34
30
  def self.factories
35
31
  @factories ||= Registry.new("Factory")
@@ -37,7 +37,7 @@ module FactoryGirl
37
37
  end
38
38
 
39
39
  def attributes_to_set_on_instance
40
- attribute_names_to_assign - @attribute_names_assigned
40
+ (attribute_names_to_assign - @attribute_names_assigned).uniq
41
41
  end
42
42
 
43
43
  def attributes_to_set_on_hash
@@ -66,7 +66,7 @@ module FactoryGirl
66
66
 
67
67
  def alias_names_to_ignore
68
68
  @attribute_list.reject(&:ignored).map do |attribute|
69
- override_names.map {|override| attribute.name if attribute.alias_for?(override) && attribute.name != override }
69
+ override_names.map {|override| attribute.name if attribute.alias_for?(override) && attribute.name != override && !ignored_attribute_names.include?(override) }
70
70
  end.flatten.compact
71
71
  end
72
72
  end
@@ -4,12 +4,8 @@ module FactoryGirl
4
4
  @name = name
5
5
  @strategy = strategy
6
6
 
7
- @overrides = if traits_and_overrides.last.respond_to?(:has_key?)
8
- traits_and_overrides.pop
9
- else
10
- {}
11
- end
12
- @traits = traits_and_overrides
7
+ @overrides = traits_and_overrides.extract_options!
8
+ @traits = traits_and_overrides
13
9
  end
14
10
 
15
11
  def run(strategy_override = nil, &block)
@@ -1,4 +1,4 @@
1
1
  module FactoryGirl
2
- VERSION = "3.0.0.rc1"
2
+ VERSION = "3.0.0"
3
3
  end
4
4
 
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe "association assignment from nested attributes" do
4
+ before do
5
+ define_model("Post", title: :string) do
6
+ has_many :comments
7
+ accepts_nested_attributes_for :comments
8
+ end
9
+
10
+ define_model("Comment", post_id: :integer, body: :text) do
11
+ belongs_to :post
12
+ end
13
+
14
+ FactoryGirl.define do
15
+ factory :post do
16
+ comments_attributes { [FactoryGirl.attributes_for(:comment), FactoryGirl.attributes_for(:comment)] }
17
+ end
18
+
19
+ factory :comment do
20
+ sequence(:body) {|n| "Body #{n}" }
21
+ end
22
+ end
23
+ end
24
+
25
+ it "assigns the correct amount of comments" do
26
+ FactoryGirl.create(:post).comments.count.should == 2
27
+ end
28
+
29
+ it "assigns the correct amount of comments when overridden" do
30
+ FactoryGirl.create(:post, :comments_attributes => [FactoryGirl.attributes_for(:comment)]).comments.count.should == 1
31
+ end
32
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/ordered_hash'
3
2
 
4
3
  describe "attribute overrides" do
5
4
  before do
@@ -32,9 +31,7 @@ describe "attribute overrides" do
32
31
  let(:admin) { FactoryGirl.create(:admin) }
33
32
 
34
33
  let(:post_attributes) do
35
- attributes = ActiveSupport::OrderedHash.new
36
- attributes[:secure] = false
37
- attributes
34
+ { secure: false }
38
35
  end
39
36
 
40
37
  let(:non_admin_post_attributes) do
@@ -89,3 +89,36 @@ describe "transient sequences" do
89
89
  FactoryGirl.build(:user).name.should == "John Doe 2"
90
90
  end
91
91
  end
92
+
93
+ describe "assigning values from a transient attribute" do
94
+ before do
95
+ define_class("User") do
96
+ attr_accessor :foo_id, :foo_name
97
+ end
98
+
99
+ define_class("Foo") do
100
+ attr_accessor :id, :name
101
+ def initialize(id, name)
102
+ @id = id
103
+ @name = name
104
+ end
105
+ end
106
+
107
+ FactoryGirl.define do
108
+ factory :user do
109
+ ignore do
110
+ foo { Foo.new('id-of-foo', 'name-of-foo')}
111
+ end
112
+
113
+ foo_id { foo.id }
114
+ foo_name { foo.name }
115
+ end
116
+ end
117
+ end
118
+
119
+ it "does not ignore an _id attribute that is an alias for a transient attribute" do
120
+ user = FactoryGirl.build(:user, :foo => Foo.new('passed-in-id-of-foo', 'passed-in-name-of-foo'))
121
+ user.foo_id.should == 'passed-in-id-of-foo'
122
+ user.foo_name.should == 'passed-in-name-of-foo'
123
+ end
124
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc1
5
- prerelease: 6
4
+ version: 3.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Clayton
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-09 00:00:00.000000000 Z
13
+ date: 2012-03-23 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70291930464900 !ruby/object:Gem::Requirement
17
+ requirement: &70112674654360 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70291930464900
25
+ version_requirements: *70112674654360
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70291930463360 !ruby/object:Gem::Requirement
28
+ requirement: &70112674653480 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70291930463360
36
+ version_requirements: *70112674653480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cucumber
39
- requirement: &70291930461720 !ruby/object:Gem::Requirement
39
+ requirement: &70112674652580 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70291930461720
47
+ version_requirements: *70112674652580
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: timecop
50
- requirement: &70291930461040 !ruby/object:Gem::Requirement
50
+ requirement: &70112674652200 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70291930461040
58
+ version_requirements: *70112674652200
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: simplecov
61
- requirement: &70291930459800 !ruby/object:Gem::Requirement
61
+ requirement: &70112674651740 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70291930459800
69
+ version_requirements: *70112674651740
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: aruba
72
- requirement: &70291930458700 !ruby/object:Gem::Requirement
72
+ requirement: &70112674651320 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70291930458700
80
+ version_requirements: *70112674651320
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: mocha
83
- requirement: &70291930330920 !ruby/object:Gem::Requirement
83
+ requirement: &70112674650900 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70291930330920
91
+ version_requirements: *70112674650900
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: bourne
94
- requirement: &70291930329740 !ruby/object:Gem::Requirement
94
+ requirement: &70112674650480 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70291930329740
102
+ version_requirements: *70112674650480
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: appraisal
105
- requirement: &70291930328760 !ruby/object:Gem::Requirement
105
+ requirement: &70112674649980 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 0.3.8
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70291930328760
113
+ version_requirements: *70112674649980
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: sqlite3-ruby
116
- requirement: &70291930327820 !ruby/object:Gem::Requirement
116
+ requirement: &70112674646080 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70291930327820
124
+ version_requirements: *70112674646080
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: yard
127
- requirement: &70291930326540 !ruby/object:Gem::Requirement
127
+ requirement: &70112674644200 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70291930326540
135
+ version_requirements: *70112674644200
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: bluecloth
138
- requirement: &70291930325800 !ruby/object:Gem::Requirement
138
+ requirement: &70112674643660 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70291930325800
146
+ version_requirements: *70112674643660
147
147
  description: ! "factory_girl provides a framework and DSL for defining and\n using
148
148
  factories - less error-prone, more explicit, and\n all-around
149
149
  easier to work with than fixtures."
@@ -209,7 +209,6 @@ files:
209
209
  - lib/factory_girl/find_definitions.rb
210
210
  - lib/factory_girl/null_factory.rb
211
211
  - lib/factory_girl/null_object.rb
212
- - lib/factory_girl/rails2.rb
213
212
  - lib/factory_girl/registry.rb
214
213
  - lib/factory_girl/reload.rb
215
214
  - lib/factory_girl/sequence.rb
@@ -248,6 +247,7 @@ files:
248
247
  - spec/acceptance/initialize_with_spec.rb
249
248
  - spec/acceptance/modify_factories_spec.rb
250
249
  - spec/acceptance/modify_inherited_spec.rb
250
+ - spec/acceptance/nested_attributes_spec.rb
251
251
  - spec/acceptance/overrides_spec.rb
252
252
  - spec/acceptance/parent_spec.rb
253
253
  - spec/acceptance/sequence_spec.rb
@@ -307,12 +307,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
307
307
  required_rubygems_version: !ruby/object:Gem::Requirement
308
308
  none: false
309
309
  requirements:
310
- - - ! '>'
310
+ - - ! '>='
311
311
  - !ruby/object:Gem::Version
312
- version: 1.3.1
312
+ version: '0'
313
313
  requirements: []
314
314
  rubyforge_project:
315
- rubygems_version: 1.8.16
315
+ rubygems_version: 1.8.17
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
@@ -350,6 +350,7 @@ test_files:
350
350
  - spec/acceptance/initialize_with_spec.rb
351
351
  - spec/acceptance/modify_factories_spec.rb
352
352
  - spec/acceptance/modify_inherited_spec.rb
353
+ - spec/acceptance/nested_attributes_spec.rb
353
354
  - spec/acceptance/overrides_spec.rb
354
355
  - spec/acceptance/parent_spec.rb
355
356
  - spec/acceptance/sequence_spec.rb
@@ -1,8 +0,0 @@
1
- Rails.configuration.after_initialize do
2
- FactoryGirl.definition_file_paths = [
3
- File.join(Rails.root, 'factories'),
4
- File.join(Rails.root, 'test', 'factories'),
5
- File.join(Rails.root, 'spec', 'factories')
6
- ]
7
- FactoryGirl.find_definitions
8
- end