fixture_factory 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2400bfa9a06b737fc0c45a0923573c98d5e212fc8819830259032b1dff5c8f4f
4
- data.tar.gz: f7188d3a67f00d1274105c200b569739c913c8b8b26c3d14418b9effd7bf0d6e
3
+ metadata.gz: a3cfc56492aba74f896ae46e75abc1444ea6dce64c836da9e24b046aebff9f43
4
+ data.tar.gz: d0e255b0c304c9763806f49acc00463d3b522f62db3356ab8703471befcca245
5
5
  SHA512:
6
- metadata.gz: 778d52104a7364044668361062da829a01dd69b6532da5ce7c8e4c336001ad92820bac847d6fe2b253b98a65eb8b1f7c027d084f46d97e3d2de86789c4c290e8
7
- data.tar.gz: 4970561723810fd451f93cd32f63f77209454cb9f576ad79ba7e5803345f322cdebe3e9695fdd4ae93c43da09fec147bbcf21831a62b65b70c293043c4dfc75c
6
+ metadata.gz: 78368269a25209bd0dac219b4680879456353ab490300facf0a6ac427cc6df3400295ae24dfb7059ff4148c4221b06719794b6403ebacf095bc0e0f21f8b97b9
7
+ data.tar.gz: 82e7039c1d6b27c570239627020cc28c130ea576120bda2cfa6b64ff17b28ecc134d832c22c212af92653be68823ed398036998fef74e0d10548f0f989717bf6
@@ -9,18 +9,18 @@ require 'fixture_factory/errors'
9
9
 
10
10
  module FixtureFactory
11
11
  class << self
12
- def attributes_for(name, options) # :nodoc:
13
- _, attributes = retrieve(name, options)
12
+ def attributes_for(name, **options) # :nodoc:
13
+ _, attributes = retrieve(name, **options)
14
14
  attributes
15
15
  end
16
16
 
17
- def build(name, options) # :nodoc:
18
- klass, attributes = retrieve(name, options)
17
+ def build(name, **options) # :nodoc:
18
+ klass, attributes = retrieve(name, **options)
19
19
  klass.new(attributes)
20
20
  end
21
21
 
22
- def create(name, options) # :nodoc:
23
- build(name, options).tap(&:save!)
22
+ def create(name, **options) # :nodoc:
23
+ build(name, **options).tap(&:save!)
24
24
  end
25
25
 
26
26
  def evaluate(block, args: [], context:) # :nodoc:
@@ -4,16 +4,15 @@ module FixtureFactory
4
4
  class Definition # :nodoc:
5
5
  EMPTY_BLOCK = proc {}
6
6
 
7
- attr_reader :klass
8
7
  attr_writer :block
9
- attr_accessor :fixture_method, :fixture_name, :parent, :sequence
8
+ attr_accessor :class_name, :fixture_method, :fixture_name, :parent, :sequence
10
9
 
11
10
  def initialize(name, options = {})
12
- self.parent = options.fetch(:parent) { default_parent_for(name) }
13
- self.klass = options.fetch(:class) { parent.klass }
14
- self.fixture_method = options.fetch(:via) { parent.fixture_method }
15
- self.fixture_name = options.fetch(:like) { parent.fixture_name }
16
- self.block = options.fetch(:block) { EMPTY_BLOCK }
11
+ self.parent = options.fetch(:parent) { default_parent_for(name) }
12
+ self.class_name = options.fetch(:class_name) { parent.class_name }
13
+ self.fixture_method = options.fetch(:via) { parent.fixture_method }
14
+ self.fixture_name = options.fetch(:like) { parent.fixture_name }
15
+ self.block = options.fetch(:block) { EMPTY_BLOCK }
17
16
  self.sequence = Sequence.new
18
17
  end
19
18
 
@@ -29,15 +28,10 @@ module FixtureFactory
29
28
  end
30
29
  end
31
30
 
32
- def klass=(new_class)
33
- @klass = case new_class
34
- when String
35
- new_class.to_s.constantize
36
- else
37
- new_class
38
- end
31
+ def klass
32
+ @klass ||= class_name.to_s.constantize
39
33
  rescue NameError
40
- raise WrongClassError, new_class
34
+ raise WrongClassError, class_name
41
35
  end
42
36
 
43
37
  def fixture_args
@@ -76,7 +70,7 @@ module FixtureFactory
76
70
  name,
77
71
  parent: nil,
78
72
  like: nil,
79
- class: name.to_s.classify.safe_constantize,
73
+ class_name: name.to_s.classify,
80
74
  via: name.to_s.pluralize,
81
75
  )
82
76
  end
@@ -34,7 +34,7 @@ module FixtureFactory
34
34
  super(
35
35
  <<~MSG.squish
36
36
  No class named "#{class_name}".
37
- Try using the `class` option in your definition to specify a valid class name.
37
+ Try using the `class_name` option in your definition to specify a valid class name.
38
38
  https://github.com/Shopify/fixture_factory/blob/master/README.md#naming
39
39
  MSG
40
40
  )
@@ -46,6 +46,14 @@ module FixtureFactory
46
46
  # factory(:admin, via: :users, like: :bob_admin, class: 'User')
47
47
  # end
48
48
  def factory(name, options = {}, &block)
49
+ if options.key?(:class)
50
+ ActiveSupport::Deprecation.warn(<<~MSG.squish)
51
+ factory class: option is deprecated and will be removed.
52
+ Please use the class_name: option instead.
53
+ MSG
54
+ options[:class_name] ||= options.delete(:class)
55
+ end
56
+
49
57
  parent = all_factory_definitions[options[:parent]]
50
58
  options[:parent] = parent if options.key?(:parent)
51
59
  options[:block] = block if block
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FixtureFactory
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-09 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -136,10 +136,11 @@ files:
136
136
  - lib/fixture_factory/registry.rb
137
137
  - lib/fixture_factory/sequence.rb
138
138
  - lib/fixture_factory/version.rb
139
- homepage:
139
+ homepage: https://github.com/Shopify/fixture_factory
140
140
  licenses:
141
141
  - MIT
142
- metadata: {}
142
+ metadata:
143
+ allowed_push_host: https://rubygems.org
143
144
  post_install_message:
144
145
  rdoc_options: []
145
146
  require_paths: