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 +4 -4
- data/lib/fixture_factory/definition.rb +9 -9
- data/lib/fixture_factory/errors.rb +26 -8
- data/lib/fixture_factory/registry.rb +7 -6
- data/lib/fixture_factory/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d381248d146c43a6d012835ba18cc6a4e35eed54dac49e7bc1251835e3c7c067
|
4
|
+
data.tar.gz: 484dfa6915dcdfe39916de7550476629165c7b145f848d08731431a3ddfab9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
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)
|
12
|
-
self.
|
13
|
-
self.fixture_method = options.fetch(:via)
|
14
|
-
self.fixture_name = options.fetch(:like)
|
15
|
-
self.block = options.fetch(: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 ||=
|
32
|
+
@klass ||= proc_class.call
|
33
33
|
rescue NameError
|
34
|
-
raise WrongClassError,
|
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
|
-
|
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(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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?(:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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]]
|
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.
|
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-
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|