factory_girl 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,12 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
+ - jruby-19mode
4
5
  before_install:
5
6
  - gem update --system
6
7
  script: "bundle exec rake spec:unit spec:acceptance features"
8
+ jdk:
9
+ - openjdk6
7
10
  gemfile:
8
11
  - gemfiles/3.0.gemfile
9
12
  - gemfiles/3.1.gemfile
@@ -16,6 +16,13 @@ If you're *not* using Rails, you'll just have to change the required version of
16
16
  gem "factory_girl", "~> 3.0"
17
17
  ```
18
18
 
19
+ JRuby users: FactoryGirl works with JRuby starting with 1.6.7.2 (latest stable, as per July 2012).
20
+ JRuby has to be used in 1.9 mode, for that, use JRUBY_OPTS environment variable:
21
+
22
+ ```
23
+ export JRUBY_OPTS=--1.9
24
+ ```
25
+
19
26
  Once your Gemfile is updated, you'll want to update your bundle.
20
27
 
21
28
  Using Without Bundler
@@ -141,7 +148,9 @@ end
141
148
  World(FactoryGirl::Syntax::Methods)
142
149
  ```
143
150
 
144
- This would allow you to write:
151
+ This allows you to use the core set of syntax methods (`build`,
152
+ `build_stubbed`, `create`, `attributes_for`, and their `*_list` counterparts)
153
+ without having to call them on FactoryGirl directly:
145
154
 
146
155
  ```ruby
147
156
  describe User, "#full_name" do
@@ -258,8 +267,8 @@ Static and dynamic attributes can be ignored. Ignored attributes will be ignored
258
267
  within attributes\_for and won't be set on the model, even if the attribute
259
268
  exists or you attempt to override it.
260
269
 
261
- Within Factory Girl's dynamic attributes, you can access ignored attributes as
262
- you would expect. If you need to access the evaluator in a Factory Girl callback,
270
+ Within FactoryGirl's dynamic attributes, you can access ignored attributes as
271
+ you would expect. If you need to access the evaluator in a FactoryGirl callback,
263
272
  you'll need to declare a second block argument (for the evaluator) and access
264
273
  ignored attributes from there.
265
274
 
@@ -690,7 +699,7 @@ Instead of creating a child factory that added additional attributes:
690
699
  ```ruby
691
700
  FactoryGirl.define do
692
701
  factory :application_user, parent: :user do
693
- full_name { Faker::Name.name }
702
+ full_name "Jane Doe"
694
703
  date_of_birth { 21.years.ago }
695
704
  gender "Female"
696
705
  health 90
@@ -703,7 +712,7 @@ You could modify that factory instead.
703
712
  ```ruby
704
713
  FactoryGirl.modify do
705
714
  factory :user do
706
- full_name { Faker::Name.name }
715
+ full_name "Jane Doe"
707
716
  date_of_birth { 21.years.ago }
708
717
  gender "Female"
709
718
  health 90
@@ -758,14 +767,14 @@ sequence(:name) {|n| "person#{n}@example.com" }
758
767
 
759
768
  factory :user do
760
769
  ignore do
761
- name { Faker::Name.name }
770
+ name "Jane Doe"
762
771
  end
763
772
 
764
773
  email
765
774
  initialize_with { new(name) }
766
775
  end
767
776
 
768
- FactoryGirl.build(:user).name # Bob Hope
777
+ FactoryGirl.build(:user).name # Jane Doe
769
778
  ```
770
779
 
771
780
  Notice that I ignored the `name` attribute. If you don't want attributes
@@ -793,7 +802,7 @@ For example:
793
802
  ```ruby
794
803
  factory :user do
795
804
  ignore do
796
- name { Faker::Name.name }
805
+ name "John Doe"
797
806
  end
798
807
 
799
808
  initialize_with { User.build_with_name(name) }
@@ -809,7 +818,7 @@ factory :user do
809
818
  comments_count 5
810
819
  end
811
820
 
812
- name { Faker::Name.name }
821
+ name "John Doe"
813
822
 
814
823
  initialize_with { new(attributes) }
815
824
  end
@@ -1005,6 +1014,9 @@ factory\_girl ships with step definitions that make calling factories from Cucum
1005
1014
  require "factory_girl/step_definitions"
1006
1015
  ```
1007
1016
 
1017
+ Note: These step definitions are _deprecated_. Read why here:
1018
+ http://robots.thoughtbot.com/post/25650434584/writing-better-cucumber-scenarios-or-why-were
1019
+
1008
1020
  Alternate Syntaxes
1009
1021
  ------------------
1010
1022
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (3.5.0)
4
+ factory_girl (3.6.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -27,7 +27,6 @@ GEM
27
27
  cucumber (>= 1.1.1)
28
28
  ffi (>= 1.0.11)
29
29
  rspec (>= 2.7.0)
30
- bluecloth (2.2.0)
31
30
  bourne (1.1.2)
32
31
  mocha (= 0.10.5)
33
32
  builder (3.0.0)
@@ -41,10 +40,14 @@ GEM
41
40
  term-ansicolor (>= 1.0.6)
42
41
  diff-lcs (1.1.3)
43
42
  ffi (1.0.11)
43
+ ffi (1.0.11-java)
44
44
  gherkin (2.9.3)
45
45
  json (>= 1.4.6)
46
+ gherkin (2.9.3-java)
47
+ json (>= 1.4.6)
46
48
  i18n (0.6.0)
47
49
  json (1.7.0)
50
+ json (1.7.0-java)
48
51
  metaclass (0.0.1)
49
52
  mocha (0.10.5)
50
53
  metaclass (~> 0.0.1)
@@ -71,13 +74,13 @@ GEM
71
74
  yard (0.8.1)
72
75
 
73
76
  PLATFORMS
77
+ java
74
78
  ruby
75
79
 
76
80
  DEPENDENCIES
77
81
  activerecord
78
82
  appraisal (~> 0.4)
79
83
  aruba
80
- bluecloth
81
84
  bourne
82
85
  cucumber (~> 1.1)
83
86
  factory_girl!
data/NEWS CHANGED
@@ -1,3 +1,12 @@
1
+ 3.6.0 (July 27, 2012)
2
+ Code/spec cleanup
3
+ Allow factories with traits to be used in associations
4
+ Refactor Factory to use DefinitionHierarchy to handle managing callbacks,
5
+ custom constructor, and custom to_create
6
+ Add memoization to speed up factories providing attribute overrides
7
+ Add initial support of JRuby when running in 1.9 mode
8
+ Improve docs on what happens when including FactoryGirl::Syntax::Methods
9
+
1
10
  3.5.0 (June 22, 2012)
2
11
  Allow created_at to be set when using build_stubbed
3
12
  Deprecate FactoryGirl step definitions
@@ -104,14 +113,14 @@
104
113
  Fix inline traits
105
114
 
106
115
  2.4.0 (January 13, 2012)
107
- Refactor internals of Factory Girl to use anonymous class on which attributes
116
+ Refactor internals of FactoryGirl to use anonymous class on which attributes
108
117
  get defined
109
118
  Explicitly require Ruby 1.8.7 or higher in gemspec
110
119
  Fix documentation
111
120
  Add Gemnasium status to documentation
112
121
  Supplying a Class to a factory that overrides to_s no longer results in
113
122
  getting the wrong Class constructed
114
- Be more agnostic about ORMs when using columns in Factory Girl step
123
+ Be more agnostic about ORMs when using columns in FactoryGirl step
115
124
  definitions
116
125
  Test against Active Record 3.2.0.rc2
117
126
  Update GETTING_STARTED to use Ruby syntax highlighting
data/README.md CHANGED
@@ -28,9 +28,9 @@ and run `bundle install` from your shell.
28
28
  Supported Ruby versions
29
29
  -----------------------
30
30
 
31
- The Factory Girl 3.x series supports Ruby 1.9.x.
31
+ The FactoryGirl 3.x series supports Ruby 1.9.x.
32
32
 
33
- For older versions of Ruby, please use the Factory Girl 2.x series.
33
+ For older versions of Ruby, please use the FactoryGirl 2.x series.
34
34
 
35
35
  More Information
36
36
  ----------------
@@ -31,8 +31,14 @@ Gem::Specification.new do |s|
31
31
  s.add_development_dependency("mocha")
32
32
  s.add_development_dependency("bourne")
33
33
  s.add_development_dependency("appraisal", "~> 0.4")
34
- s.add_development_dependency("sqlite3-ruby")
34
+
35
+ if RUBY_PLATFORM == "java"
36
+ s.add_development_dependency("activerecord-jdbcsqlite3-adapter")
37
+ s.add_development_dependency("jdbc-sqlite3")
38
+ else
39
+ s.add_development_dependency("sqlite3-ruby")
40
+ end
41
+
35
42
  s.add_development_dependency("yard")
36
- s.add_development_dependency("bluecloth")
37
43
  end
38
44
 
@@ -207,7 +207,7 @@ Feature: Use step definitions generated by factories
207
207
  | id | name |
208
208
  | 123 | Joe |
209
209
 
210
- Scenario: pass a factory girl table as an argument and modify it
210
+ Scenario: pass a FactoryGirl table as an argument and modify it
211
211
  Given these super users exist:
212
212
  | id | Name |
213
213
  | 123 | Joe |
@@ -1,4 +1,4 @@
1
- Feature: Factory girl can find factory definitions correctly
1
+ Feature: FactoryGirl can find factory definitions correctly
2
2
  Scenario: Find definitions with a path
3
3
  Given a file named "awesome_factories.rb" with:
4
4
  """
@@ -8,8 +8,8 @@ Feature: Factory girl can find factory definitions correctly
8
8
  end
9
9
  end
10
10
  """
11
- When "awesome_factories.rb" is added to Factory Girl's file definitions path
12
- And I create a "awesome_category" instance from Factory Girl
11
+ When "awesome_factories.rb" is added to FactoryGirl's file definitions path
12
+ And I create a "awesome_category" instance from FactoryGirl
13
13
  Then I should find the following for the last category:
14
14
  | name |
15
15
  | awesome!!! |
@@ -23,8 +23,8 @@ Feature: Factory girl can find factory definitions correctly
23
23
  end
24
24
  end
25
25
  """
26
- When "awesome_factories.rb" is added to Factory Girl's file definitions path as an absolute path
27
- And I create a "another_awesome_category" instance from Factory Girl
26
+ When "awesome_factories.rb" is added to FactoryGirl's file definitions path as an absolute path
27
+ And I create a "another_awesome_category" instance from FactoryGirl
28
28
  Then I should find the following for the last category:
29
29
  | name |
30
30
  | awesome!!! |
@@ -38,13 +38,13 @@ Feature: Factory girl can find factory definitions correctly
38
38
  end
39
39
  end
40
40
  """
41
- When "nested" is added to Factory Girl's file definitions path
42
- And I create a "great_category" instance from Factory Girl
41
+ When "nested" is added to FactoryGirl's file definitions path
42
+ And I create a "great_category" instance from FactoryGirl
43
43
  Then I should find the following for the last category:
44
44
  | name |
45
45
  | great!!! |
46
46
 
47
- Scenario: Reload Factory Girl
47
+ Scenario: Reload FactoryGirl
48
48
  Given a file named "nested/reload_factories.rb" with:
49
49
  """
50
50
  FactoryGirl.define do
@@ -58,7 +58,7 @@ Feature: Factory girl can find factory definitions correctly
58
58
  end
59
59
  end
60
60
  """
61
- When "nested" is added to Factory Girl's file definitions path
61
+ When "nested" is added to FactoryGirl's file definitions path
62
62
  And I append to "nested/reload_factories.rb" with:
63
63
  """
64
64
 
@@ -69,7 +69,7 @@ Feature: Factory girl can find factory definitions correctly
69
69
  end
70
70
  """
71
71
  And I reload factories
72
- And I create a "handy_category" instance from Factory Girl
72
+ And I create a "handy_category" instance from FactoryGirl
73
73
  Then I should find the following for the last category:
74
74
  | name |
75
75
  | HANDY!!! |
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  World(FactoryGirlDefinitionsHelper)
9
9
 
10
- When /^"([^"]*)" is added to Factory Girl's file definitions path$/ do |file_name|
10
+ When /^"([^"]*)" is added to FactoryGirl's file definitions path$/ do |file_name|
11
11
  new_factory_file = File.join(current_dir, file_name.gsub(".rb", ""))
12
12
 
13
13
  append_file_to_factory_girl_definitions_path(new_factory_file)
@@ -15,7 +15,7 @@ When /^"([^"]*)" is added to Factory Girl's file definitions path$/ do |file_nam
15
15
  step %{I find definitions}
16
16
  end
17
17
 
18
- When /^"([^"]*)" is added to Factory Girl's file definitions path as an absolute path$/ do |file_name|
18
+ When /^"([^"]*)" is added to FactoryGirl's file definitions path as an absolute path$/ do |file_name|
19
19
  new_factory_file = File.expand_path(File.join(current_dir, file_name.gsub(".rb", "")))
20
20
 
21
21
  append_file_to_factory_girl_definitions_path(new_factory_file)
@@ -23,7 +23,7 @@ When /^"([^"]*)" is added to Factory Girl's file definitions path as an absolute
23
23
  step %{I find definitions}
24
24
  end
25
25
 
26
- When /^I create a "([^"]*)" instance from Factory Girl$/ do |factory_name|
26
+ When /^I create a "([^"]*)" instance from FactoryGirl$/ do |factory_name|
27
27
  FactoryGirl.create(factory_name)
28
28
  end
29
29
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.5.0)
4
+ factory_girl (3.6.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -26,7 +26,6 @@ GEM
26
26
  cucumber (>= 1.1.1)
27
27
  ffi (>= 1.0.11)
28
28
  rspec (>= 2.7.0)
29
- bluecloth (2.2.0)
30
29
  bourne (1.1.2)
31
30
  mocha (= 0.10.5)
32
31
  builder (2.1.2)
@@ -40,10 +39,14 @@ GEM
40
39
  term-ansicolor (>= 1.0.6)
41
40
  diff-lcs (1.1.3)
42
41
  ffi (1.0.11)
42
+ ffi (1.0.11-java)
43
43
  gherkin (2.9.3)
44
44
  json (>= 1.4.6)
45
+ gherkin (2.9.3-java)
46
+ json (>= 1.4.6)
45
47
  i18n (0.5.0)
46
48
  json (1.7.0)
49
+ json (1.7.0-java)
47
50
  metaclass (0.0.1)
48
51
  mocha (0.10.5)
49
52
  metaclass (~> 0.0.1)
@@ -70,13 +73,13 @@ GEM
70
73
  yard (0.8.1)
71
74
 
72
75
  PLATFORMS
76
+ java
73
77
  ruby
74
78
 
75
79
  DEPENDENCIES
76
80
  activerecord (~> 3.0.0)
77
81
  appraisal (~> 0.4)
78
82
  aruba
79
- bluecloth
80
83
  bourne
81
84
  cucumber (~> 1.1)
82
85
  factory_girl!
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.5.0)
4
+ factory_girl (3.6.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -27,7 +27,6 @@ GEM
27
27
  cucumber (>= 1.1.1)
28
28
  ffi (>= 1.0.11)
29
29
  rspec (>= 2.7.0)
30
- bluecloth (2.2.0)
31
30
  bourne (1.1.2)
32
31
  mocha (= 0.10.5)
33
32
  builder (3.0.0)
@@ -41,10 +40,14 @@ GEM
41
40
  term-ansicolor (>= 1.0.6)
42
41
  diff-lcs (1.1.3)
43
42
  ffi (1.0.11)
43
+ ffi (1.0.11-java)
44
44
  gherkin (2.9.3)
45
45
  json (>= 1.4.6)
46
+ gherkin (2.9.3-java)
47
+ json (>= 1.4.6)
46
48
  i18n (0.6.0)
47
49
  json (1.7.0)
50
+ json (1.7.0-java)
48
51
  metaclass (0.0.1)
49
52
  mocha (0.10.5)
50
53
  metaclass (~> 0.0.1)
@@ -71,13 +74,13 @@ GEM
71
74
  yard (0.8.1)
72
75
 
73
76
  PLATFORMS
77
+ java
74
78
  ruby
75
79
 
76
80
  DEPENDENCIES
77
81
  activerecord (~> 3.1.0)
78
82
  appraisal (~> 0.4)
79
83
  aruba
80
- bluecloth
81
84
  bourne
82
85
  cucumber (~> 1.1)
83
86
  factory_girl!
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.5.0)
4
+ factory_girl (3.6.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -27,7 +27,6 @@ GEM
27
27
  cucumber (>= 1.1.1)
28
28
  ffi (>= 1.0.11)
29
29
  rspec (>= 2.7.0)
30
- bluecloth (2.2.0)
31
30
  bourne (1.1.2)
32
31
  mocha (= 0.10.5)
33
32
  builder (3.0.0)
@@ -41,10 +40,14 @@ GEM
41
40
  term-ansicolor (>= 1.0.6)
42
41
  diff-lcs (1.1.3)
43
42
  ffi (1.0.11)
43
+ ffi (1.0.11-java)
44
44
  gherkin (2.9.3)
45
45
  json (>= 1.4.6)
46
+ gherkin (2.9.3-java)
47
+ json (>= 1.4.6)
46
48
  i18n (0.6.0)
47
49
  json (1.7.0)
50
+ json (1.7.0-java)
48
51
  metaclass (0.0.1)
49
52
  mocha (0.10.5)
50
53
  metaclass (~> 0.0.1)
@@ -71,13 +74,13 @@ GEM
71
74
  yard (0.8.1)
72
75
 
73
76
  PLATFORMS
77
+ java
74
78
  ruby
75
79
 
76
80
  DEPENDENCIES
77
81
  activerecord (~> 3.2.0)
78
82
  appraisal (~> 0.4)
79
83
  aruba
80
- bluecloth
81
84
  bourne
82
85
  cucumber (~> 1.1)
83
86
  factory_girl!
@@ -2,6 +2,7 @@ require 'set'
2
2
  require 'active_support/core_ext/module/delegation'
3
3
  require 'active_support/notifications'
4
4
 
5
+ require 'factory_girl/definition_hierarchy'
5
6
  require 'factory_girl/configuration'
6
7
  require 'factory_girl/errors'
7
8
  require 'factory_girl/factory_runner'
@@ -41,6 +42,7 @@ require 'factory_girl/decorator/class_key_hash'
41
42
  require 'factory_girl/decorator/disallows_duplicates_registry'
42
43
  require 'factory_girl/decorator/invocation_tracker'
43
44
  require 'factory_girl/decorator/invocation_ignorer'
45
+ require 'factory_girl/decorator/new_constructor'
44
46
  require 'factory_girl/version'
45
47
 
46
48
  module FactoryGirl
@@ -13,7 +13,10 @@ module FactoryGirl
13
13
  def to_proc
14
14
  factory = @factory
15
15
  overrides = @overrides
16
- -> { association(factory, overrides) }
16
+ traits_and_overrides = [factory, overrides].flatten
17
+ factory_name = traits_and_overrides.shift
18
+
19
+ -> { association(factory_name, *traits_and_overrides) }
17
20
  end
18
21
 
19
22
  def association?
@@ -31,7 +31,13 @@ module FactoryGirl
31
31
  private
32
32
 
33
33
  def method_tracking_evaluator
34
- @method_tracking_evaluator ||= Decorator::AttributeHash.new(invocation_decorator.new(@evaluator), attribute_names_to_assign)
34
+ @method_tracking_evaluator ||= Decorator::AttributeHash.new(decorated_evaluator, attribute_names_to_assign)
35
+ end
36
+
37
+ def decorated_evaluator
38
+ invocation_decorator.new(
39
+ Decorator::NewConstructor.new(@evaluator, @build_class)
40
+ )
35
41
  end
36
42
 
37
43
  def invocation_decorator
@@ -71,7 +77,7 @@ module FactoryGirl
71
77
  end
72
78
 
73
79
  def attribute_names_to_assign
74
- non_ignored_attribute_names + override_names - ignored_attribute_names - alias_names_to_ignore
80
+ @attribute_names_to_assign ||= non_ignored_attribute_names + override_names - ignored_attribute_names - alias_names_to_ignore
75
81
  end
76
82
 
77
83
  def non_ignored_attribute_names
@@ -5,7 +5,7 @@ module FactoryGirl
5
5
  def initialize(name, block)
6
6
  @name = name.to_sym
7
7
  @block = block
8
- check_name
8
+ ensure_valid_callback_name!
9
9
  end
10
10
 
11
11
  def run(instance, evaluator)
@@ -26,7 +26,7 @@ module FactoryGirl
26
26
 
27
27
  private
28
28
 
29
- def check_name
29
+ def ensure_valid_callback_name!
30
30
  unless FactoryGirl.callback_names.include?(name)
31
31
  raise InvalidCallbackNameError, "#{name} is not a valid callback name. " +
32
32
  "Valid callback names are #{FactoryGirl.callback_names.inspect}"
@@ -0,0 +1,12 @@
1
+ module FactoryGirl
2
+ class Decorator
3
+ class NewConstructor < Decorator
4
+ def initialize(component, build_class)
5
+ super(component)
6
+ @build_class = build_class
7
+ end
8
+
9
+ delegate :new, to: :@build_class
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ module FactoryGirl
2
+ class DefinitionHierarchy
3
+ def callbacks
4
+ []
5
+ end
6
+
7
+ def constructor
8
+ FactoryGirl.constructor
9
+ end
10
+
11
+ def to_create
12
+ FactoryGirl.to_create
13
+ end
14
+
15
+ def self.add_callbacks(callbacks)
16
+ if callbacks.any?
17
+ define_method :callbacks do
18
+ super() + callbacks
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.build_constructor(&block)
24
+ if block
25
+ define_method(:constructor) do
26
+ block
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.build_to_create(&block)
32
+ if block
33
+ define_method(:to_create) do
34
+ block
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -10,8 +10,7 @@ module FactoryGirl
10
10
  undef_method(method) unless method =~ /^__|initialize/
11
11
  end
12
12
 
13
- def initialize(build_class, build_strategy, overrides = {})
14
- @build_class = build_class
13
+ def initialize(build_strategy, overrides = {})
15
14
  @build_strategy = build_strategy
16
15
  @overrides = overrides
17
16
  @cached_attributes = overrides
@@ -21,12 +20,13 @@ module FactoryGirl
21
20
  end
22
21
  end
23
22
 
24
- delegate :new, to: :@build_class
25
-
26
- def association(factory_name, overrides = {})
23
+ def association(factory_name, *traits_and_overrides)
24
+ overrides = traits_and_overrides.extract_options!
27
25
  strategy_override = overrides.fetch(:strategy) { :create }
28
26
 
29
- runner = FactoryRunner.new(factory_name, strategy_override, [overrides.except(:strategy)])
27
+ traits_and_overrides += [overrides.except(:strategy)]
28
+
29
+ runner = FactoryRunner.new(factory_name, strategy_override, traits_and_overrides)
30
30
  @build_strategy.association(runner)
31
31
  end
32
32
 
@@ -33,7 +33,7 @@ module FactoryGirl
33
33
 
34
34
  strategy = StrategyCalculator.new(build_strategy).strategy.new
35
35
 
36
- evaluator = evaluator_class.new(build_class, strategy, overrides.symbolize_keys)
36
+ evaluator = evaluator_class.new(strategy, overrides.symbolize_keys)
37
37
  attribute_assigner = AttributeAssigner.new(evaluator, build_class, &compiled_constructor)
38
38
 
39
39
  evaluation = Evaluation.new(attribute_assigner, compiled_to_create)
@@ -84,6 +84,7 @@ module FactoryGirl
84
84
  parent.compile
85
85
  parent.defined_traits.each {|trait| define_trait(trait) }
86
86
  @definition.compile
87
+ build_hierarchy
87
88
  @compiled = true
88
89
  end
89
90
  end
@@ -111,16 +112,30 @@ module FactoryGirl
111
112
  end
112
113
  end
113
114
 
115
+ def hierarchy_class
116
+ @hierarchy_class ||= Class.new(parent.hierarchy_class)
117
+ end
118
+
119
+ def hierarchy_instance
120
+ @hierarchy_instance ||= hierarchy_class.new
121
+ end
122
+
123
+ def build_hierarchy
124
+ hierarchy_class.build_to_create &definition.to_create
125
+ hierarchy_class.build_constructor &definition.constructor
126
+ hierarchy_class.add_callbacks definition.callbacks
127
+ end
128
+
114
129
  def callbacks
115
- parent.callbacks + definition.callbacks
130
+ hierarchy_instance.callbacks
116
131
  end
117
132
 
118
133
  def compiled_to_create
119
- @definition.to_create || parent.compiled_to_create || FactoryGirl.to_create
134
+ hierarchy_instance.to_create
120
135
  end
121
136
 
122
137
  def compiled_constructor
123
- @definition.constructor || parent.compiled_constructor || FactoryGirl.constructor
138
+ hierarchy_instance.constructor
124
139
  end
125
140
 
126
141
  private
@@ -141,6 +156,9 @@ module FactoryGirl
141
156
  super
142
157
  @definition = @definition.clone
143
158
  @evaluator_class = nil
159
+ @hierarchy_class = nil
160
+ @hierarchy_instance = nil
161
+ @compiled = false
144
162
  end
145
163
  end
146
164
  end
@@ -10,10 +10,9 @@ module FactoryGirl
10
10
  delegate :defined_traits, :callbacks, :attributes, :constructor,
11
11
  :to_create, to: :definition
12
12
 
13
- def compiled_to_create; to_create; end
14
- def compiled_constructor; constructor; end
15
13
  def compile; end
16
14
  def class_name; end
17
15
  def evaluator_class; FactoryGirl::Evaluator; end
16
+ def hierarchy_class; FactoryGirl::DefinitionHierarchy; end
18
17
  end
19
18
  end
@@ -16,5 +16,9 @@ module FactoryGirl
16
16
  def respond_to?(method, include_private=false)
17
17
  @methods_to_respond_to.include? method.to_s
18
18
  end
19
+
20
+ def respond_to_missing?(*args)
21
+ false
22
+ end
19
23
  end
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '3.5.0'
2
+ VERSION = '3.6.0'
3
3
  end
@@ -118,8 +118,6 @@ describe "defaulting `created_at`" do
118
118
  Timecop.freeze Time.now
119
119
  end
120
120
 
121
- after { Timecop.return }
122
-
123
121
  it "defaults created_at for objects with created_at" do
124
122
  build_stubbed(:thing_with_timestamp).created_at.should == Time.now
125
123
  end
@@ -669,3 +669,32 @@ describe "implicit traits containing callbacks" do
669
669
  FactoryGirl.build(:user_with_trait_with_callback).value.should == 1
670
670
  end
671
671
  end
672
+
673
+ describe "traits used in associations" do
674
+ before do
675
+ define_model("User", admin: :boolean, name: :string)
676
+ define_model("Post", author_id: :integer) do
677
+ belongs_to :author, class_name: 'User'
678
+ end
679
+
680
+ FactoryGirl.define do
681
+ factory :user do
682
+ admin false
683
+
684
+ trait :admin do
685
+ admin true
686
+ end
687
+ end
688
+
689
+ factory :post do
690
+ association :author, factory: [:user, :admin], name: 'John Doe'
691
+ end
692
+ end
693
+ end
694
+
695
+ it "allows assigning traits for the factory of an association" do
696
+ author = FactoryGirl.create(:post).author
697
+ author.should be_admin
698
+ author.name.should == 'John Doe'
699
+ end
700
+ end
@@ -7,7 +7,7 @@ describe FactoryGirl::EvaluatorClassDefiner do
7
7
 
8
8
  let(:attributes) { [simple_attribute, relative_attribute, attribute_that_raises_a_second_time] }
9
9
  let(:class_definer) { FactoryGirl::EvaluatorClassDefiner.new(attributes, FactoryGirl::Evaluator) }
10
- let(:evaluator) { class_definer.evaluator_class.new(Object, stub("build strategy", add_observer: true)) }
10
+ let(:evaluator) { class_definer.evaluator_class.new(stub("build strategy", add_observer: true)) }
11
11
 
12
12
  it "returns an evaluator when accessing the evaluator class" do
13
13
  evaluator.should be_a(FactoryGirl::Evaluator)
@@ -7,7 +7,6 @@ describe FactoryGirl::Strategy::Stub do
7
7
 
8
8
  context "asking for a result" do
9
9
  before { Timecop.freeze(Time.now) }
10
- after { Timecop.return }
11
10
  let(:result_instance) do
12
11
  define_class("ResultInstance") do
13
12
  attr_accessor :id
@@ -20,6 +20,7 @@ RSpec.configure do |config|
20
20
  config.include DeclarationMatchers
21
21
 
22
22
  config.after do
23
+ Timecop.return
23
24
  FactoryGirl.reload
24
25
  end
25
26
  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: 3.5.0
4
+ version: 3.6.0
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-06-22 00:00:00.000000000 Z
13
+ date: 2012-07-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -188,22 +188,6 @@ dependencies:
188
188
  - - ! '>='
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
- - !ruby/object:Gem::Dependency
192
- name: bluecloth
193
- requirement: !ruby/object:Gem::Requirement
194
- none: false
195
- requirements:
196
- - - ! '>='
197
- - !ruby/object:Gem::Version
198
- version: '0'
199
- type: :development
200
- prerelease: false
201
- version_requirements: !ruby/object:Gem::Requirement
202
- none: false
203
- requirements:
204
- - - ! '>='
205
- - !ruby/object:Gem::Version
206
- version: '0'
207
191
  description: ! "factory_girl provides a framework and DSL for defining and\n using
208
192
  factories - less error-prone, more explicit, and\n all-around
209
193
  easier to work with than fixtures."
@@ -267,7 +251,9 @@ files:
267
251
  - lib/factory_girl/decorator/disallows_duplicates_registry.rb
268
252
  - lib/factory_girl/decorator/invocation_ignorer.rb
269
253
  - lib/factory_girl/decorator/invocation_tracker.rb
254
+ - lib/factory_girl/decorator/new_constructor.rb
270
255
  - lib/factory_girl/definition.rb
256
+ - lib/factory_girl/definition_hierarchy.rb
271
257
  - lib/factory_girl/definition_proxy.rb
272
258
  - lib/factory_girl/errors.rb
273
259
  - lib/factory_girl/evaluation.rb