fixture_factory 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3cfc56492aba74f896ae46e75abc1444ea6dce64c836da9e24b046aebff9f43
4
- data.tar.gz: d0e255b0c304c9763806f49acc00463d3b522f62db3356ab8703471befcca245
3
+ metadata.gz: d381248d146c43a6d012835ba18cc6a4e35eed54dac49e7bc1251835e3c7c067
4
+ data.tar.gz: 484dfa6915dcdfe39916de7550476629165c7b145f848d08731431a3ddfab9b7
5
5
  SHA512:
6
- metadata.gz: 78368269a25209bd0dac219b4680879456353ab490300facf0a6ac427cc6df3400295ae24dfb7059ff4148c4221b06719794b6403ebacf095bc0e0f21f8b97b9
7
- data.tar.gz: 82e7039c1d6b27c570239627020cc28c130ea576120bda2cfa6b64ff17b28ecc134d832c22c212af92653be68823ed398036998fef74e0d10548f0f989717bf6
6
+ metadata.gz: 2b1178163cd32b43d455c6d832d0211fc09eefaa92b7677e7fbc59b14eb07fdde7e19af582c196c6eb981570973b629aec6aa0ad8b1a9d16e7faafdcd73604f4
7
+ data.tar.gz: faa5c0d04ae035afbd89e2211a902b02b4ddccc8152ec2dc2fc7b4ca0558f012f8ac963a0bbe4651f02f33da91cf21012b15b62c74cf94068cb74571255f0450
@@ -5,14 +5,14 @@ module FixtureFactory
5
5
  EMPTY_BLOCK = proc {}
6
6
 
7
7
  attr_writer :block
8
- attr_accessor :class_name, :fixture_method, :fixture_name, :parent, :sequence
8
+ attr_accessor :fixture_method, :fixture_name, :parent, :sequence, :proc_class
9
9
 
10
10
  def initialize(name, options = {})
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 }
11
+ self.parent = options.fetch(:parent) { default_parent_for(name) }
12
+ self.proc_class = options.fetch(:class) { parent.proc_class }
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 }
16
16
  self.sequence = Sequence.new
17
17
  end
18
18
 
@@ -29,9 +29,9 @@ module FixtureFactory
29
29
  end
30
30
 
31
31
  def klass
32
- @klass ||= class_name.to_s.constantize
32
+ @klass ||= proc_class.call
33
33
  rescue NameError
34
- raise WrongClassError, class_name
34
+ raise WrongClassError, proc_class
35
35
  end
36
36
 
37
37
  def fixture_args
@@ -70,7 +70,7 @@ module FixtureFactory
70
70
  name,
71
71
  parent: nil,
72
72
  like: nil,
73
- class_name: name.to_s.classify,
73
+ class: -> { name.to_s.classify.safe_constantize },
74
74
  via: name.to_s.pluralize,
75
75
  )
76
76
  end
@@ -30,14 +30,32 @@ module FixtureFactory
30
30
  end
31
31
 
32
32
  class WrongClassError < Error
33
- def initialize(class_name)
34
- super(
35
- <<~MSG.squish
36
- No class named "#{class_name}".
37
- Try using the `class_name` option in your definition to specify a valid class name.
38
- https://github.com/Shopify/fixture_factory/blob/master/README.md#naming
39
- MSG
40
- )
33
+ def initialize(klass)
34
+ message = if klass.is_a?(String)
35
+ string_class_error_message(klass)
36
+ else
37
+ proc_class_error_message(klass)
38
+ end
39
+ super(message)
40
+ end
41
+
42
+ private
43
+
44
+ def proc_class_error_message(proc_class)
45
+ location, line_number = proc_class.source_location
46
+ <<~MSG.squish
47
+ Constant defined in file #{location} on line #{line_number} is not defined.
48
+ Try using the `class` option in your definition to specify a valid class name.
49
+ https://github.com/Shopify/fixture_factory/blob/master/README.md#naming
50
+ MSG
51
+ end
52
+
53
+ def string_class_error_message(class_name)
54
+ <<~MSG.squish
55
+ No class named "#{class_name}".
56
+ Try using the `class_name` option in your definition to specify a valid class name.
57
+ https://github.com/Shopify/fixture_factory/blob/master/README.md#naming
58
+ MSG
41
59
  end
42
60
  end
43
61
  end
@@ -46,12 +46,13 @@ 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)
49
+ if options.key?(:class_name)
50
+ options[:class] ||= -> do
51
+ class_name = options.delete(:class_name).to_s
52
+ class_name.constantize
53
+ rescue NameError
54
+ raise WrongClassError, class_name
55
+ end
55
56
  end
56
57
 
57
58
  parent = all_factory_definitions[options[:parent]]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FixtureFactory
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
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.1
4
+ version: 0.3.0
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-05-25 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord