factory_girl 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
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.11"
5
+ gem "activerecord", "~> 3.2.15"
6
6
 
7
7
  gemspec :path=>"../"
@@ -1,52 +1,51 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
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.11)
11
- activesupport (= 3.2.11)
10
+ activemodel (3.2.15)
11
+ activesupport (= 3.2.15)
12
12
  builder (~> 3.0.0)
13
- activerecord (3.2.11)
14
- activemodel (= 3.2.11)
15
- activesupport (= 3.2.11)
13
+ activerecord (3.2.15)
14
+ activemodel (= 3.2.15)
15
+ activesupport (= 3.2.15)
16
16
  arel (~> 3.0.2)
17
17
  tzinfo (~> 0.3.29)
18
- activesupport (3.2.11)
19
- i18n (~> 0.6)
18
+ activesupport (3.2.15)
19
+ i18n (~> 0.6, >= 0.6.4)
20
20
  multi_json (~> 1.0)
21
- appraisal (0.5.1)
21
+ appraisal (0.5.2)
22
22
  bundler
23
23
  rake
24
24
  arel (3.0.2)
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.5.0)
30
+ mocha (>= 0.13.2, < 0.15)
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.3)
41
+ gherkin (2.11.8)
42
+ multi_json (~> 1.3)
43
+ i18n (0.6.5)
45
44
  metaclass (0.0.1)
46
- mocha (0.13.0)
45
+ mocha (0.14.0)
47
46
  metaclass (~> 0.0.1)
48
- multi_json (1.5.0)
49
- rake (10.0.3)
47
+ multi_json (1.8.2)
48
+ rake (10.1.0)
50
49
  rspec (2.12.0)
51
50
  rspec-core (~> 2.12.0)
52
51
  rspec-expectations (~> 2.12.0)
@@ -54,21 +53,21 @@ GEM
54
53
  rspec-core (2.12.2)
55
54
  rspec-expectations (2.12.1)
56
55
  diff-lcs (~> 1.1.3)
57
- rspec-mocks (2.12.1)
56
+ rspec-mocks (2.12.2)
58
57
  simplecov (0.7.1)
59
58
  multi_json (~> 1.0)
60
59
  simplecov-html (~> 0.7.1)
61
60
  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)
61
+ sqlite3 (1.3.8)
62
+ timecop (0.6.3)
63
+ tzinfo (0.3.38)
64
+ yard (0.8.7.3)
66
65
 
67
66
  PLATFORMS
68
67
  ruby
69
68
 
70
69
  DEPENDENCIES
71
- activerecord (~> 3.2.11)
70
+ activerecord (~> 3.2.15)
72
71
  appraisal (~> 0.5.1)
73
72
  aruba
74
73
  bourne
data/gemfiles/4.0.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "activerecord", :github=>"rails/rails"
5
+ gem "activerecord", "~> 4.0.1"
6
6
 
7
7
  gemspec :path=>"../"
@@ -1,63 +1,61 @@
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
1
  PATH
21
- remote: /Users/joshuaclayton/dev/gems/factory_girl
2
+ remote: ..
22
3
  specs:
23
- factory_girl (4.2.0)
4
+ factory_girl (4.3.0)
24
5
  activesupport (>= 3.0.0)
25
6
 
26
7
  GEM
27
8
  remote: http://rubygems.org/
28
9
  specs:
29
- activerecord-deprecated_finders (0.0.2)
30
- appraisal (0.5.1)
10
+ activemodel (4.0.1)
11
+ activesupport (= 4.0.1)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.1)
14
+ activemodel (= 4.0.1)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.1)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activesupport (4.0.1)
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)
31
26
  bundler
32
27
  rake
33
- arel (3.0.2)
34
- aruba (0.5.1)
35
- childprocess (~> 0.3.6)
28
+ arel (4.0.1)
29
+ aruba (0.5.3)
30
+ childprocess (>= 0.3.6)
36
31
  cucumber (>= 1.1.1)
37
32
  rspec-expectations (>= 2.7.0)
38
- atomic (1.0.1)
39
- bourne (1.3.0)
40
- mocha (= 0.13.0)
33
+ atomic (1.1.14)
34
+ atomic (1.1.14-java)
35
+ bourne (1.5.0)
36
+ mocha (>= 0.13.2, < 0.15)
41
37
  builder (3.1.4)
42
- childprocess (0.3.6)
43
- ffi (~> 1.0, >= 1.0.6)
44
- cucumber (1.2.1)
38
+ childprocess (0.3.9)
39
+ ffi (~> 1.0, >= 1.0.11)
40
+ cucumber (1.2.5)
45
41
  builder (>= 2.1.2)
46
42
  diff-lcs (>= 1.1.3)
47
- gherkin (~> 2.11.0)
48
- json (>= 1.4.6)
43
+ gherkin (~> 2.11.7)
44
+ multi_json (~> 1.3)
49
45
  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)
46
+ ffi (1.9.3)
47
+ ffi (1.9.3-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.5)
55
53
  metaclass (0.0.1)
56
- minitest (4.4.0)
57
- mocha (0.13.0)
54
+ minitest (4.7.5)
55
+ mocha (0.14.0)
58
56
  metaclass (~> 0.0.1)
59
- multi_json (1.5.0)
60
- rake (10.0.3)
57
+ multi_json (1.8.2)
58
+ rake (10.1.0)
61
59
  rspec (2.12.0)
62
60
  rspec-core (~> 2.12.0)
63
61
  rspec-expectations (~> 2.12.0)
@@ -65,23 +63,26 @@ GEM
65
63
  rspec-core (2.12.2)
66
64
  rspec-expectations (2.12.1)
67
65
  diff-lcs (~> 1.1.3)
68
- rspec-mocks (2.12.1)
66
+ rspec-mocks (2.12.2)
69
67
  simplecov (0.7.1)
70
68
  multi_json (~> 1.0)
71
69
  simplecov-html (~> 0.7.1)
72
70
  simplecov-html (0.7.1)
73
- sqlite3 (1.3.7)
74
- thread_safe (0.1.0)
71
+ sqlite3 (1.3.8)
72
+ thread_safe (0.1.3)
73
+ atomic
74
+ thread_safe (0.1.3-java)
75
75
  atomic
76
- timecop (0.5.9)
77
- tzinfo (0.3.35)
78
- yard (0.8.3)
76
+ timecop (0.6.3)
77
+ tzinfo (0.3.38)
78
+ yard (0.8.7.3)
79
79
 
80
80
  PLATFORMS
81
+ java
81
82
  ruby
82
83
 
83
84
  DEPENDENCIES
84
- activerecord!
85
+ activerecord (~> 4.0.1)
85
86
  appraisal (~> 0.5.1)
86
87
  aruba
87
88
  bourne
data/lib/factory_girl.rb CHANGED
@@ -55,7 +55,7 @@ module FactoryGirl
55
55
  end
56
56
 
57
57
  class << self
58
- delegate :factories, :sequences, :traits, :strategies, :callback_names,
58
+ delegate :factories, :sequences, :traits, :callbacks, :strategies, :callback_names,
59
59
  :to_create, :skip_create, :initialize_with, :constructor, :duplicate_attribute_assignment_from_initialize_with,
60
60
  :duplicate_attribute_assignment_from_initialize_with=, to: :configuration
61
61
  end
@@ -11,7 +11,7 @@ module FactoryGirl
11
11
  block = @block
12
12
 
13
13
  -> {
14
- value = block.arity == 1 ? block.call(self) : instance_exec(&block)
14
+ value = block.arity == 1 ? instance_exec(self, &block) : instance_exec(&block)
15
15
  raise SequenceAbuseError if FactoryGirl::Sequence === value
16
16
  value
17
17
  }
@@ -10,7 +10,7 @@ module FactoryGirl
10
10
 
11
11
  def run(instance, evaluator)
12
12
  case block.arity
13
- when 1 then syntax_runner.instance_exec(instance, &block)
13
+ when 1, -1 then syntax_runner.instance_exec(instance, &block)
14
14
  when 2 then syntax_runner.instance_exec(instance, evaluator, &block)
15
15
  else syntax_runner.instance_exec(&block)
16
16
  end
@@ -15,7 +15,8 @@ module FactoryGirl
15
15
  initialize_with { new }
16
16
  end
17
17
 
18
- delegate :to_create, :skip_create, :constructor, to: :@definition
18
+ delegate :to_create, :skip_create, :constructor, :before, :after,
19
+ :callback, :callbacks, to: :@definition
19
20
 
20
21
  def initialize_with(&block)
21
22
  @definition.define_constructor(&block)
@@ -84,6 +84,21 @@ module FactoryGirl
84
84
  @constructor = block
85
85
  end
86
86
 
87
+ def before(*names, &block)
88
+ callback(*names.map {|name| "before_#{name}" }, &block)
89
+ end
90
+
91
+ def after(*names, &block)
92
+ callback(*names.map {|name| "after_#{name}" }, &block)
93
+ end
94
+
95
+ def callback(*names, &block)
96
+ names.each do |name|
97
+ FactoryGirl.register_callback(name)
98
+ add_callback(Callback.new(name, block))
99
+ end
100
+ end
101
+
87
102
  private
88
103
 
89
104
  def base_traits
@@ -1,7 +1,7 @@
1
1
  module FactoryGirl
2
2
  class DefinitionHierarchy
3
3
  def callbacks
4
- []
4
+ FactoryGirl.callbacks
5
5
  end
6
6
 
7
7
  def constructor
@@ -1,11 +1,13 @@
1
1
  module FactoryGirl
2
2
  class DefinitionProxy
3
- UNPROXIED_METHODS = %w(__send__ __id__ nil? send object_id extend instance_eval initialize block_given? raise caller)
3
+ UNPROXIED_METHODS = %w(__send__ __id__ nil? send object_id extend instance_eval initialize block_given? raise caller method)
4
4
 
5
5
  (instance_methods + private_instance_methods).each do |method|
6
6
  undef_method(method) unless UNPROXIED_METHODS.include?(method.to_s)
7
7
  end
8
8
 
9
+ delegate :before, :after, :callback, to: :@definition
10
+
9
11
  attr_reader :child_factories
10
12
 
11
13
  def initialize(definition, ignore = false)
@@ -14,6 +16,11 @@ module FactoryGirl
14
16
  @child_factories = []
15
17
  end
16
18
 
19
+ def singleton_method_added(name)
20
+ message = "Defining methods in blocks (trait or factory) is not supported (#{name})"
21
+ raise FactoryGirl::MethodDefinitionError, message
22
+ end
23
+
17
24
  # Adds an attribute that should be assigned on generated instances for this
18
25
  # factory.
19
26
  #
@@ -157,20 +164,5 @@ module FactoryGirl
157
164
  def initialize_with(&block)
158
165
  @definition.define_constructor(&block)
159
166
  end
160
-
161
- def before(*names, &block)
162
- callback(*names.map {|name| "before_#{name}" }, &block)
163
- end
164
-
165
- def after(*names, &block)
166
- callback(*names.map {|name| "after_#{name}" }, &block)
167
- end
168
-
169
- def callback(*names, &block)
170
- names.each do |name|
171
- FactoryGirl.register_callback(name)
172
- @definition.add_callback(Callback.new(name, block))
173
- end
174
- end
175
167
  end
176
168
  end
@@ -16,4 +16,7 @@ module FactoryGirl
16
16
  # * Defining an attribute with both a static and lazy value
17
17
  # * Defining an attribute twice in the same factory
18
18
  class AttributeDefinitionError < RuntimeError; end
19
+
20
+ # Raised when a method is defined in a factory or trait with arguments
21
+ class MethodDefinitionError < RuntimeError; end
19
22
  end
@@ -8,7 +8,7 @@ module FactoryGirl
8
8
 
9
9
  def initialize(name, options = {})
10
10
  assert_valid_options(options)
11
- @name = name.is_a?(Symbol) ? name : name.to_s.underscore.to_sym
11
+ @name = name.respond_to?(:to_sym) ? name.to_sym : name.to_s.underscore.to_sym
12
12
  @parent = options[:parent]
13
13
  @aliases = options[:aliases] || []
14
14
  @class_name = options[:class]
@@ -8,6 +8,7 @@ module FactoryGirl
8
8
  def define_strategy_methods
9
9
  define_singular_strategy_method
10
10
  define_list_strategy_method
11
+ define_pair_strategy_method
11
12
  end
12
13
 
13
14
  private
@@ -28,6 +29,14 @@ module FactoryGirl
28
29
  end
29
30
  end
30
31
 
32
+ def define_pair_strategy_method
33
+ strategy_name = @strategy_name
34
+
35
+ define_syntax_method("#{strategy_name}_pair") do |name, *traits_and_overrides, &block|
36
+ 2.times.map { send(strategy_name, name, *traits_and_overrides, &block) }
37
+ end
38
+ end
39
+
31
40
  def define_syntax_method(name, &block)
32
41
  FactoryGirl::Syntax::Methods.module_exec do
33
42
  define_method(name, &block)
@@ -48,6 +48,14 @@ module FactoryGirl
48
48
  def self.run(block)
49
49
  new.instance_eval(&block)
50
50
  end
51
+
52
+ delegate :before, :after, :callback, to: :configuration
53
+
54
+ private
55
+
56
+ def configuration
57
+ FactoryGirl.configuration
58
+ end
51
59
  end
52
60
 
53
61
  class ModifyDSL
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '4.2.0'
2
+ VERSION = '4.3.0'
3
3
  end