factory_burgers 1.0.0 → 1.1.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: 43c66971abd931b22cd77a4848068e79208f41062d7b94cc9835a865bf1b1fba
4
- data.tar.gz: 2e6dd7ec270142169da16e6db5c8880823f31bb70a7389d4ca0c176879b167af
3
+ metadata.gz: 7adfdace4f86d8ec2d39e60d0f0bb3b8863d1c189d0c6c6ed1a6b59047585b12
4
+ data.tar.gz: 183a11ba6d22a15fc1c245b805d16c22a5998f4923b80f9d0f769aefd62c0cb5
5
5
  SHA512:
6
- metadata.gz: c9ecf2bff205b15aa84b523f274d18d24749bbe9254c1a8ee5b25f9f46027954e3c6231f679fca66eedaa0a3b62f3ff6777f92c60a5ed13e8af0ee9848242562
7
- data.tar.gz: 89fe0e394b3f6a673421502be11de3e1763f276a07b59d9c99d275b5de03ca4b69e8f30d6da7c4c5f94180d8c456ba6acdaa64ce838e2711dfa524652f306666
6
+ metadata.gz: 560cd421fa2de822944d72420d1aa705595b7b3ce15a1193a7df4b426ce8d22fedec42728ee2b8a44ae5134995ec786aa6ec77203353f6ab5e38c5c23ec53261
7
+ data.tar.gz: 28703bd03c2cc1551ae1f4f9812bca12f38f3982c8155bab79d691614653afd36f0d400bbcb47ceb44bcacfd6b813110e6501cca0fa33e541c609480974b432c
@@ -36,7 +36,7 @@ module FactoryBurgers
36
36
  end
37
37
 
38
38
  def find_highest_index_value(klass, column, sql, regex)
39
- matches = klass.where(sql).pluck(column).select { |val| val =~ regex }
39
+ matches = klass.where(sql).pluck(column).grep(regex)
40
40
  return matches.map { |value| value =~ regex && Regexp.last_match(1) }.map(&:to_i).max
41
41
  end
42
42
 
@@ -50,7 +50,7 @@ module FactoryBurgers
50
50
  end
51
51
 
52
52
  module FactoryBotAdapters
53
- #:nodoc:
53
+ # :nodoc:
54
54
  class FactoryBotV6
55
55
  def load_factories
56
56
  FactoryBot.reload
@@ -23,6 +23,9 @@ module FactoryBurgers
23
23
  def factories_for_class(klass)
24
24
  factories.select do |factory|
25
25
  factory.build_class.ancestors.include?(klass)
26
+ rescue NameError
27
+ # Some usages of factories include pseudo "abstract" factory parent classes that do not point to a real class
28
+ false
26
29
  end
27
30
  end
28
31
 
@@ -40,7 +40,7 @@ module FactoryBurgers
40
40
  return [] if attribute_items.nil?
41
41
 
42
42
  attribute_items = attribute_items.select { |attr| attr["name"].present? }
43
- return attribute_items.map { |attr| [attr["name"], attr["value"]] }.to_h
43
+ return attribute_items.to_h { |attr| [attr["name"], attr["value"]] }
44
44
  end
45
45
 
46
46
  def get_resource_owner(owner_type, owner_id)
@@ -5,13 +5,14 @@ module FactoryBurgers
5
5
  # Respond with factory data to display in the main form
6
6
  class Data
7
7
  def call(*)
8
- factories = FactoryBurgers.factory_bot_adapter.factories.sort_by(&:name)
9
- factory_data = factories.map { |factory| factory_data(factory) }
8
+ factories = FactoryBurgers::Introspection.factories
9
+ models = factories.map { |factory| factory_model(factory) }.select(&:valid?)
10
+ factory_data = models.map(&:to_h)
10
11
  return [200, {"Content-Type" => "application/json"}, [JSON.dump(factory_data)]]
11
12
  end
12
13
 
13
- def factory_data(factory)
14
- FactoryBurgers::Models::Factory.new(factory).to_h
14
+ def factory_model(factory)
15
+ FactoryBurgers::Models::Factory.new(factory)
15
16
  end
16
17
  end
17
18
  end
@@ -12,6 +12,10 @@ module FactoryBurgers
12
12
  @factory = factory
13
13
  end
14
14
 
15
+ def valid?
16
+ build_class.present?
17
+ end
18
+
15
19
  def to_h
16
20
  {
17
21
  name: name,
@@ -21,8 +25,8 @@ module FactoryBurgers
21
25
  }
22
26
  end
23
27
 
24
- def to_json(*opts, &blk)
25
- to_h.to_json(*opts, &blk)
28
+ def to_json(...)
29
+ to_h.to_json(...)
26
30
  end
27
31
 
28
32
  def name
@@ -45,6 +49,9 @@ module FactoryBurgers
45
49
 
46
50
  def build_class
47
51
  factory.build_class
52
+ rescue NameError
53
+ # Some usages of factories include pseudo "abstract" factory parent classes that do not point to a real class
54
+ nil
48
55
  end
49
56
 
50
57
  def settable_columns
@@ -56,7 +63,7 @@ module FactoryBurgers
56
63
  end
57
64
  end
58
65
 
59
- #:nodoc:
66
+ # :nodoc:
60
67
  class Attribute
61
68
  attr_reader :column
62
69
 
@@ -68,8 +75,8 @@ module FactoryBurgers
68
75
  {name: name}
69
76
  end
70
77
 
71
- def to_json(*opts, &blk)
72
- to_h.to_json(*opts, &blk)
78
+ def to_json(...)
79
+ to_h.to_json(...)
73
80
  end
74
81
 
75
82
  def name
@@ -77,7 +84,7 @@ module FactoryBurgers
77
84
  end
78
85
  end
79
86
 
80
- #:nodoc:
87
+ # :nodoc:
81
88
  class Trait
82
89
  attr_reader :trait
83
90
 
@@ -89,8 +96,8 @@ module FactoryBurgers
89
96
  {name: name}
90
97
  end
91
98
 
92
- def to_json(*opts, &blk)
93
- to_h.to_json(*opts, &blk)
99
+ def to_json(...)
100
+ to_h.to_json(...)
94
101
  end
95
102
 
96
103
  def name
@@ -1,3 +1,3 @@
1
1
  module FactoryBurgers
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -4,7 +4,7 @@ Dir[Pathname(__dir__).join("factory_burgers/**/*.rb")].sort.each do |file|
4
4
  require file
5
5
  end
6
6
 
7
- #:nodoc:
7
+ # :nodoc:
8
8
  module FactoryBurgers
9
9
  class << self
10
10
  delegate :run_initializers, to: :initializer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_burgers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Schwartz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-12 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -267,7 +267,7 @@ homepage: https://github.com/ozydingo/factory_burgers
267
267
  licenses:
268
268
  - MIT
269
269
  metadata: {}
270
- post_install_message:
270
+ post_install_message:
271
271
  rdoc_options: []
272
272
  require_paths:
273
273
  - lib
@@ -282,8 +282,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
282
  - !ruby/object:Gem::Version
283
283
  version: '0'
284
284
  requirements: []
285
- rubygems_version: 3.0.3
286
- signing_key:
285
+ rubygems_version: 3.4.10
286
+ signing_key:
287
287
  specification_version: 4
288
288
  summary: Bring the power of thoughtbot/factory_bot to manual testing
289
289
  test_files: []