factory_girl 3.6.0 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/GETTING_STARTED.md CHANGED
@@ -632,7 +632,45 @@ end
632
632
  FactoryGirl.create_list(:user, 3, :admin, :male, name: "Jon Snow")
633
633
  ```
634
634
 
635
+ Traits can be used with associations easily too:
635
636
 
637
+ ```ruby
638
+ factory :user do
639
+ name "Friendly User"
640
+
641
+ trait :admin do
642
+ admin true
643
+ end
644
+ end
645
+
646
+ factory :post do
647
+ association :user, :admin, name: 'John Doe'
648
+ end
649
+
650
+ # creates an admin user with named "John Doe"
651
+ FactoryGirl.create(:post).user
652
+ ```
653
+
654
+ When you're using association names that're different than the factory:
655
+
656
+ ```ruby
657
+ factory :user do
658
+ name "Friendly User"
659
+
660
+ trait :admin do
661
+ admin true
662
+ end
663
+ end
664
+
665
+ factory :post do
666
+ association :author, :admin, factory: :user, name: 'John Doe'
667
+ # or
668
+ association :author, factory: [:user, :admin], name: 'John Doe'
669
+ end
670
+
671
+ # creates an admin user with named "John Doe"
672
+ FactoryGirl.create(:post).user
673
+ ```
636
674
  Callbacks
637
675
  ---------
638
676
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (3.6.0)
4
+ factory_girl (3.6.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -53,14 +53,14 @@ GEM
53
53
  metaclass (~> 0.0.1)
54
54
  multi_json (1.3.4)
55
55
  rake (0.9.2.2)
56
- rspec (2.9.0)
57
- rspec-core (~> 2.9.0)
58
- rspec-expectations (~> 2.9.0)
59
- rspec-mocks (~> 2.9.0)
60
- rspec-core (2.9.0)
61
- rspec-expectations (2.9.1)
56
+ rspec (2.11.0)
57
+ rspec-core (~> 2.11.0)
58
+ rspec-expectations (~> 2.11.0)
59
+ rspec-mocks (~> 2.11.0)
60
+ rspec-core (2.11.1)
61
+ rspec-expectations (2.11.2)
62
62
  diff-lcs (~> 1.1.3)
63
- rspec-mocks (2.9.0)
63
+ rspec-mocks (2.11.1)
64
64
  simplecov (0.6.2)
65
65
  multi_json (~> 1.3)
66
66
  simplecov-html (~> 0.5.3)
data/NEWS CHANGED
@@ -1,3 +1,9 @@
1
+ 3.6.1 (August 2, 2012)
2
+ Update README to include info about running with JRuby
3
+ Update dependencies on RSpec and tiny versions of Rails in Appraisal
4
+ Improve flexibility of using traits with associations and add documentation
5
+ Stub update_column to raise to mirror ActiveRecord's change from update_attribute
6
+
1
7
  3.6.0 (July 27, 2012)
2
8
  Code/spec cleanup
3
9
  Allow factories with traits to be used in associations
data/README.md CHANGED
@@ -28,9 +28,12 @@ and run `bundle install` from your shell.
28
28
  Supported Ruby versions
29
29
  -----------------------
30
30
 
31
- The FactoryGirl 3.x series supports Ruby 1.9.x.
31
+ The FactoryGirl 3.x+ series supports MRI Ruby 1.9. Additionally, FactoryGirl
32
+ 3.6+ supports JRuby 1.6.7.2+ while running in 1.9 mode. See
33
+ [GETTING_STARTED](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md)
34
+ for more information on configuring the JRuby environment.
32
35
 
33
- For older versions of Ruby, please use the FactoryGirl 2.x series.
36
+ For versions of Ruby prior to 1.9, please use FactoryGirl 2.x.
34
37
 
35
38
  More Information
36
39
  ----------------
@@ -1,22 +1,22 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.6.0)
4
+ factory_girl (3.6.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.0.12)
11
- activesupport (= 3.0.12)
10
+ activemodel (3.0.16)
11
+ activesupport (= 3.0.16)
12
12
  builder (~> 2.1.2)
13
13
  i18n (~> 0.5.0)
14
- activerecord (3.0.12)
15
- activemodel (= 3.0.12)
16
- activesupport (= 3.0.12)
14
+ activerecord (3.0.16)
15
+ activemodel (= 3.0.16)
16
+ activesupport (= 3.0.16)
17
17
  arel (~> 2.0.10)
18
18
  tzinfo (~> 0.3.23)
19
- activesupport (3.0.12)
19
+ activesupport (3.0.16)
20
20
  appraisal (0.4.1)
21
21
  bundler
22
22
  rake
@@ -29,48 +29,46 @@ GEM
29
29
  bourne (1.1.2)
30
30
  mocha (= 0.10.5)
31
31
  builder (2.1.2)
32
- childprocess (0.3.2)
33
- ffi (~> 1.0.6)
34
- cucumber (1.1.9)
32
+ childprocess (0.3.4)
33
+ ffi (~> 1.0, >= 1.0.6)
34
+ cucumber (1.2.1)
35
35
  builder (>= 2.1.2)
36
- diff-lcs (>= 1.1.2)
37
- gherkin (~> 2.9.0)
36
+ diff-lcs (>= 1.1.3)
37
+ gherkin (~> 2.11.0)
38
38
  json (>= 1.4.6)
39
- term-ansicolor (>= 1.0.6)
40
39
  diff-lcs (1.1.3)
41
- ffi (1.0.11)
42
- ffi (1.0.11-java)
43
- gherkin (2.9.3)
40
+ ffi (1.1.3)
41
+ ffi (1.1.3-java)
42
+ gherkin (2.11.1)
44
43
  json (>= 1.4.6)
45
- gherkin (2.9.3-java)
44
+ gherkin (2.11.1-java)
46
45
  json (>= 1.4.6)
47
46
  i18n (0.5.0)
48
- json (1.7.0)
49
- json (1.7.0-java)
47
+ json (1.7.4)
48
+ json (1.7.4-java)
50
49
  metaclass (0.0.1)
51
50
  mocha (0.10.5)
52
51
  metaclass (~> 0.0.1)
53
- multi_json (1.3.4)
52
+ multi_json (1.3.6)
54
53
  rake (0.9.2.2)
55
- rspec (2.9.0)
56
- rspec-core (~> 2.9.0)
57
- rspec-expectations (~> 2.9.0)
58
- rspec-mocks (~> 2.9.0)
59
- rspec-core (2.9.0)
60
- rspec-expectations (2.9.1)
54
+ rspec (2.11.0)
55
+ rspec-core (~> 2.11.0)
56
+ rspec-expectations (~> 2.11.0)
57
+ rspec-mocks (~> 2.11.0)
58
+ rspec-core (2.11.1)
59
+ rspec-expectations (2.11.2)
61
60
  diff-lcs (~> 1.1.3)
62
- rspec-mocks (2.9.0)
63
- simplecov (0.6.2)
64
- multi_json (~> 1.3)
61
+ rspec-mocks (2.11.1)
62
+ simplecov (0.6.4)
63
+ multi_json (~> 1.0)
65
64
  simplecov-html (~> 0.5.3)
66
65
  simplecov-html (0.5.3)
67
66
  sqlite3 (1.3.6)
68
67
  sqlite3-ruby (1.3.3)
69
68
  sqlite3 (>= 1.3.3)
70
- term-ansicolor (1.0.7)
71
- timecop (0.3.5)
69
+ timecop (0.4.4)
72
70
  tzinfo (0.3.33)
73
- yard (0.8.1)
71
+ yard (0.8.2.1)
74
72
 
75
73
  PLATFORMS
76
74
  java
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.6.0)
4
+ factory_girl (3.6.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.1.4)
11
- activesupport (= 3.1.4)
10
+ activemodel (3.1.7)
11
+ activesupport (= 3.1.7)
12
12
  builder (~> 3.0.0)
13
13
  i18n (~> 0.6)
14
- activerecord (3.1.4)
15
- activemodel (= 3.1.4)
16
- activesupport (= 3.1.4)
14
+ activerecord (3.1.7)
15
+ activemodel (= 3.1.7)
16
+ activesupport (= 3.1.7)
17
17
  arel (~> 2.2.3)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.1.4)
20
- multi_json (~> 1.0)
19
+ activesupport (3.1.7)
20
+ multi_json (>= 1.0, < 1.3)
21
21
  appraisal (0.4.1)
22
22
  bundler
23
23
  rake
@@ -30,48 +30,46 @@ GEM
30
30
  bourne (1.1.2)
31
31
  mocha (= 0.10.5)
32
32
  builder (3.0.0)
33
- childprocess (0.3.2)
34
- ffi (~> 1.0.6)
35
- cucumber (1.1.9)
33
+ childprocess (0.3.4)
34
+ ffi (~> 1.0, >= 1.0.6)
35
+ cucumber (1.2.1)
36
36
  builder (>= 2.1.2)
37
- diff-lcs (>= 1.1.2)
38
- gherkin (~> 2.9.0)
37
+ diff-lcs (>= 1.1.3)
38
+ gherkin (~> 2.11.0)
39
39
  json (>= 1.4.6)
40
- term-ansicolor (>= 1.0.6)
41
40
  diff-lcs (1.1.3)
42
- ffi (1.0.11)
43
- ffi (1.0.11-java)
44
- gherkin (2.9.3)
41
+ ffi (1.1.3)
42
+ ffi (1.1.3-java)
43
+ gherkin (2.11.1)
45
44
  json (>= 1.4.6)
46
- gherkin (2.9.3-java)
45
+ gherkin (2.11.1-java)
47
46
  json (>= 1.4.6)
48
47
  i18n (0.6.0)
49
- json (1.7.0)
50
- json (1.7.0-java)
48
+ json (1.7.4)
49
+ json (1.7.4-java)
51
50
  metaclass (0.0.1)
52
51
  mocha (0.10.5)
53
52
  metaclass (~> 0.0.1)
54
- multi_json (1.3.4)
53
+ multi_json (1.2.0)
55
54
  rake (0.9.2.2)
56
- rspec (2.9.0)
57
- rspec-core (~> 2.9.0)
58
- rspec-expectations (~> 2.9.0)
59
- rspec-mocks (~> 2.9.0)
60
- rspec-core (2.9.0)
61
- rspec-expectations (2.9.1)
55
+ rspec (2.11.0)
56
+ rspec-core (~> 2.11.0)
57
+ rspec-expectations (~> 2.11.0)
58
+ rspec-mocks (~> 2.11.0)
59
+ rspec-core (2.11.1)
60
+ rspec-expectations (2.11.2)
62
61
  diff-lcs (~> 1.1.3)
63
- rspec-mocks (2.9.0)
64
- simplecov (0.6.2)
65
- multi_json (~> 1.3)
62
+ rspec-mocks (2.11.1)
63
+ simplecov (0.6.4)
64
+ multi_json (~> 1.0)
66
65
  simplecov-html (~> 0.5.3)
67
66
  simplecov-html (0.5.3)
68
67
  sqlite3 (1.3.6)
69
68
  sqlite3-ruby (1.3.3)
70
69
  sqlite3 (>= 1.3.3)
71
- term-ansicolor (1.0.7)
72
- timecop (0.3.5)
70
+ timecop (0.4.4)
73
71
  tzinfo (0.3.33)
74
- yard (0.8.1)
72
+ yard (0.8.2.1)
75
73
 
76
74
  PLATFORMS
77
75
  java
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.6.0)
4
+ factory_girl (3.6.1)
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)
10
+ activemodel (3.2.7)
11
+ activesupport (= 3.2.7)
12
12
  builder (~> 3.0.0)
13
- activerecord (3.2.3)
14
- activemodel (= 3.2.3)
15
- activesupport (= 3.2.3)
13
+ activerecord (3.2.7)
14
+ activemodel (= 3.2.7)
15
+ activesupport (= 3.2.7)
16
16
  arel (~> 3.0.2)
17
17
  tzinfo (~> 0.3.29)
18
- activesupport (3.2.3)
18
+ activesupport (3.2.7)
19
19
  i18n (~> 0.6)
20
20
  multi_json (~> 1.0)
21
21
  appraisal (0.4.1)
@@ -30,48 +30,46 @@ GEM
30
30
  bourne (1.1.2)
31
31
  mocha (= 0.10.5)
32
32
  builder (3.0.0)
33
- childprocess (0.3.2)
34
- ffi (~> 1.0.6)
35
- cucumber (1.1.9)
33
+ childprocess (0.3.4)
34
+ ffi (~> 1.0, >= 1.0.6)
35
+ cucumber (1.2.1)
36
36
  builder (>= 2.1.2)
37
- diff-lcs (>= 1.1.2)
38
- gherkin (~> 2.9.0)
37
+ diff-lcs (>= 1.1.3)
38
+ gherkin (~> 2.11.0)
39
39
  json (>= 1.4.6)
40
- term-ansicolor (>= 1.0.6)
41
40
  diff-lcs (1.1.3)
42
- ffi (1.0.11)
43
- ffi (1.0.11-java)
44
- gherkin (2.9.3)
41
+ ffi (1.1.3)
42
+ ffi (1.1.3-java)
43
+ gherkin (2.11.1)
45
44
  json (>= 1.4.6)
46
- gherkin (2.9.3-java)
45
+ gherkin (2.11.1-java)
47
46
  json (>= 1.4.6)
48
47
  i18n (0.6.0)
49
- json (1.7.0)
50
- json (1.7.0-java)
48
+ json (1.7.4)
49
+ json (1.7.4-java)
51
50
  metaclass (0.0.1)
52
51
  mocha (0.10.5)
53
52
  metaclass (~> 0.0.1)
54
- multi_json (1.3.4)
53
+ multi_json (1.3.6)
55
54
  rake (0.9.2.2)
56
- rspec (2.9.0)
57
- rspec-core (~> 2.9.0)
58
- rspec-expectations (~> 2.9.0)
59
- rspec-mocks (~> 2.9.0)
60
- rspec-core (2.9.0)
61
- rspec-expectations (2.9.1)
55
+ rspec (2.11.0)
56
+ rspec-core (~> 2.11.0)
57
+ rspec-expectations (~> 2.11.0)
58
+ rspec-mocks (~> 2.11.0)
59
+ rspec-core (2.11.1)
60
+ rspec-expectations (2.11.2)
62
61
  diff-lcs (~> 1.1.3)
63
- rspec-mocks (2.9.0)
64
- simplecov (0.6.2)
65
- multi_json (~> 1.3)
62
+ rspec-mocks (2.11.1)
63
+ simplecov (0.6.4)
64
+ multi_json (~> 1.0)
66
65
  simplecov-html (~> 0.5.3)
67
66
  simplecov-html (0.5.3)
68
67
  sqlite3 (1.3.6)
69
68
  sqlite3-ruby (1.3.3)
70
69
  sqlite3 (>= 1.3.3)
71
- term-ansicolor (1.0.7)
72
- timecop (0.3.5)
70
+ timecop (0.4.4)
73
71
  tzinfo (0.3.33)
74
- yard (0.8.1)
72
+ yard (0.8.2.1)
75
73
 
76
74
  PLATFORMS
77
75
  java
@@ -2,9 +2,11 @@ module FactoryGirl
2
2
  class Declaration
3
3
  # @api private
4
4
  class Association < Declaration
5
- def initialize(name, options)
5
+ def initialize(name, *options)
6
6
  super(name, false)
7
- @options = options
7
+ @options = options.dup
8
+ @overrides = options.extract_options!
9
+ @traits = options
8
10
  end
9
11
 
10
12
  def ==(other)
@@ -18,8 +20,8 @@ module FactoryGirl
18
20
  private
19
21
 
20
22
  def build
21
- factory_name = @options[:factory] || name
22
- [Attribute::Association.new(name, factory_name, @options.except(:factory))]
23
+ factory_name = @overrides[:factory] || name
24
+ [Attribute::Association.new(name, factory_name, [@traits, @overrides.except(:factory)].flatten)]
23
25
  end
24
26
  end
25
27
  end
@@ -138,8 +138,8 @@ module FactoryGirl
138
138
  # If no name is given, the name of the attribute is assumed to be the
139
139
  # name of the factory. For example, a "user" association will by
140
140
  # default use the "user" factory.
141
- def association(name, options = {})
142
- @definition.declare_attribute(Declaration::Association.new(name, options))
141
+ def association(name, *options)
142
+ @definition.declare_attribute(Declaration::Association.new(name, *options))
143
143
  end
144
144
 
145
145
  def to_create(&block)
@@ -51,6 +51,10 @@ module FactoryGirl
51
51
  def update_attribute(*args)
52
52
  raise 'stubbed models are not allowed to access the database'
53
53
  end
54
+
55
+ def update_column(*args)
56
+ raise 'stubbed models are not allowed to access the database'
57
+ end
54
58
  end
55
59
 
56
60
  created_at_missing_default = result_instance.respond_to?(:created_at) && !result_instance.created_at
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '3.6.0'
2
+ VERSION = '3.6.1'
3
3
  end
@@ -131,7 +131,6 @@ describe "defaulting `created_at`" do
131
131
  end
132
132
 
133
133
  it "doesn't allow setting created_at on an object that doesn't define it" do
134
- expect { build_stubbed(:thing_without_timestamp, :created_at => Time.now) }.to
135
- raise_error(NoMethodError, /created_at=/)
134
+ expect { build_stubbed(:thing_without_timestamp, :created_at => Time.now) }.to raise_error(NoMethodError, /created_at=/)
136
135
  end
137
136
  end
@@ -673,6 +673,15 @@ end
673
673
  describe "traits used in associations" do
674
674
  before do
675
675
  define_model("User", admin: :boolean, name: :string)
676
+
677
+ define_model("Comment", user_id: :integer) do
678
+ belongs_to :user
679
+ end
680
+
681
+ define_model("Order", creator_id: :integer) do
682
+ belongs_to :creator, class_name: 'User'
683
+ end
684
+
676
685
  define_model("Post", author_id: :integer) do
677
686
  belongs_to :author, class_name: 'User'
678
687
  end
@@ -689,6 +698,14 @@ describe "traits used in associations" do
689
698
  factory :post do
690
699
  association :author, factory: [:user, :admin], name: 'John Doe'
691
700
  end
701
+
702
+ factory :comment do
703
+ association :user, :admin, name: 'Joe Slick'
704
+ end
705
+
706
+ factory :order do
707
+ association :creator, :admin, factory: :user, name: 'Joe Creator'
708
+ end
692
709
  end
693
710
  end
694
711
 
@@ -697,4 +714,16 @@ describe "traits used in associations" do
697
714
  author.should be_admin
698
715
  author.name.should == 'John Doe'
699
716
  end
717
+
718
+ it "allows inline traits with the default association" do
719
+ user = FactoryGirl.create(:comment).user
720
+ user.should be_admin
721
+ user.name.should == 'Joe Slick'
722
+ end
723
+
724
+ it "allows inline traits with a specific factory for an association" do
725
+ creator = FactoryGirl.create(:order).creator
726
+ creator.should be_admin
727
+ creator.name.should == 'Joe Creator'
728
+ end
700
729
  end
@@ -49,6 +49,13 @@ module DeclarationMatchers
49
49
  self
50
50
  end
51
51
 
52
+ def failure_message
53
+ [
54
+ "expected declarations to include declaration of type #{@declaration_type}",
55
+ @options ? "with options #{options}" : nil
56
+ ].compact.join ' '
57
+ end
58
+
52
59
  private
53
60
 
54
61
  def expected_declaration
@@ -56,7 +63,12 @@ module DeclarationMatchers
56
63
  when :static then FactoryGirl::Declaration::Static.new(@name, @value, ignored?)
57
64
  when :dynamic then FactoryGirl::Declaration::Dynamic.new(@name, ignored?, @value)
58
65
  when :implicit then FactoryGirl::Declaration::Implicit.new(@name, @factory, ignored?)
59
- when :association then FactoryGirl::Declaration::Association.new(@name, options)
66
+ when :association
67
+ if @options
68
+ FactoryGirl::Declaration::Association.new(@name, options)
69
+ else
70
+ FactoryGirl::Declaration::Association.new(@name)
71
+ end
60
72
  end
61
73
  end
62
74
 
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: 3.6.0
4
+ version: 3.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-27 00:00:00.000000000 Z
13
+ date: 2012-08-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport