factory_girl 4.7.0 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,6 @@ source "https://rubygems.org"
5
5
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
6
6
  gem "jdbc-sqlite3", :platforms => :jruby
7
7
  gem "sqlite3", "~> 1.3.10", :platforms => :ruby
8
- gem "activerecord", "~> 5.0.0.beta2"
8
+ gem "activerecord", "~> 5.0.0"
9
9
 
10
10
  gemspec :path => "../"
@@ -1,28 +1,21 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- factory_girl (4.7.0)
4
+ factory_girl (4.8.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.0.0.beta2)
11
- activesupport (= 5.0.0.beta2)
12
- activerecord (5.0.0.beta2)
13
- activemodel (= 5.0.0.beta2)
14
- activesupport (= 5.0.0.beta2)
10
+ activemodel (5.0.0)
11
+ activesupport (= 5.0.0)
12
+ activerecord (5.0.0)
13
+ activemodel (= 5.0.0)
14
+ activesupport (= 5.0.0)
15
15
  arel (~> 7.0)
16
- activerecord-jdbc-adapter (1.3.19)
17
- activerecord (>= 2.2)
18
- activerecord-jdbcsqlite3-adapter (1.3.19)
19
- activerecord-jdbc-adapter (~> 1.3.19)
20
- jdbc-sqlite3 (>= 3.7.2, < 3.9)
21
- activesupport (5.0.0.beta2)
22
- concurrent-ruby (~> 1.0)
16
+ activesupport (5.0.0)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
23
18
  i18n (~> 0.7)
24
- json (~> 1.7, >= 1.7.7)
25
- method_source
26
19
  minitest (~> 5.1)
27
20
  tzinfo (~> 1.1)
28
21
  appraisal (2.1.0)
@@ -30,7 +23,7 @@ GEM
30
23
  rake
31
24
  thor (>= 0.14.0)
32
25
  arel (7.0.0)
33
- aruba (0.13.0)
26
+ aruba (0.14.1)
34
27
  childprocess (~> 0.5.6)
35
28
  contracts (~> 0.9)
36
29
  cucumber (>= 1.3.19)
@@ -42,9 +35,8 @@ GEM
42
35
  builder (3.2.2)
43
36
  childprocess (0.5.9)
44
37
  ffi (~> 1.0, >= 1.0.11)
45
- concurrent-ruby (1.0.0)
46
- concurrent-ruby (1.0.0-java)
47
- contracts (0.13.0)
38
+ concurrent-ruby (1.0.2)
39
+ contracts (0.14.0)
48
40
  cucumber (1.3.20)
49
41
  builder (>= 2.1.2)
50
42
  diff-lcs (>= 1.1.3)
@@ -54,28 +46,22 @@ GEM
54
46
  diff-lcs (1.2.5)
55
47
  docile (1.1.5)
56
48
  ffi (1.9.10)
57
- ffi (1.9.10-java)
58
49
  gherkin (2.12.2)
59
50
  multi_json (~> 1.3)
60
- gherkin (2.12.2-java)
61
- multi_json (~> 1.3)
62
51
  i18n (0.7.0)
63
- jdbc-sqlite3 (3.8.11.2)
64
52
  json (1.8.3)
65
- json (1.8.3-java)
66
53
  metaclass (0.0.4)
67
- method_source (0.8.2)
68
- minitest (5.8.4)
54
+ minitest (5.9.0)
69
55
  mocha (1.1.0)
70
56
  metaclass (~> 0.0.1)
71
- multi_json (1.11.2)
57
+ multi_json (1.12.1)
72
58
  multi_test (0.1.2)
73
- rake (10.5.0)
59
+ rake (11.2.2)
74
60
  rspec (3.4.0)
75
61
  rspec-core (~> 3.4.0)
76
62
  rspec-expectations (~> 3.4.0)
77
63
  rspec-mocks (~> 3.4.0)
78
- rspec-core (3.4.2)
64
+ rspec-core (3.4.4)
79
65
  rspec-support (~> 3.4.0)
80
66
  rspec-expectations (3.4.0)
81
67
  diff-lcs (>= 1.2.0, < 2.0)
@@ -95,18 +81,16 @@ GEM
95
81
  sqlite3 (1.3.11)
96
82
  thor (0.19.1)
97
83
  thread_safe (0.3.5)
98
- thread_safe (0.3.5-java)
99
- timecop (0.8.0)
84
+ timecop (0.8.1)
100
85
  tzinfo (1.2.2)
101
86
  thread_safe (~> 0.1)
102
87
  yard (0.8.7.6)
103
88
 
104
89
  PLATFORMS
105
- java
106
90
  ruby
107
91
 
108
92
  DEPENDENCIES
109
- activerecord (~> 5.0.0.beta2)
93
+ activerecord (~> 5.0.0)
110
94
  activerecord-jdbcsqlite3-adapter
111
95
  appraisal (~> 2.1.0)
112
96
  aruba
@@ -123,4 +107,4 @@ DEPENDENCIES
123
107
  yard
124
108
 
125
109
  BUNDLED WITH
126
- 1.11.2
110
+ 1.13.6
@@ -68,10 +68,23 @@ module FactoryGirl
68
68
  end
69
69
 
70
70
  class << self
71
- delegate :factories, :sequences, :traits, :callbacks, :strategies, :callback_names,
72
- :to_create, :skip_create, :initialize_with, :constructor,
73
- :duplicate_attribute_assignment_from_initialize_with, :duplicate_attribute_assignment_from_initialize_with=,
74
- :allow_class_lookup, :allow_class_lookup=, to: :configuration
71
+ delegate :factories,
72
+ :sequences,
73
+ :traits,
74
+ :callbacks,
75
+ :strategies,
76
+ :callback_names,
77
+ :to_create,
78
+ :skip_create,
79
+ :initialize_with,
80
+ :constructor,
81
+ :duplicate_attribute_assignment_from_initialize_with,
82
+ :duplicate_attribute_assignment_from_initialize_with=,
83
+ :allow_class_lookup,
84
+ :allow_class_lookup=,
85
+ :use_parent_strategy,
86
+ :use_parent_strategy=,
87
+ to: :configuration
75
88
  end
76
89
 
77
90
  def self.register_factory(factory)
@@ -3,7 +3,7 @@ module FactoryGirl
3
3
  class Configuration
4
4
  attr_reader :factories, :sequences, :traits, :strategies, :callback_names
5
5
 
6
- attr_accessor :allow_class_lookup
6
+ attr_accessor :allow_class_lookup, :use_parent_strategy
7
7
 
8
8
  def initialize
9
9
  @factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Factory'))
@@ -7,9 +7,8 @@ module FactoryGirl
7
7
  end
8
8
 
9
9
  def attributes
10
- @attributes.inject({}) do |result, attribute_name|
10
+ @attributes.each_with_object({}) do |attribute_name, result|
11
11
  result[attribute_name] = send(attribute_name)
12
- result
13
12
  end
14
13
  end
15
14
  end
@@ -125,17 +125,12 @@ module FactoryGirl
125
125
 
126
126
  def aggregate_from_traits_and_self(method_name, &block)
127
127
  compile
128
- [].tap do |list|
129
- base_traits.each do |trait|
130
- list << trait.send(method_name)
131
- end
132
-
133
- list << instance_exec(&block)
134
128
 
135
- additional_traits.each do |trait|
136
- list << trait.send(method_name)
137
- end
138
- end.flatten.compact
129
+ [
130
+ base_traits.map(&method_name),
131
+ instance_exec(&block),
132
+ additional_traits.map(&method_name),
133
+ ].flatten.compact
139
134
  end
140
135
  end
141
136
  end
@@ -23,7 +23,9 @@ module FactoryGirl
23
23
 
24
24
  def association(factory_name, *traits_and_overrides)
25
25
  overrides = traits_and_overrides.extract_options!
26
- strategy_override = overrides.fetch(:strategy) { :create }
26
+ strategy_override = overrides.fetch(:strategy) do
27
+ FactoryGirl.use_parent_strategy ? @build_strategy.class : :create
28
+ end
27
29
 
28
30
  traits_and_overrides += [overrides.except(:strategy)]
29
31
 
@@ -84,7 +84,7 @@ module FactoryGirl
84
84
 
85
85
  def error_message
86
86
  lines = invalid_factories.map do |_factory, exceptions|
87
- exceptions.map &:message
87
+ exceptions.map(&:message)
88
88
  end.flatten
89
89
 
90
90
  <<-ERROR_MESSAGE.strip
@@ -3,6 +3,31 @@ module FactoryGirl
3
3
  class Stub
4
4
  @@next_id = 1000
5
5
 
6
+ DISABLED_PERSISTENCE_METHODS = [
7
+ :connection,
8
+ :decrement!,
9
+ :decrement,
10
+ :delete,
11
+ :destroy!,
12
+ :destroy,
13
+ :destroyed?,
14
+ :increment!,
15
+ :increment,
16
+ :reload,
17
+ :save!,
18
+ :save,
19
+ :toggle!,
20
+ :toggle,
21
+ :touch,
22
+ :update!,
23
+ :update,
24
+ :update_attribute,
25
+ :update_attributes!,
26
+ :update_attributes,
27
+ :update_column,
28
+ :update_columns,
29
+ ].freeze
30
+
6
31
  def association(runner)
7
32
  runner.run(:build_stubbed)
8
33
  end
@@ -33,36 +58,10 @@ module FactoryGirl
33
58
  id.nil?
34
59
  end
35
60
 
36
- def save(*args)
37
- raise "stubbed models are not allowed to access the database - #{self.class.to_s}#save(#{args.join(",")})"
38
- end
39
-
40
- def destroy(*args)
41
- raise "stubbed models are not allowed to access the database - #{self.class.to_s}#destroy(#{args.join(",")})"
42
- end
43
-
44
- def connection
45
- raise "stubbed models are not allowed to access the database - #{self.class.to_s}#connection()"
46
- end
47
-
48
- def reload(*args)
49
- raise "stubbed models are not allowed to access the database - #{self.class.to_s}#reload()"
50
- end
51
-
52
- def update_attribute(*args)
53
- raise "stubbed models are not allowed to access the database - #{self.class.to_s}#update_attribute(#{args.join(",")})"
54
- end
55
-
56
- def update_column(*args)
57
- raise "stubbed models are not allowed to access the database - #{self.class.to_s}#update_column(#{args.join(",")})"
58
- end
59
-
60
- def increment!(*args)
61
- raise "stubbed models are not allowed to access the database - #{self.class}#increment!(#{args.join(',')})"
62
- end
63
-
64
- def decrement!(*args)
65
- raise "stubbed models are not allowed to access the database - #{self.class}#decrement!(#{args.join(',')})"
61
+ DISABLED_PERSISTENCE_METHODS.each do |write_method|
62
+ define_singleton_method(write_method) do |*args|
63
+ raise "stubbed models are not allowed to access the database - #{self.class}##{write_method}(#{args.join(",")})"
64
+ end
66
65
  end
67
66
  end
68
67
 
@@ -76,6 +75,18 @@ module FactoryGirl
76
75
  end
77
76
  end
78
77
  end
78
+
79
+ has_updated_at = result_instance.respond_to?(:updated_at)
80
+ updated_at_no_default = has_updated_at && !result_instance.updated_at
81
+ result_instance_missing_updated_at = !has_updated_at
82
+
83
+ if updated_at_no_default || result_instance_missing_updated_at
84
+ result_instance.instance_eval do
85
+ def updated_at
86
+ @updated_at ||= Time.current
87
+ end
88
+ end
89
+ end
79
90
  end
80
91
 
81
92
  def clear_changed_attributes_on_result(result_instance)
@@ -25,6 +25,10 @@ module FactoryGirl
25
25
  strategy_name = @strategy_name
26
26
 
27
27
  define_syntax_method("#{strategy_name}_list") do |name, amount, *traits_and_overrides, &block|
28
+ unless amount.respond_to?(:times)
29
+ raise ArgumentError, "count missing for #{strategy_name}_list"
30
+ end
31
+
28
32
  amount.times.map { send(strategy_name, name, *traits_and_overrides, &block) }
29
33
  end
30
34
  end
@@ -69,13 +69,13 @@ module FactoryGirl
69
69
 
70
70
  # @!method strategy_method
71
71
  # @!visibility private
72
- # @param [Symbol] name name of the factory to build
72
+ # @param [Symbol] name the name of the factory to build
73
73
  # @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
74
74
  # @param [Proc] block block to be executed
75
75
 
76
76
  # @!method strategy_method_list
77
77
  # @!visibility private
78
- # @param [Symbol] name name of the factory to execute
78
+ # @param [Symbol] name the name of the factory to execute
79
79
  # @param [Integer] amount the number of instances to execute
80
80
  # @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
81
81
 
@@ -90,6 +90,22 @@ module FactoryGirl
90
90
  def generate(name)
91
91
  FactoryGirl.sequence_by_name(name).next
92
92
  end
93
+
94
+ # Generates and returns the list of values in a sequence.
95
+ #
96
+ # Arguments:
97
+ # name: (Symbol)
98
+ # The name of the sequence that a value should be generated for.
99
+ # count: (Fixnum)
100
+ # Count of values
101
+ #
102
+ # Returns:
103
+ # The next value in the sequence. (Object)
104
+ def generate_list(name, count)
105
+ (1..count).map do
106
+ FactoryGirl.sequence_by_name(name).next
107
+ end
108
+ end
93
109
  end
94
110
  end
95
111
  end
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '4.7.0'.freeze
2
+ VERSION = '4.8.0'.freeze
3
3
  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: 4.7.0
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Clayton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-01 00:00:00.000000000 Z
12
+ date: 2016-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -202,6 +202,7 @@ files:
202
202
  - Gemfile
203
203
  - Gemfile.lock
204
204
  - LICENSE
205
+ - NAME.md
205
206
  - NEWS
206
207
  - README.md
207
208
  - Rakefile
@@ -290,10 +291,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
291
  version: '0'
291
292
  requirements: []
292
293
  rubyforge_project:
293
- rubygems_version: 2.5.1
294
+ rubygems_version: 2.6.4
294
295
  signing_key:
295
296
  specification_version: 4
296
297
  summary: factory_girl provides a framework and DSL for defining and using model instance
297
298
  factories.
298
299
  test_files: []
299
- has_rdoc: