factory_girl 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/Appraisals +7 -3
  2. data/GETTING_STARTED.md +28 -4
  3. data/Gemfile.lock +28 -32
  4. data/LICENSE +1 -1
  5. data/NEWS +11 -0
  6. data/README.md +2 -2
  7. data/factory_girl.gemspec +5 -5
  8. data/features/step_definitions/database_steps.rb +1 -1
  9. data/gemfiles/3.0.gemfile +1 -1
  10. data/gemfiles/3.0.gemfile.lock +40 -48
  11. data/gemfiles/3.1.gemfile +1 -1
  12. data/gemfiles/3.1.gemfile.lock +41 -49
  13. data/gemfiles/3.2.gemfile +1 -1
  14. data/gemfiles/3.2.gemfile.lock +42 -50
  15. data/gemfiles/4.0.gemfile +7 -0
  16. data/gemfiles/4.0.gemfile.lock +95 -0
  17. data/lib/factory_girl/definition_hierarchy.rb +9 -0
  18. data/lib/factory_girl/definition_proxy.rb +1 -1
  19. data/lib/factory_girl/evaluator.rb +11 -2
  20. data/lib/factory_girl/factory.rb +1 -3
  21. data/lib/factory_girl/sequence.rb +17 -3
  22. data/lib/factory_girl/strategy/stub.rb +2 -2
  23. data/lib/factory_girl/strategy_syntax_method_registrar.rb +2 -2
  24. data/lib/factory_girl/version.rb +1 -1
  25. data/spec/acceptance/activesupport_instrumentation_spec.rb +3 -3
  26. data/spec/acceptance/aliases_spec.rb +1 -1
  27. data/spec/acceptance/attribute_aliases_spec.rb +3 -3
  28. data/spec/acceptance/attribute_existing_on_object_spec.rb +8 -8
  29. data/spec/acceptance/attributes_for_spec.rb +11 -9
  30. data/spec/acceptance/attributes_from_instance_spec.rb +7 -7
  31. data/spec/acceptance/attributes_ordered_spec.rb +6 -6
  32. data/spec/acceptance/build_list_spec.rb +20 -5
  33. data/spec/acceptance/build_spec.rb +10 -13
  34. data/spec/acceptance/build_stubbed_spec.rb +38 -13
  35. data/spec/acceptance/callbacks_spec.rb +19 -19
  36. data/spec/acceptance/create_list_spec.rb +22 -7
  37. data/spec/acceptance/create_spec.rb +10 -11
  38. data/spec/acceptance/define_child_before_parent_spec.rb +1 -1
  39. data/spec/acceptance/definition_spec.rb +2 -7
  40. data/spec/acceptance/definition_without_block_spec.rb +1 -1
  41. data/spec/acceptance/global_initialize_with_spec.rb +10 -10
  42. data/spec/acceptance/global_to_create_spec.rb +18 -18
  43. data/spec/acceptance/initialize_with_spec.rb +13 -13
  44. data/spec/acceptance/keyed_by_class_spec.rb +2 -2
  45. data/spec/acceptance/modify_factories_spec.rb +21 -21
  46. data/spec/acceptance/modify_inherited_spec.rb +7 -7
  47. data/spec/acceptance/nested_attributes_spec.rb +2 -2
  48. data/spec/acceptance/overrides_spec.rb +1 -1
  49. data/spec/acceptance/parent_spec.rb +9 -9
  50. data/spec/acceptance/register_strategies_spec.rb +9 -9
  51. data/spec/acceptance/sequence_context_spec.rb +52 -0
  52. data/spec/acceptance/sequence_spec.rb +12 -12
  53. data/spec/acceptance/skip_create_spec.rb +1 -1
  54. data/spec/acceptance/stub_spec.rb +4 -4
  55. data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +5 -5
  56. data/spec/acceptance/traits_spec.rb +84 -84
  57. data/spec/acceptance/transient_attributes_spec.rb +13 -13
  58. data/spec/factory_girl/attribute/association_spec.rb +4 -4
  59. data/spec/factory_girl/attribute/dynamic_spec.rb +5 -5
  60. data/spec/factory_girl/attribute/sequence_spec.rb +2 -2
  61. data/spec/factory_girl/attribute/static_spec.rb +3 -3
  62. data/spec/factory_girl/attribute_list_spec.rb +12 -12
  63. data/spec/factory_girl/attribute_spec.rb +1 -1
  64. data/spec/factory_girl/callback_spec.rb +5 -5
  65. data/spec/factory_girl/declaration/implicit_spec.rb +1 -1
  66. data/spec/factory_girl/declaration_list_spec.rb +11 -11
  67. data/spec/factory_girl/definition_proxy_spec.rb +21 -21
  68. data/spec/factory_girl/definition_spec.rb +6 -6
  69. data/spec/factory_girl/disallows_duplicates_registry_spec.rb +1 -1
  70. data/spec/factory_girl/evaluator_class_definer_spec.rb +54 -21
  71. data/spec/factory_girl/factory_spec.rb +34 -34
  72. data/spec/factory_girl/null_factory_spec.rb +1 -1
  73. data/spec/factory_girl/null_object_spec.rb +3 -3
  74. data/spec/factory_girl/registry_spec.rb +12 -12
  75. data/spec/factory_girl/sequence_spec.rb +34 -17
  76. data/spec/factory_girl/strategy/attributes_for_spec.rb +1 -1
  77. data/spec/factory_girl/strategy/create_spec.rb +1 -1
  78. data/spec/factory_girl/strategy/stub_spec.rb +4 -4
  79. data/spec/factory_girl/strategy_calculator_spec.rb +3 -3
  80. data/spec/factory_girl_spec.rb +3 -3
  81. data/spec/spec_helper.rb +1 -1
  82. data/spec/support/macros/define_constant.rb +2 -2
  83. data/spec/support/shared_examples/strategy.rb +7 -7
  84. metadata +17 -11
data/gemfiles/3.2.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2.0"
5
+ gem "activerecord", "~> 3.2.11"
6
6
 
7
7
  gemspec :path=>"../"
@@ -1,36 +1,35 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (4.1.0)
4
+ factory_girl (4.2.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.7)
11
- activesupport (= 3.2.7)
10
+ activemodel (3.2.11)
11
+ activesupport (= 3.2.11)
12
12
  builder (~> 3.0.0)
13
- activerecord (3.2.7)
14
- activemodel (= 3.2.7)
15
- activesupport (= 3.2.7)
13
+ activerecord (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
16
  arel (~> 3.0.2)
17
17
  tzinfo (~> 0.3.29)
18
- activesupport (3.2.7)
18
+ activesupport (3.2.11)
19
19
  i18n (~> 0.6)
20
20
  multi_json (~> 1.0)
21
- appraisal (0.4.1)
21
+ appraisal (0.5.1)
22
22
  bundler
23
23
  rake
24
24
  arel (3.0.2)
25
- aruba (0.4.11)
26
- childprocess (>= 0.2.3)
25
+ aruba (0.5.1)
26
+ childprocess (~> 0.3.6)
27
27
  cucumber (>= 1.1.1)
28
- ffi (>= 1.0.11)
29
- rspec (>= 2.7.0)
30
- bourne (1.1.2)
31
- mocha (= 0.10.5)
32
- builder (3.0.0)
33
- childprocess (0.3.4)
28
+ rspec-expectations (>= 2.7.0)
29
+ bourne (1.3.0)
30
+ mocha (= 0.13.0)
31
+ builder (3.0.4)
32
+ childprocess (0.3.6)
34
33
  ffi (~> 1.0, >= 1.0.6)
35
34
  cucumber (1.2.1)
36
35
  builder (>= 2.1.2)
@@ -38,53 +37,46 @@ GEM
38
37
  gherkin (~> 2.11.0)
39
38
  json (>= 1.4.6)
40
39
  diff-lcs (1.1.3)
41
- ffi (1.1.3)
42
- ffi (1.1.3-java)
43
- gherkin (2.11.1)
40
+ ffi (1.3.1)
41
+ gherkin (2.11.5)
44
42
  json (>= 1.4.6)
45
- gherkin (2.11.1-java)
46
- json (>= 1.4.6)
47
- i18n (0.6.0)
48
- json (1.7.4)
49
- json (1.7.4-java)
43
+ i18n (0.6.1)
44
+ json (1.7.6)
50
45
  metaclass (0.0.1)
51
- mocha (0.10.5)
46
+ mocha (0.13.0)
52
47
  metaclass (~> 0.0.1)
53
- multi_json (1.3.6)
54
- rake (0.9.2.2)
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)
48
+ multi_json (1.5.0)
49
+ rake (10.0.3)
50
+ rspec (2.12.0)
51
+ rspec-core (~> 2.12.0)
52
+ rspec-expectations (~> 2.12.0)
53
+ rspec-mocks (~> 2.12.0)
54
+ rspec-core (2.12.2)
55
+ rspec-expectations (2.12.1)
61
56
  diff-lcs (~> 1.1.3)
62
- rspec-mocks (2.11.1)
63
- simplecov (0.6.4)
57
+ rspec-mocks (2.12.1)
58
+ simplecov (0.7.1)
64
59
  multi_json (~> 1.0)
65
- simplecov-html (~> 0.5.3)
66
- simplecov-html (0.5.3)
67
- sqlite3 (1.3.6)
68
- sqlite3-ruby (1.3.3)
69
- sqlite3 (>= 1.3.3)
70
- timecop (0.4.4)
71
- tzinfo (0.3.33)
72
- yard (0.8.2.1)
60
+ simplecov-html (~> 0.7.1)
61
+ 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)
73
66
 
74
67
  PLATFORMS
75
- java
76
68
  ruby
77
69
 
78
70
  DEPENDENCIES
79
- activerecord (~> 3.2.0)
80
- appraisal (~> 0.4)
71
+ activerecord (~> 3.2.11)
72
+ appraisal (~> 0.5.1)
81
73
  aruba
82
74
  bourne
83
- cucumber (~> 1.1)
75
+ cucumber (~> 1.2.1)
84
76
  factory_girl!
85
- mocha
86
- rspec (~> 2.0)
77
+ mocha (>= 0.12.8)
78
+ rspec (~> 2.12.0)
87
79
  simplecov
88
- sqlite3-ruby
80
+ sqlite3
89
81
  timecop
90
82
  yard
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activerecord", :github=>"rails/rails"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,95 @@
1
+ GIT
2
+ remote: git://github.com/rails/rails.git
3
+ revision: 40e797827935756aacf0463e4b44e1c1c92b0aeb
4
+ specs:
5
+ activemodel (4.0.0.beta)
6
+ activesupport (= 4.0.0.beta)
7
+ builder (~> 3.1.0)
8
+ activerecord (4.0.0.beta)
9
+ activemodel (= 4.0.0.beta)
10
+ activerecord-deprecated_finders (= 0.0.2)
11
+ activesupport (= 4.0.0.beta)
12
+ arel (~> 3.0.2)
13
+ activesupport (4.0.0.beta)
14
+ i18n (~> 0.6)
15
+ minitest (~> 4.1)
16
+ multi_json (~> 1.3)
17
+ thread_safe (~> 0.1)
18
+ tzinfo (~> 0.3.33)
19
+
20
+ PATH
21
+ remote: /Users/joshuaclayton/dev/gems/factory_girl
22
+ specs:
23
+ factory_girl (4.2.0)
24
+ activesupport (>= 3.0.0)
25
+
26
+ GEM
27
+ remote: http://rubygems.org/
28
+ specs:
29
+ activerecord-deprecated_finders (0.0.2)
30
+ appraisal (0.5.1)
31
+ bundler
32
+ rake
33
+ arel (3.0.2)
34
+ aruba (0.5.1)
35
+ childprocess (~> 0.3.6)
36
+ cucumber (>= 1.1.1)
37
+ rspec-expectations (>= 2.7.0)
38
+ atomic (1.0.1)
39
+ bourne (1.3.0)
40
+ mocha (= 0.13.0)
41
+ builder (3.1.4)
42
+ childprocess (0.3.6)
43
+ ffi (~> 1.0, >= 1.0.6)
44
+ cucumber (1.2.1)
45
+ builder (>= 2.1.2)
46
+ diff-lcs (>= 1.1.3)
47
+ gherkin (~> 2.11.0)
48
+ json (>= 1.4.6)
49
+ diff-lcs (1.1.3)
50
+ ffi (1.3.1)
51
+ gherkin (2.11.5)
52
+ json (>= 1.4.6)
53
+ i18n (0.6.1)
54
+ json (1.7.6)
55
+ metaclass (0.0.1)
56
+ minitest (4.4.0)
57
+ mocha (0.13.0)
58
+ metaclass (~> 0.0.1)
59
+ multi_json (1.5.0)
60
+ rake (10.0.3)
61
+ rspec (2.12.0)
62
+ rspec-core (~> 2.12.0)
63
+ rspec-expectations (~> 2.12.0)
64
+ rspec-mocks (~> 2.12.0)
65
+ rspec-core (2.12.2)
66
+ rspec-expectations (2.12.1)
67
+ diff-lcs (~> 1.1.3)
68
+ rspec-mocks (2.12.1)
69
+ simplecov (0.7.1)
70
+ multi_json (~> 1.0)
71
+ simplecov-html (~> 0.7.1)
72
+ simplecov-html (0.7.1)
73
+ sqlite3 (1.3.7)
74
+ thread_safe (0.1.0)
75
+ atomic
76
+ timecop (0.5.9)
77
+ tzinfo (0.3.35)
78
+ yard (0.8.3)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ activerecord!
85
+ appraisal (~> 0.5.1)
86
+ aruba
87
+ bourne
88
+ cucumber (~> 1.2.1)
89
+ factory_girl!
90
+ mocha (>= 0.12.8)
91
+ rspec (~> 2.12.0)
92
+ simplecov
93
+ sqlite3
94
+ timecop
95
+ yard
@@ -12,6 +12,12 @@ module FactoryGirl
12
12
  FactoryGirl.to_create
13
13
  end
14
14
 
15
+ def self.build_from_definition(definition)
16
+ build_to_create(&definition.to_create)
17
+ build_constructor(&definition.constructor)
18
+ add_callbacks definition.callbacks
19
+ end
20
+
15
21
  def self.add_callbacks(callbacks)
16
22
  if callbacks.any?
17
23
  define_method :callbacks do
@@ -19,6 +25,7 @@ module FactoryGirl
19
25
  end
20
26
  end
21
27
  end
28
+ private_class_method :add_callbacks
22
29
 
23
30
  def self.build_constructor(&block)
24
31
  if block
@@ -27,6 +34,7 @@ module FactoryGirl
27
34
  end
28
35
  end
29
36
  end
37
+ private_class_method :build_constructor
30
38
 
31
39
  def self.build_to_create(&block)
32
40
  if block
@@ -35,5 +43,6 @@ module FactoryGirl
35
43
  end
36
44
  end
37
45
  end
46
+ private_class_method :build_to_create
38
47
  end
39
48
  end
@@ -108,7 +108,7 @@ module FactoryGirl
108
108
  # Except that no globally available sequence will be defined.
109
109
  def sequence(name, *args, &block)
110
110
  sequence = Sequence.new(name, *args, &block)
111
- add_attribute(name) { sequence.next }
111
+ add_attribute(name) { increment_sequence(sequence) }
112
112
  end
113
113
 
114
114
  # Adds an attribute that builds an association. The associated instance will
@@ -11,9 +11,10 @@ module FactoryGirl
11
11
  end
12
12
 
13
13
  def initialize(build_strategy, overrides = {})
14
- @build_strategy = build_strategy
15
- @overrides = overrides
14
+ @build_strategy = build_strategy
15
+ @overrides = overrides
16
16
  @cached_attributes = overrides
17
+ @instance = nil
17
18
 
18
19
  @overrides.each do |name, value|
19
20
  singleton_class.define_attribute(name) { value }
@@ -42,10 +43,18 @@ module FactoryGirl
42
43
  end
43
44
  end
44
45
 
46
+ def respond_to_missing?(method_name, include_private = false)
47
+ @instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name)
48
+ end
49
+
45
50
  def __override_names__
46
51
  @overrides.keys
47
52
  end
48
53
 
54
+ def increment_sequence(sequence)
55
+ sequence.next(self)
56
+ end
57
+
49
58
  def self.attribute_list
50
59
  AttributeList.new.tap do |list|
51
60
  attribute_lists.each do |attribute_list|
@@ -121,9 +121,7 @@ module FactoryGirl
121
121
  end
122
122
 
123
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
124
+ hierarchy_class.build_from_definition definition
127
125
  end
128
126
 
129
127
  def callbacks
@@ -19,10 +19,16 @@ module FactoryGirl
19
19
  end
20
20
  end
21
21
 
22
- def next
23
- @proc ? @proc.call(@value.peek) : @value.peek
22
+ def next(scope = nil)
23
+ if @proc && scope
24
+ scope.instance_exec(value, &@proc)
25
+ elsif @proc
26
+ @proc.call(value)
27
+ else
28
+ value
29
+ end
24
30
  ensure
25
- @value.next
31
+ increment_value
26
32
  end
27
33
 
28
34
  def names
@@ -31,6 +37,14 @@ module FactoryGirl
31
37
 
32
38
  private
33
39
 
40
+ def value
41
+ @value.peek
42
+ end
43
+
44
+ def increment_value
45
+ @value.next
46
+ end
47
+
34
48
  class EnumeratorAdapter
35
49
  def initialize(value)
36
50
  @value = value
@@ -21,7 +21,7 @@ module FactoryGirl
21
21
  end
22
22
 
23
23
  def stub_database_interaction_on_result(result_instance)
24
- result_instance.id = next_id
24
+ result_instance.id ||= next_id
25
25
 
26
26
  result_instance.instance_eval do
27
27
  def persisted?
@@ -63,7 +63,7 @@ module FactoryGirl
63
63
  if created_at_missing_default || result_instance_missing_created_at
64
64
  result_instance.instance_eval do
65
65
  def created_at
66
- @created_at ||= Time.now
66
+ @created_at ||= Time.now.in_time_zone
67
67
  end
68
68
  end
69
69
  end
@@ -23,8 +23,8 @@ module FactoryGirl
23
23
  def define_list_strategy_method
24
24
  strategy_name = @strategy_name
25
25
 
26
- define_syntax_method("#{strategy_name}_list") do |name, amount, *traits_and_overrides|
27
- amount.times.map { send(strategy_name, name, *traits_and_overrides) }
26
+ define_syntax_method("#{strategy_name}_list") do |name, amount, *traits_and_overrides, &block|
27
+ amount.times.map { send(strategy_name, name, *traits_and_overrides, &block) }
28
28
  end
29
29
  end
30
30
 
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '4.1.0'
2
+ VERSION = '4.2.0'
3
3
  end
@@ -35,7 +35,7 @@ describe "using ActiveSupport::Instrumentation to track factory interaction" do
35
35
  FactoryGirl.build(:slow_user)
36
36
  end
37
37
 
38
- time_to_execute.should >= 0.1
38
+ expect(time_to_execute).to be >= 0.1
39
39
  end
40
40
 
41
41
  it "builds the correct payload" do
@@ -56,7 +56,7 @@ describe "using ActiveSupport::Instrumentation to track factory interaction" do
56
56
  FactoryGirl.attributes_for(:slow_user)
57
57
  end
58
58
 
59
- tracked_invocations[:slow_user].should == { build: 2, attributes_for: 1 }
60
- tracked_invocations[:user].should == { build: 5, create: 2 }
59
+ expect(tracked_invocations[:slow_user]).to eq(build: 2, attributes_for: 1)
60
+ expect(tracked_invocations[:user]).to eq(build: 5, create: 2)
61
61
  end
62
62
  end
@@ -14,6 +14,6 @@ describe "aliases and overrides" do
14
14
  end
15
15
 
16
16
  subject { FactoryGirl.create(:user, one: "override") }
17
- its(:one) { should == "override" }
17
+ its(:one) { should eq "override" }
18
18
  its(:two) { should be_nil }
19
19
  end
@@ -29,7 +29,7 @@ describe "attribute aliases" do
29
29
  subject { FactoryGirl.build(:post, user_id: 1) }
30
30
 
31
31
  it "doesn't assign both an association and its foreign key" do
32
- subject.user_id.should == 1
32
+ expect(subject.user_id).to eq 1
33
33
  end
34
34
  end
35
35
 
@@ -37,8 +37,8 @@ describe "attribute aliases" do
37
37
  subject { FactoryGirl.create(:post_with_named_user).user }
38
38
 
39
39
  it "assigns attributes correctly" do
40
- subject.name.should == "John Doe"
41
- subject.age.should == 20
40
+ expect(subject.name).to eq "John Doe"
41
+ expect(subject.age).to eq 20
42
42
  end
43
43
  end
44
44
  end