factory_girl 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6276447e1d14327c827a7b14fe08b3bbc729d07b
4
+ data.tar.gz: d8eac964100d437c88ad82ad217a267285ff7461
5
+ SHA512:
6
+ metadata.gz: c25de9107b3313fe1b40d5713f2a2446ce569bb68923eb8a084af42c50a050571e4b98fee61bf534d77bce8b3751cf832b65793d4058dceb8571e369ab4fa7e8
7
+ data.tar.gz: 8464e558d14c2a3e0f890af7010dc4c85652c56656a6d0d9b2ec948eb0519e9be15fad7ce843f7124c6437d97343d70b2e320d3e7e2df034e7ce5be5f4f5aca6
data/.travis.yml CHANGED
@@ -1,16 +1,17 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
3
+ - 2.0.0
4
4
  - jruby-19mode
5
5
  before_install:
6
6
  - gem update --system
7
+ install: "bundle install"
7
8
  script: "bundle exec rake spec:unit spec:acceptance features"
8
9
  jdk:
9
10
  - openjdk6
10
11
  gemfile:
11
- - gemfiles/3.0.gemfile
12
12
  - gemfiles/3.1.gemfile
13
13
  - gemfiles/3.2.gemfile
14
+ - gemfiles/4.0.gemfile
14
15
  branches:
15
16
  only:
16
17
  - master
data/Appraisals CHANGED
@@ -1,15 +1,11 @@
1
- appraise "3.0" do
2
- gem "activerecord", "~> 3.0.19"
3
- end
4
-
5
1
  appraise "3.1" do
6
- gem "activerecord", "~> 3.1.10"
2
+ gem "activerecord", "~> 3.1.12"
7
3
  end
8
4
 
9
5
  appraise "3.2" do
10
- gem "activerecord", "~> 3.2.11"
6
+ gem "activerecord", "~> 3.2.15"
11
7
  end
12
8
 
13
9
  appraise '4.0' do
14
- gem 'activerecord', github: 'rails/rails'
10
+ gem 'activerecord', "~> 4.0.1"
15
11
  end
data/GETTING_STARTED.md CHANGED
@@ -19,7 +19,7 @@ gem "factory_girl", "~> 4.0"
19
19
  JRuby users: FactoryGirl works with JRuby starting with 1.6.7.2 (latest stable, as per July 2012).
20
20
  JRuby has to be used in 1.9 mode, for that, use JRUBY_OPTS environment variable:
21
21
 
22
- ```
22
+ ```bash
23
23
  export JRUBY_OPTS=--1.9
24
24
  ```
25
25
 
@@ -30,7 +30,7 @@ Using Without Bundler
30
30
 
31
31
  If you're not using Bundler, be sure to have the gem installed and call:
32
32
 
33
- ```
33
+ ```ruby
34
34
  require 'factory_girl'
35
35
  ```
36
36
 
@@ -498,7 +498,7 @@ factory :user do
498
498
  end
499
499
 
500
500
  # will increase value counter for :email which is shared by :sender and :receiver
501
- FactoryGirl.next(:sender)
501
+ FactoryGirl.generate(:sender)
502
502
  ```
503
503
 
504
504
  Define aliases and use default value (1) for the counter
@@ -563,7 +563,7 @@ Traits can be used as attributes:
563
563
  factory :week_long_published_story_with_title, parent: :story do
564
564
  published
565
565
  week_long_publishing
566
- title { "Publishing that was started at {start_at}" }
566
+ title { "Publishing that was started at #{start_at}" }
567
567
  end
568
568
  ```
569
569
 
@@ -695,6 +695,24 @@ end
695
695
  # creates an admin user with name "John Doe"
696
696
  FactoryGirl.create(:post).author
697
697
  ```
698
+
699
+ Finally, traits can be used within other traits to mix in their attributes.
700
+
701
+ ```ruby
702
+ FactoryGirl.define do
703
+ factory :order do
704
+ trait :completed do
705
+ completed_at { 3.days.ago }
706
+ end
707
+
708
+ trait :refunded do
709
+ completed
710
+ refunded_at { 1.day.ago }
711
+ end
712
+ end
713
+ end
714
+ ```
715
+
698
716
  Callbacks
699
717
  ---------
700
718
 
@@ -748,6 +766,40 @@ factory :user do
748
766
  end
749
767
  ```
750
768
 
769
+ To override callbacks for all factories, define them within the
770
+ `FactoryGirl.define` block:
771
+
772
+ ```ruby
773
+ FactoryGirl.define do
774
+ after(:build) {|object| puts "Built #{object}" }
775
+ after(:create) {|object| AuditLog.create(attrs: object.attributes) }
776
+
777
+ factory :user do
778
+ name "John Doe"
779
+ end
780
+ end
781
+ ```
782
+
783
+ You can also call callbacks that rely on `Symbol#to_proc`:
784
+
785
+ ```ruby
786
+ # app/models/user.rb
787
+ class User < ActiveRecord::Base
788
+ def confirm!
789
+ # confirm the user account
790
+ end
791
+ end
792
+
793
+ # spec/factories.rb
794
+ FactoryGirl.define do
795
+ factory :user do
796
+ after :create, &:confirm!
797
+ end
798
+ end
799
+
800
+ FactoryGirl.create(:user) # creates the user and confirms it
801
+ ```
802
+
751
803
  Modifying factories
752
804
  -------------------
753
805
 
@@ -816,6 +868,13 @@ To set the attributes for each of the factories, you can pass in a hash as you n
816
868
  twenty_year_olds = FactoryGirl.build_list(:user, 25, date_of_birth: 20.years.ago)
817
869
  ```
818
870
 
871
+ There's also a set of `*_pair` methods for creating two records at a time:
872
+
873
+ ```ruby
874
+ built_users = FactoryGirl.build_pair(:user) # array of two built users
875
+ created_users = FactoryGirl.create_pair(:user) # array of two created users
876
+ ```
877
+
819
878
  Custom Construction
820
879
  -------------------
821
880
 
@@ -835,7 +894,7 @@ class User
835
894
  end
836
895
 
837
896
  # factories.rb
838
- sequence(:name) {|n| "person#{n}@example.com" }
897
+ sequence(:email) {|n| "person#{n}@example.com" }
839
898
 
840
899
  factory :user do
841
900
  ignore do
@@ -1103,3 +1162,40 @@ config.after(:suite) do
1103
1162
  puts @factory_girl_results
1104
1163
  end
1105
1164
  ```
1165
+
1166
+ Rails Preloaders and RSpec
1167
+ --------------------------
1168
+
1169
+ When running RSpec with a Rails preloader such as `spring` or `zeus`, it's possible
1170
+ to encounter an `ActiveRecord::AssociationTypeMismatch` error when creating a factory
1171
+ with associations, as below:
1172
+
1173
+ ```ruby
1174
+ FactoryGirl.define do
1175
+ factory :united_states, class: Location do
1176
+ name 'United States'
1177
+ association :location_group, factory: :north_america
1178
+ end
1179
+
1180
+ factory :north_america, class: LocationGroup do
1181
+ name 'North America'
1182
+ end
1183
+ end
1184
+ ```
1185
+
1186
+ The error occurs during the run of the test suite:
1187
+
1188
+ ```
1189
+ Failure/Error: united_states = FactoryGirl.create(:united_states)
1190
+ ActiveRecord::AssociationTypeMismatch:
1191
+ LocationGroup(#70251250797320) expected, got LocationGroup(#70251200725840)
1192
+ ```
1193
+
1194
+ The two possible solutions are to either run the suite without the preloader, or
1195
+ to add `FactoryGirl.reload` to the RSpec configuration, like so:
1196
+
1197
+ ```ruby
1198
+ RSpec.configure do |config|
1199
+ config.before(:suite) { FactoryGirl.reload }
1200
+ end
1201
+ ```
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "activerecord", :require => false
3
+ gem "activerecord", ">= 3.0.0", :require => false
4
4
 
5
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,57 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (4.2.0)
4
+ factory_girl (4.3.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.2.3)
11
- activesupport (= 3.2.3)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.3)
14
- activemodel (= 3.2.3)
15
- activesupport (= 3.2.3)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.3)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.5.1)
10
+ activemodel (4.0.0)
11
+ activesupport (= 4.0.0)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.0)
14
+ activemodel (= 4.0.0)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.0)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activesupport (4.0.0)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ minitest (~> 4.2)
22
+ multi_json (~> 1.3)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 0.3.37)
25
+ appraisal (0.5.2)
22
26
  bundler
23
27
  rake
24
- arel (3.0.2)
25
- aruba (0.4.11)
26
- childprocess (>= 0.2.3)
28
+ arel (4.0.0)
29
+ aruba (0.5.3)
30
+ childprocess (>= 0.3.6)
27
31
  cucumber (>= 1.1.1)
28
- ffi (>= 1.0.11)
29
- rspec (>= 2.7.0)
30
- bourne (1.3.0)
31
- mocha (= 0.13.0)
32
- builder (3.0.4)
33
- childprocess (0.3.2)
34
- ffi (~> 1.0.6)
35
- cucumber (1.2.1)
32
+ rspec-expectations (>= 2.7.0)
33
+ atomic (1.1.10)
34
+ atomic (1.1.10-java)
35
+ bourne (1.5.0)
36
+ mocha (>= 0.13.2, < 0.15)
37
+ builder (3.1.4)
38
+ childprocess (0.3.9)
39
+ ffi (~> 1.0, >= 1.0.11)
40
+ cucumber (1.2.5)
36
41
  builder (>= 2.1.2)
37
42
  diff-lcs (>= 1.1.3)
38
- gherkin (~> 2.11.0)
39
- json (>= 1.4.6)
43
+ gherkin (~> 2.11.7)
44
+ multi_json (~> 1.3)
40
45
  diff-lcs (1.1.3)
41
- ffi (1.0.11)
42
- ffi (1.0.11-java)
43
- gherkin (2.11.5)
44
- json (>= 1.4.6)
45
- gherkin (2.11.5-java)
46
- json (>= 1.4.6)
47
- i18n (0.6.1)
48
- json (1.7.5)
49
- json (1.7.5-java)
46
+ ffi (1.9.0)
47
+ ffi (1.9.0-java)
48
+ gherkin (2.11.8)
49
+ multi_json (~> 1.3)
50
+ gherkin (2.11.8-java)
51
+ multi_json (~> 1.3)
52
+ i18n (0.6.4)
50
53
  metaclass (0.0.1)
51
- mocha (0.13.0)
54
+ minitest (4.7.5)
55
+ mocha (0.14.0)
52
56
  metaclass (~> 0.0.1)
53
- multi_json (1.5.0)
54
- rake (0.9.2.2)
57
+ multi_json (1.7.7)
58
+ rake (10.1.0)
55
59
  rspec (2.12.0)
56
60
  rspec-core (~> 2.12.0)
57
61
  rspec-expectations (~> 2.12.0)
@@ -59,22 +63,26 @@ GEM
59
63
  rspec-core (2.12.2)
60
64
  rspec-expectations (2.12.1)
61
65
  diff-lcs (~> 1.1.3)
62
- rspec-mocks (2.12.1)
63
- simplecov (0.6.2)
64
- multi_json (~> 1.3)
65
- simplecov-html (~> 0.5.3)
66
- simplecov-html (0.5.3)
67
- sqlite3 (1.3.7)
68
- timecop (0.3.5)
69
- tzinfo (0.3.33)
70
- yard (0.8.1)
66
+ rspec-mocks (2.12.2)
67
+ simplecov (0.7.1)
68
+ multi_json (~> 1.0)
69
+ simplecov-html (~> 0.7.1)
70
+ simplecov-html (0.7.1)
71
+ sqlite3 (1.3.8)
72
+ thread_safe (0.1.2)
73
+ atomic
74
+ thread_safe (0.1.2-java)
75
+ atomic
76
+ timecop (0.6.2.2)
77
+ tzinfo (0.3.37)
78
+ yard (0.8.7)
71
79
 
72
80
  PLATFORMS
73
81
  java
74
82
  ruby
75
83
 
76
84
  DEPENDENCIES
77
- activerecord
85
+ activerecord (>= 3.0.0)
78
86
  appraisal (~> 0.5.1)
79
87
  aruba
80
88
  bourne
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # factory_girl [![Build Status](https://secure.travis-ci.org/thoughtbot/factory_girl.png)](http://travis-ci.org/thoughtbot/factory_girl?branch=master) [![Dependency Status](https://gemnasium.com/thoughtbot/factory_girl.png)](https://gemnasium.com/thoughtbot/factory_girl)
1
+ # factory_girl [![Build Status](https://secure.travis-ci.org/thoughtbot/factory_girl.png)](http://travis-ci.org/thoughtbot/factory_girl?branch=master) [![Dependency Status](https://gemnasium.com/thoughtbot/factory_girl.png)](https://gemnasium.com/thoughtbot/factory_girl) [![Code Climate](https://codeclimate.com/github/thoughtbot/factory_girl.png)](https://codeclimate.com/github/thoughtbot/factory_girl)
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
 
@@ -51,16 +51,9 @@ Please see the [contribution guidelines](https://github.com/thoughtbot/factory_g
51
51
  Credits
52
52
  -------
53
53
 
54
- factory_girl was written by Joe Ferris with contributions from several authors, including:
55
-
56
- * Alex Sharp
57
- * Eugene Bolshakov
58
- * Jon Yurek
59
- * Josh Nichols
60
- * Josh Owens
61
- * Nate Sutton
62
- * Josh Clayton
63
- * Thomas Walpole
54
+ factory_girl was originally written by Joe Ferris and is now maintained by Josh
55
+ Clayton. Many improvements and bugfixes were contributed by the [open source
56
+ community](https://github.com/thoughtbot/factory_girl/graphs/contributors).
64
57
 
65
58
  ![thoughtbot](http://thoughtbot.com/assets/tm/logo.png)
66
59
 
@@ -71,4 +64,4 @@ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
71
64
  License
72
65
  -------
73
66
 
74
- factory_girl is Copyright © 2008-2013 Joe Ferris and thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.
67
+ factory_girl is Copyright © 2008-2013 Joe Ferris and thoughtbot. It is free software, and may be redistributed under the terms specified in the [LICENSE](https://github.com/thoughtbot/factory_girl/blob/master/LICENSE) file.
data/Rakefile CHANGED
@@ -9,8 +9,8 @@ require 'cucumber/rake/task'
9
9
  Bundler::GemHelper.install_tasks
10
10
 
11
11
  desc 'Default: run the specs and features.'
12
- task :default => 'spec:unit' do
13
- system("bundle exec rake -s appraisal spec:acceptance features;")
12
+ task :default do
13
+ system("bundle exec rake -s appraisal spec:unit spec:acceptance features;")
14
14
  end
15
15
 
16
16
  namespace :spec do
data/factory_girl.gemspec CHANGED
@@ -40,5 +40,6 @@ Gem::Specification.new do |s|
40
40
  end
41
41
 
42
42
  s.add_development_dependency("yard")
43
+ s.license = "MIT"
43
44
  end
44
45
 
data/gemfiles/3.1.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.1.10"
5
+ gem "activerecord", "~> 3.1.12"
6
6
 
7
7
  gemspec :path=>"../"
@@ -1,52 +1,54 @@
1
1
  PATH
2
- remote: /Users/joshuaclayton/dev/gems/factory_girl
2
+ remote: ../
3
3
  specs:
4
- factory_girl (4.2.0)
4
+ factory_girl (4.3.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.1.10)
11
- activesupport (= 3.1.10)
10
+ activemodel (3.1.12)
11
+ activesupport (= 3.1.12)
12
12
  builder (~> 3.0.0)
13
13
  i18n (~> 0.6)
14
- activerecord (3.1.10)
15
- activemodel (= 3.1.10)
16
- activesupport (= 3.1.10)
14
+ activerecord (3.1.12)
15
+ activemodel (= 3.1.12)
16
+ activesupport (= 3.1.12)
17
17
  arel (~> 2.2.3)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.1.10)
20
- multi_json (>= 1.0, < 1.3)
21
- appraisal (0.5.1)
19
+ activesupport (3.1.12)
20
+ multi_json (~> 1.0)
21
+ appraisal (0.5.2)
22
22
  bundler
23
23
  rake
24
24
  arel (2.2.3)
25
- aruba (0.5.1)
26
- childprocess (~> 0.3.6)
25
+ aruba (0.5.3)
26
+ childprocess (>= 0.3.6)
27
27
  cucumber (>= 1.1.1)
28
28
  rspec-expectations (>= 2.7.0)
29
- bourne (1.3.0)
30
- mocha (= 0.13.0)
29
+ bourne (1.4.0)
30
+ mocha (~> 0.13.2)
31
31
  builder (3.0.4)
32
- childprocess (0.3.6)
33
- ffi (~> 1.0, >= 1.0.6)
34
- cucumber (1.2.1)
32
+ childprocess (0.3.9)
33
+ ffi (~> 1.0, >= 1.0.11)
34
+ cucumber (1.2.5)
35
35
  builder (>= 2.1.2)
36
36
  diff-lcs (>= 1.1.3)
37
- gherkin (~> 2.11.0)
38
- json (>= 1.4.6)
37
+ gherkin (~> 2.11.7)
38
+ multi_json (~> 1.3)
39
39
  diff-lcs (1.1.3)
40
- ffi (1.3.1)
41
- gherkin (2.11.5)
42
- json (>= 1.4.6)
43
- i18n (0.6.1)
44
- json (1.7.6)
40
+ ffi (1.9.0)
41
+ ffi (1.9.0-java)
42
+ gherkin (2.11.8)
43
+ multi_json (~> 1.3)
44
+ gherkin (2.11.8-java)
45
+ multi_json (~> 1.3)
46
+ i18n (0.6.4)
45
47
  metaclass (0.0.1)
46
- mocha (0.13.0)
48
+ mocha (0.13.3)
47
49
  metaclass (~> 0.0.1)
48
- multi_json (1.2.0)
49
- rake (10.0.3)
50
+ multi_json (1.7.7)
51
+ rake (10.1.0)
50
52
  rspec (2.12.0)
51
53
  rspec-core (~> 2.12.0)
52
54
  rspec-expectations (~> 2.12.0)
@@ -54,21 +56,22 @@ GEM
54
56
  rspec-core (2.12.2)
55
57
  rspec-expectations (2.12.1)
56
58
  diff-lcs (~> 1.1.3)
57
- rspec-mocks (2.12.1)
59
+ rspec-mocks (2.12.2)
58
60
  simplecov (0.7.1)
59
61
  multi_json (~> 1.0)
60
62
  simplecov-html (~> 0.7.1)
61
63
  simplecov-html (0.7.1)
62
- sqlite3 (1.3.7)
63
- timecop (0.5.9)
64
- tzinfo (0.3.35)
65
- yard (0.8.3)
64
+ sqlite3 (1.3.8)
65
+ timecop (0.6.1)
66
+ tzinfo (0.3.37)
67
+ yard (0.8.6.1)
66
68
 
67
69
  PLATFORMS
70
+ java
68
71
  ruby
69
72
 
70
73
  DEPENDENCIES
71
- activerecord (~> 3.1.10)
74
+ activerecord (~> 3.1.12)
72
75
  appraisal (~> 0.5.1)
73
76
  aruba
74
77
  bourne