oas_rails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oas_rails/media_type.rb +29 -10
- data/lib/oas_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dff52d1f5445bbcd000de4c14988e919905c7e5ea1bd179b7ac7c458fde9570e
|
4
|
+
data.tar.gz: adba7ada7bc1658bf3b65f85731eef40c5f72ce930b3b087da5be23b4abd45a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 331be1bcbe64381095ab5f62b94154d394340740fe61a43c6463a544c8bc302ae2a89e30b30feedc698673ae4c7eca268b10d59b68e1f607b8eecfdb64917e9b
|
7
|
+
data.tar.gz: edfefc2472d3419045df61ce6ca9a37c48e87d61055b6225af54d7633c8cf08c0471ce15392967c564a866f1e24e322e10defed30ac05736d2b77bd1770fa629
|
data/lib/oas_rails/media_type.rb
CHANGED
@@ -20,23 +20,42 @@ module OasRails
|
|
20
20
|
new(media_type: "", schema:, examples:)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# Searches for examples in test files based on the provided class and test framework.
|
24
|
+
#
|
25
|
+
# This method handles different test frameworks to fetch examples for the given class.
|
26
|
+
# Currently, it supports FactoryBot and fixtures.
|
27
|
+
#
|
28
|
+
# @param klass [Class] the class to search examples for.
|
29
|
+
# @param utils [Module] a utility module that provides the `detect_test_framework` method. Defaults to `Utils`.
|
30
|
+
# @return [Hash] a hash containing examples data or an empty hash if no examples are found.
|
31
|
+
# @example Usage with FactoryBot
|
32
|
+
# search_for_examples_in_tests(klass: User)
|
33
|
+
#
|
34
|
+
# @example Usage with fixtures
|
35
|
+
# search_for_examples_in_tests(klass: Project)
|
36
|
+
#
|
37
|
+
# @example Usage with a custom utils module
|
38
|
+
# custom_utils = Module.new do
|
39
|
+
# def self.detect_test_framework
|
40
|
+
# :factory_bot
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# search_for_examples_in_tests(klass: User, utils: custom_utils)
|
44
|
+
def search_for_examples_in_tests(klass:, utils: Utils)
|
45
|
+
case utils.detect_test_framework
|
25
46
|
when :factory_bot
|
26
47
|
{}
|
27
48
|
# TODO: create examples with FactoryBot
|
28
49
|
when :fixtures
|
29
|
-
# Handle fixtures scenario
|
30
50
|
fixture_file = Rails.root.join('test', 'fixtures', "#{klass.to_s.pluralize.downcase}.yml")
|
31
|
-
fixture_data = YAML.load_file(fixture_file).with_indifferent_access
|
32
51
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
users_hash[name] = { value: { klass.to_s.downcase => attributes } }
|
52
|
+
begin
|
53
|
+
fixture_data = YAML.load_file(fixture_file).with_indifferent_access
|
54
|
+
rescue Errno::ENOENT
|
55
|
+
return {}
|
38
56
|
end
|
39
|
-
|
57
|
+
|
58
|
+
fixture_data.transform_values { |attributes| { value: { klass.to_s.downcase => attributes } } }
|
40
59
|
else
|
41
60
|
{}
|
42
61
|
end
|
data/lib/oas_rails/version.rb
CHANGED