fabrial 0.2.0 → 0.3.0

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: bf013a11226fff5bf52dea812c36fcc95e8912f05d8118a8973727a7864125d6
4
- data.tar.gz: 663a33a75e7e52a7e5f51be1476d0a250dc892a47fe0f8909b673fdeb7b6c23b
3
+ metadata.gz: 86f03b9211c2441a8ca1e341e7bfb202e6d1bdf0cf588f8abc581aea8daf1a68
4
+ data.tar.gz: 9bc2b809e7fa65f979dd7aa268555c4b142d565dacb31cffb1e4805d5b6a89f9
5
5
  SHA512:
6
- metadata.gz: 0b7bafadd06459481ddbc1e93e3598885976b9c1d93d44d8ac2319683554699f802f482988c3265c6dcf11df7ba27af4d45fafffecaf751dbc0b43ce9776f18f
7
- data.tar.gz: 1949a259ec2c8f075241e54a11d9eebad8fde59473501af794b81e193772b26a331af245eeb36f14c247fe423f3b040881602a8115fce8d73a7263adb777cb01
6
+ metadata.gz: c214bb35c6d29c06ebfa3d21b5a93064da81abbc86f3e28e5713ae906b0ca476beaaf40aa60d011b37f7ef10ffffc37ed7a5b5bad3de05cedc704f58be171c44
7
+ data.tar.gz: ac7a67c81a346eebdf6a9440bed3627797ab576a0c15ff247acc7d3280af3c731a491e0ea0dd5a2d9a71d16871fc24fb65932fbc2946fce40cc1c0d673bd7fee
data/.gitignore CHANGED
@@ -7,6 +7,9 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ # Gems should not commit `Gemfile.lock`
11
+ Gemfile.lock
12
+
10
13
  # Appraisal gemfiles
11
14
  /gemfiles/.bundle/
12
15
  /gemfiles/*.gemfile.lock
@@ -47,6 +47,7 @@ Gem::Specification.new do |spec|
47
47
  spec.add_development_dependency 'minitest', '~> 5.12', '>= 5.12.2'
48
48
  spec.add_development_dependency 'minitest-focus', '~> 1.1', '>= 1.1.2'
49
49
  spec.add_development_dependency 'minitest-reporters', '~> 1.3', '>= 1.3.8'
50
+ spec.add_development_dependency 'mocha'
50
51
  spec.add_development_dependency 'pry'
51
52
  spec.add_development_dependency 'pry-byebug'
52
53
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -3,4 +3,11 @@
3
3
  module Fabrial
4
4
  class Error < RuntimeError; end
5
5
  class UnknownClassError < Error; end
6
+ class CreationError < Error
7
+ def message
8
+ return super unless cause
9
+
10
+ "#{super}: #{cause.message}"
11
+ end
12
+ end
6
13
  end
@@ -34,6 +34,28 @@ module Fabrial::Fabricate
34
34
  end
35
35
  end
36
36
 
37
+ def extract_child_records(klass, data)
38
+ children = data.select do |type, v|
39
+ # Must have nested data
40
+ [Array, Hash].any? { |c| v.is_a? c } &&
41
+ # Must be a class that we can instantiate
42
+ get_class(type) &&
43
+
44
+ # Even if it has the same name as a Model in the system, if it is also
45
+ # the name of a column in the table, assume the data is for a serialzed
46
+ # field and not a nested relation. Ex: Requests have a serialized field
47
+ # called content and there is also a Content model in the system.
48
+ (
49
+ # If they are using a class as the key, then always choose the class
50
+ # over the field.
51
+ type.is_a?(Class) ||
52
+
53
+ !column_names(klass).include?(type.to_s)
54
+ )
55
+ end
56
+ data.extract!(*children.keys)
57
+ end
58
+
37
59
  private
38
60
 
39
61
  def contains_return?(objects)
@@ -121,7 +143,12 @@ module Fabrial::Fabricate
121
143
  type_col = klass.inheritance_column.try :to_sym
122
144
  type = data.delete(type_col).try :safe_constantize
123
145
  type ||= klass
124
- create type, data.reverse_merge(associations)
146
+ begin
147
+ create type, data.reverse_merge(associations)
148
+ rescue
149
+ raise Fabrial::CreationError,
150
+ "Error creating #{type.name} with data: #{data}"
151
+ end
125
152
  end
126
153
 
127
154
  def collect_associations(klass, ancestors)
@@ -132,28 +159,6 @@ module Fabrial::Fabricate
132
159
  associations
133
160
  end
134
161
 
135
- def extract_child_records(klass, data)
136
- children = data.select do |type, v|
137
- # Must have nested data
138
- [Array, Hash].any? { |c| v.is_a? c } &&
139
- # Must be a class that we can instantiate
140
- get_class(type) &&
141
-
142
- # Even if it has the same name as a Model in the system, if it is also
143
- # the name of a column in the table, assume the data is for a serialzed
144
- # field and not a nested relation. Ex: Requests have a serialized field
145
- # called content and there is also a Content model in the system.
146
- (
147
- # If they are using a class as the key, then always choose the class
148
- # over the field.
149
- type.is_a?(Class) ||
150
-
151
- !column_names(klass).include?(type.to_s)
152
- )
153
- end
154
- data.extract!(*children.keys)
155
- end
156
-
157
162
  def column_names(klass)
158
163
  klass.column_names
159
164
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fabrial
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  public_constant :VERSION
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Mickelson
@@ -140,6 +140,20 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: 1.3.8
143
+ - !ruby/object:Gem::Dependency
144
+ name: mocha
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
143
157
  - !ruby/object:Gem::Dependency
144
158
  name: pry
145
159
  requirement: !ruby/object:Gem::Requirement
@@ -227,7 +241,6 @@ files:
227
241
  - ".travis.yml"
228
242
  - Appraisals
229
243
  - Gemfile
230
- - Gemfile.lock
231
244
  - LICENSE.txt
232
245
  - README.md
233
246
  - Rakefile
@@ -1,89 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fabrial (0.1.0)
5
- activerecord (> 4.2.0, < 6.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (5.2.3)
11
- activesupport (= 5.2.3)
12
- activerecord (5.2.3)
13
- activemodel (= 5.2.3)
14
- activesupport (= 5.2.3)
15
- arel (>= 9.0)
16
- activesupport (5.2.3)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- ansi (1.5.0)
22
- appraisal (2.2.0)
23
- bundler
24
- rake
25
- thor (>= 0.14.0)
26
- arel (9.0.0)
27
- ast (2.4.0)
28
- builder (3.2.3)
29
- byebug (11.0.1)
30
- coderay (1.1.2)
31
- concurrent-ruby (1.1.5)
32
- database_cleaner (1.7.0)
33
- i18n (1.7.0)
34
- concurrent-ruby (~> 1.0)
35
- jaro_winkler (1.5.3)
36
- method_source (0.9.2)
37
- minitest (5.12.2)
38
- minitest-focus (1.1.2)
39
- minitest (>= 4, < 6)
40
- minitest-reporters (1.3.8)
41
- ansi
42
- builder
43
- minitest (>= 5.0)
44
- ruby-progressbar
45
- parallel (1.17.0)
46
- parser (2.6.5.0)
47
- ast (~> 2.4.0)
48
- pry (0.12.2)
49
- coderay (~> 1.1.0)
50
- method_source (~> 0.9.0)
51
- pry-byebug (3.7.0)
52
- byebug (~> 11.0)
53
- pry (~> 0.10)
54
- rainbow (3.0.0)
55
- rake (13.0.0)
56
- rubocop (0.75.0)
57
- jaro_winkler (~> 1.5.1)
58
- parallel (~> 1.10)
59
- parser (>= 2.6)
60
- rainbow (>= 2.2.2, < 4.0)
61
- ruby-progressbar (~> 1.7)
62
- unicode-display_width (>= 1.4.0, < 1.7)
63
- ruby-progressbar (1.10.1)
64
- sqlite3 (1.3.13)
65
- thor (0.20.3)
66
- thread_safe (0.3.6)
67
- tzinfo (1.2.5)
68
- thread_safe (~> 0.1)
69
- unicode-display_width (1.6.0)
70
-
71
- PLATFORMS
72
- ruby
73
-
74
- DEPENDENCIES
75
- appraisal (~> 2.2, >= 2.2.0)
76
- bundler (~> 1.0)
77
- database_cleaner
78
- fabrial!
79
- minitest (~> 5.12, >= 5.12.2)
80
- minitest-focus (~> 1.1, >= 1.1.2)
81
- minitest-reporters (~> 1.3, >= 1.3.8)
82
- pry
83
- pry-byebug
84
- rake (~> 13.0)
85
- rubocop (~> 0.75.0)
86
- sqlite3 (~> 1.3.0)
87
-
88
- BUNDLED WITH
89
- 1.17.3