gitlab-grape-swagger 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.github/dependabot.yml +20 -0
  4. data/.github/workflows/ci.yml +45 -0
  5. data/.gitignore +44 -0
  6. data/.gitlab-ci.yml +19 -0
  7. data/.rspec +3 -0
  8. data/.rubocop.yml +136 -0
  9. data/.rubocop_todo.yml +60 -0
  10. data/.ruby-gemset +1 -0
  11. data/CHANGELOG.md +671 -0
  12. data/CONTRIBUTING.md +126 -0
  13. data/Dangerfile +3 -0
  14. data/Gemfile +45 -0
  15. data/Gemfile.lock +249 -0
  16. data/LICENSE.txt +20 -0
  17. data/README.md +1772 -0
  18. data/RELEASING.md +82 -0
  19. data/Rakefile +20 -0
  20. data/UPGRADING.md +201 -0
  21. data/example/api/endpoints.rb +131 -0
  22. data/example/api/entities.rb +18 -0
  23. data/example/config.ru +42 -0
  24. data/example/example_requests.postman_collection +146 -0
  25. data/example/splines.png +0 -0
  26. data/example/swagger-example.png +0 -0
  27. data/grape-swagger.gemspec +23 -0
  28. data/lib/grape-swagger/doc_methods/build_model_definition.rb +68 -0
  29. data/lib/grape-swagger/doc_methods/data_type.rb +110 -0
  30. data/lib/grape-swagger/doc_methods/extensions.rb +101 -0
  31. data/lib/grape-swagger/doc_methods/file_params.rb +17 -0
  32. data/lib/grape-swagger/doc_methods/format_data.rb +53 -0
  33. data/lib/grape-swagger/doc_methods/headers.rb +20 -0
  34. data/lib/grape-swagger/doc_methods/move_params.rb +209 -0
  35. data/lib/grape-swagger/doc_methods/operation_id.rb +32 -0
  36. data/lib/grape-swagger/doc_methods/optional_object.rb +30 -0
  37. data/lib/grape-swagger/doc_methods/parse_params.rb +190 -0
  38. data/lib/grape-swagger/doc_methods/path_string.rb +52 -0
  39. data/lib/grape-swagger/doc_methods/produces_consumes.rb +15 -0
  40. data/lib/grape-swagger/doc_methods/status_codes.rb +21 -0
  41. data/lib/grape-swagger/doc_methods/tag_name_description.rb +34 -0
  42. data/lib/grape-swagger/doc_methods/version.rb +20 -0
  43. data/lib/grape-swagger/doc_methods.rb +142 -0
  44. data/lib/grape-swagger/endpoint/params_parser.rb +76 -0
  45. data/lib/grape-swagger/endpoint.rb +476 -0
  46. data/lib/grape-swagger/errors.rb +17 -0
  47. data/lib/grape-swagger/instance.rb +7 -0
  48. data/lib/grape-swagger/model_parsers.rb +42 -0
  49. data/lib/grape-swagger/rake/oapi_tasks.rb +135 -0
  50. data/lib/grape-swagger/version.rb +5 -0
  51. data/lib/grape-swagger.rb +174 -0
  52. data/spec/issues/267_nested_namespaces.rb +55 -0
  53. data/spec/issues/403_versions_spec.rb +124 -0
  54. data/spec/issues/427_entity_as_string_spec.rb +39 -0
  55. data/spec/issues/430_entity_definitions_spec.rb +94 -0
  56. data/spec/issues/532_allow_custom_format_spec.rb +42 -0
  57. data/spec/issues/533_specify_status_code_spec.rb +78 -0
  58. data/spec/issues/537_enum_values_spec.rb +50 -0
  59. data/spec/issues/539_array_post_body_spec.rb +65 -0
  60. data/spec/issues/542_array_of_type_in_post_body_spec.rb +46 -0
  61. data/spec/issues/553_align_array_put_post_params_spec.rb +152 -0
  62. data/spec/issues/572_array_post_body_spec.rb +51 -0
  63. data/spec/issues/579_align_put_post_parameters_spec.rb +185 -0
  64. data/spec/issues/582_file_response_spec.rb +55 -0
  65. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
  66. data/spec/issues/605_root_route_documentation_spec.rb +23 -0
  67. data/spec/issues/650_params_array_spec.rb +65 -0
  68. data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +100 -0
  69. data/spec/issues/680_keep_204_error_schemas_spec.rb +55 -0
  70. data/spec/issues/721_set_default_parameter_location_based_on_consumes_spec.rb +62 -0
  71. data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
  72. data/spec/issues/776_multiple_presents_spec.rb +59 -0
  73. data/spec/issues/784_extensions_on_params_spec.rb +42 -0
  74. data/spec/issues/809_utf8_routes_spec.rb +55 -0
  75. data/spec/issues/832_array_hash_float_decimal_spec.rb +114 -0
  76. data/spec/issues/847_route_param_options_spec.rb +37 -0
  77. data/spec/issues/873_wildcard_segments_path_parameters_spec.rb +28 -0
  78. data/spec/issues/878_optional_path_segments_spec.rb +29 -0
  79. data/spec/issues/881_handle_file_params_spec.rb +38 -0
  80. data/spec/issues/883_query_array_parameter_spec.rb +46 -0
  81. data/spec/issues/884_dont_document_non_schema_examples_spec.rb +49 -0
  82. data/spec/issues/887_prevent_duplicate_operation_ids_spec.rb +35 -0
  83. data/spec/lib/data_type_spec.rb +111 -0
  84. data/spec/lib/endpoint/params_parser_spec.rb +124 -0
  85. data/spec/lib/endpoint_spec.rb +153 -0
  86. data/spec/lib/extensions_spec.rb +185 -0
  87. data/spec/lib/format_data_spec.rb +115 -0
  88. data/spec/lib/model_parsers_spec.rb +104 -0
  89. data/spec/lib/move_params_spec.rb +444 -0
  90. data/spec/lib/oapi_tasks_spec.rb +163 -0
  91. data/spec/lib/operation_id_spec.rb +55 -0
  92. data/spec/lib/optional_object_spec.rb +47 -0
  93. data/spec/lib/parse_params_spec.rb +68 -0
  94. data/spec/lib/path_string_spec.rb +101 -0
  95. data/spec/lib/produces_consumes_spec.rb +116 -0
  96. data/spec/lib/tag_name_description_spec.rb +80 -0
  97. data/spec/lib/version_spec.rb +28 -0
  98. data/spec/spec_helper.rb +39 -0
  99. data/spec/support/empty_model_parser.rb +23 -0
  100. data/spec/support/grape_version.rb +13 -0
  101. data/spec/support/mock_parser.rb +23 -0
  102. data/spec/support/model_parsers/entity_parser.rb +334 -0
  103. data/spec/support/model_parsers/mock_parser.rb +346 -0
  104. data/spec/support/model_parsers/representable_parser.rb +406 -0
  105. data/spec/support/namespace_tags.rb +93 -0
  106. data/spec/support/the_paths_definitions.rb +109 -0
  107. data/spec/swagger_v2/api_documentation_spec.rb +42 -0
  108. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
  109. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +48 -0
  110. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +36 -0
  111. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +79 -0
  112. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +145 -0
  113. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +137 -0
  114. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +56 -0
  115. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +64 -0
  116. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +58 -0
  117. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +57 -0
  118. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +109 -0
  119. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +48 -0
  120. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +153 -0
  121. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +355 -0
  122. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +217 -0
  123. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +247 -0
  124. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +80 -0
  125. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +147 -0
  126. data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +135 -0
  127. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +216 -0
  128. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +53 -0
  129. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
  130. data/spec/swagger_v2/api_swagger_v2_spec.rb +245 -0
  131. data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +93 -0
  132. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +90 -0
  133. data/spec/swagger_v2/boolean_params_spec.rb +38 -0
  134. data/spec/swagger_v2/default_api_spec.rb +175 -0
  135. data/spec/swagger_v2/deprecated_field_spec.rb +25 -0
  136. data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
  137. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +130 -0
  138. data/spec/swagger_v2/errors_spec.rb +77 -0
  139. data/spec/swagger_v2/float_api_spec.rb +36 -0
  140. data/spec/swagger_v2/form_params_spec.rb +76 -0
  141. data/spec/swagger_v2/grape-swagger_spec.rb +17 -0
  142. data/spec/swagger_v2/guarded_endpoint_spec.rb +162 -0
  143. data/spec/swagger_v2/hide_api_spec.rb +147 -0
  144. data/spec/swagger_v2/host_spec.rb +43 -0
  145. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +57 -0
  146. data/spec/swagger_v2/mount_override_api_spec.rb +58 -0
  147. data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
  148. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +122 -0
  149. data/spec/swagger_v2/namespace_tags_spec.rb +78 -0
  150. data/spec/swagger_v2/namespaced_api_spec.rb +121 -0
  151. data/spec/swagger_v2/nicknamed_api_spec.rb +25 -0
  152. data/spec/swagger_v2/operation_id_api_spec.rb +27 -0
  153. data/spec/swagger_v2/param_multi_type_spec.rb +82 -0
  154. data/spec/swagger_v2/param_type_spec.rb +95 -0
  155. data/spec/swagger_v2/param_values_spec.rb +180 -0
  156. data/spec/swagger_v2/params_array_collection_format_spec.rb +105 -0
  157. data/spec/swagger_v2/params_array_spec.rb +225 -0
  158. data/spec/swagger_v2/params_example_spec.rb +38 -0
  159. data/spec/swagger_v2/params_hash_spec.rb +77 -0
  160. data/spec/swagger_v2/params_nested_spec.rb +92 -0
  161. data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
  162. data/spec/swagger_v2/reference_entity_spec.rb +129 -0
  163. data/spec/swagger_v2/security_requirement_spec.rb +46 -0
  164. data/spec/swagger_v2/simple_mounted_api_spec.rb +332 -0
  165. data/spec/version_spec.rb +10 -0
  166. metadata +225 -0
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::Extensions do
6
+ context 'it should not break method introspection' do
7
+ describe '.method' do
8
+ describe 'method introspection' do
9
+ specify do
10
+ expect(described_class.method(described_class.methods.first)).to be_a(Method)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ describe '#find_definition' do
17
+ subject { described_class }
18
+
19
+ let(:method) { :get }
20
+ let(:status) { 200 }
21
+
22
+ before { allow(subject).to receive(:method).and_return(method) }
23
+
24
+ describe 'no response for status' do
25
+ let(:path) { { get: { responses: {} } } }
26
+
27
+ specify do
28
+ definition = subject.find_definition(status, path)
29
+ expect(definition).to be_nil
30
+ end
31
+ end
32
+
33
+ describe 'response found' do
34
+ let(:model) { 'Item' }
35
+
36
+ describe 'ref given' do
37
+ let(:path) do
38
+ { get: { responses: { 200 => { schema: { '$ref' => "#/definitions/#{model}" } } } } }
39
+ end
40
+ specify do
41
+ definition = subject.find_definition(status, path)
42
+ expect(definition).to eql model
43
+ end
44
+ end
45
+
46
+ describe 'items given' do
47
+ let(:path) do
48
+ { get: { responses: { 200 => { schema: { 'items' => { '$ref' => "#/definitions/#{model}" } } } } } }
49
+ end
50
+ specify do
51
+ definition = subject.find_definition(status, path)
52
+ expect(definition).to eql model
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#extended? and extension' do
59
+ subject { described_class }
60
+ describe 'return false (default)' do
61
+ let(:part) { { foo: 'bar', bar: 'foo' } }
62
+
63
+ specify do
64
+ expect(subject.extended?(part)).to be false
65
+ expect(subject.extension(part)).to be_empty
66
+ end
67
+ end
68
+
69
+ describe 'return true' do
70
+ specify do
71
+ part = { foo: 'bar', bar: 'foo', x: 'something' }
72
+ expect(subject.extended?(part)).to be true
73
+ expect(subject.extension(part)).to eql(x: 'something')
74
+ expect(subject.extended?(part, :x)).to be true
75
+ expect(subject.extension(part, :x)).to eql(x: 'something')
76
+ end
77
+
78
+ specify do
79
+ part = { foo: 'bar', bar: 'foo', x_path: 'something' }
80
+ expect(subject.extended?(part, :x_path)).to be true
81
+ expect(subject.extension(part, :x_path)).to eql(x_path: 'something')
82
+ end
83
+
84
+ specify do
85
+ part = { foo: 'bar', bar: 'foo', x_def: 'something' }
86
+ expect(subject.extended?(part, :x_def)).to be true
87
+ expect(subject.extension(part, :x_def)).to eql(x_def: 'something')
88
+ end
89
+
90
+ specify do
91
+ part = { foo: 'bar', bar: 'foo', x_path: 'something', x_def: 'something' }
92
+ expect(subject.extended?(part, :x_path)).to be true
93
+ expect(subject.extension(part, :x_path)).to eql(x_path: 'something')
94
+ expect(subject.extended?(part, :x_def)).to be true
95
+ expect(subject.extension(part, :x_def)).to eql(x_def: 'something')
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'concatenate' do
101
+ describe 'not nested' do
102
+ describe 'simple' do
103
+ let(:extensions) { { x: { key_1: 'foo' } } }
104
+ let(:result) { { 'x-key_1' => 'foo' } }
105
+ subject { described_class.concatenate(extensions) }
106
+
107
+ specify do
108
+ expect(subject).to eql result
109
+ end
110
+ end
111
+
112
+ describe 'multiple' do
113
+ let(:extensions) { { x: { key_1: 'foo', key_2: 'bar' } } }
114
+ let(:result) { { 'x-key_1' => 'foo', 'x-key_2' => 'bar' } }
115
+ subject { described_class.concatenate(extensions) }
116
+
117
+ specify do
118
+ expect(subject).to eql result
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'nested' do
124
+ describe 'simple' do
125
+ let(:extensions) { { x: { key_1: { key_2: 'foo' } } } }
126
+ let(:result) { { 'x-key_1' => { key_2: 'foo' } } }
127
+ subject { described_class.concatenate(extensions) }
128
+
129
+ specify do
130
+ expect(subject).to eql result
131
+ end
132
+ end
133
+
134
+ describe 'simple multiple' do
135
+ let(:extensions) { { x: { key_1: { key_2: 'foo', key_3: 'bar' } } } }
136
+ let(:result) { { 'x-key_1' => { key_2: 'foo', key_3: 'bar' } } }
137
+ subject { described_class.concatenate(extensions) }
138
+
139
+ specify do
140
+ expect(subject).to eql result
141
+ end
142
+ end
143
+
144
+ describe 'simple deeper' do
145
+ let(:extensions) { { x: { key_1: { key_2: { key_3: 'foo' } } } } }
146
+ let(:result) { { 'x-key_1' => { key_2: { key_3: 'foo' } } } }
147
+ subject { described_class.concatenate(extensions) }
148
+
149
+ specify do
150
+ expect(subject).to eql result
151
+ end
152
+ end
153
+
154
+ describe 'multiple' do
155
+ let(:extensions) { { x: { key_1: { key_3: 'foo' }, key_2: { key_3: 'bar' } } } }
156
+ let(:result) { { 'x-key_1' => { key_3: 'foo' }, 'x-key_2' => { key_3: 'bar' } } }
157
+ subject { described_class.concatenate(extensions) }
158
+
159
+ specify do
160
+ expect(subject).to eql result
161
+ end
162
+ end
163
+ end
164
+
165
+ describe 'real example' do
166
+ let(:extensions) do
167
+ { x: {
168
+ 'amazon-apigateway-auth' => { type: 'none' },
169
+ 'amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
170
+ } }
171
+ end
172
+ let(:result) do
173
+ {
174
+ 'x-amazon-apigateway-auth' => { type: 'none' },
175
+ 'x-amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
176
+ }
177
+ end
178
+ subject { described_class.concatenate(extensions) }
179
+
180
+ specify do
181
+ expect(subject).to eql result
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::FormatData do
6
+ let(:subject) { GrapeSwagger::DocMethods::FormatData }
7
+
8
+ [true, false].each do |array_use_braces|
9
+ context 'when param is nested in a param of array type' do
10
+ let(:braces) { array_use_braces ? '[]' : '' }
11
+ let(:params) do
12
+ [
13
+ { in: 'formData', name: "param1#{braces}", type: 'array', items: { type: 'string' } },
14
+ { in: 'formData', name: 'param1[param2]', type: 'string' }
15
+ ]
16
+ end
17
+
18
+ it 'skips root parameter' do
19
+ expect(subject.to_format(params).first).not_to have_key "param1#{braces}"
20
+ end
21
+
22
+ it 'Move array type to param2' do
23
+ expect(subject.to_format(params).first).to include(name: "param1#{braces}[param2]", type: 'array')
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'when param is nested in a param of hash type' do
29
+ let(:params) { [{ in: 'formData', type: 'object', name: 'param1' }, { in: 'formData', name: 'param1[param2]', type: 'string' }] }
30
+
31
+ it 'skips root parameter' do
32
+ expect(subject.to_format(params).first).not_to have_key 'param1'
33
+ end
34
+
35
+ it 'Move array type to param2' do
36
+ expect(subject.to_format(params).first).to include(name: 'param1[param2]', type: 'string')
37
+ end
38
+ end
39
+
40
+ context 'when params contain a complex array' do
41
+ let(:params) do
42
+ [
43
+ { name: 'id', required: true, type: 'string' },
44
+ { name: 'description', required: false, type: 'string' },
45
+ { name: 'stuffs', required: true, type: 'array' },
46
+ { name: 'stuffs[id]', required: true, type: 'string' }
47
+ ]
48
+ end
49
+
50
+ let(:expected_params) do
51
+ [
52
+ { name: 'id', required: true, type: 'string' },
53
+ { name: 'description', required: false, type: 'string' },
54
+ { name: 'stuffs[id]', required: true, type: 'array', items: { type: 'string' } }
55
+ ]
56
+ end
57
+
58
+ it 'parses params correctly and adds array type all concerned elements' do
59
+ expect(subject.to_format(params)).to eq expected_params
60
+ end
61
+
62
+ context 'when array params are not contiguous with parent array' do
63
+ let(:params) do
64
+ [
65
+ { name: 'id', required: true, type: 'string' },
66
+ { name: 'description', required: false, type: 'string' },
67
+ { name: 'stuffs', required: true, type: 'array' },
68
+ { name: 'stuffs[owners]', required: true, type: 'array' },
69
+ { name: 'stuffs[creators]', required: true, type: 'array' },
70
+ { name: 'stuffs[owners][id]', required: true, type: 'string' },
71
+ { name: 'stuffs[creators][id]', required: true, type: 'string' },
72
+ { name: 'stuffs_and_things', required: true, type: 'string' }
73
+ ]
74
+ end
75
+
76
+ let(:expected_params) do
77
+ [
78
+ { name: 'id', required: true, type: 'string' },
79
+ { name: 'description', required: false, type: 'string' },
80
+ { name: 'stuffs[owners][id]', required: true, type: 'array', items: { type: 'string' } },
81
+ { name: 'stuffs[creators][id]', required: true, type: 'array', items: { type: 'string' } },
82
+ { name: 'stuffs_and_things', required: true, type: 'string' }
83
+ ]
84
+ end
85
+
86
+ it 'parses params correctly and adds array type all concerned elements' do
87
+ expect(subject.to_format(params)).to eq expected_params
88
+ end
89
+ end
90
+
91
+ context 'when array params are not related' do
92
+ let(:params) do
93
+ [
94
+ { name: 'id', required: true, type: 'string' },
95
+ { name: 'description', required: false, type: 'string' },
96
+ { name: 'ids[]', required: true, type: 'array', items: { type: 'string' } },
97
+ { name: 'user_ids[]', required: true, type: 'array', items: { type: 'string' } }
98
+ ]
99
+ end
100
+
101
+ let(:expected_params) do
102
+ [
103
+ { name: 'id', required: true, type: 'string' },
104
+ { name: 'description', required: false, type: 'string' },
105
+ { name: 'ids[]', required: true, type: 'array', items: { type: 'string' } },
106
+ { name: 'user_ids[]', required: true, type: 'array', items: { type: 'string' } }
107
+ ]
108
+ end
109
+
110
+ it 'parses params correctly and adds array type all concerned elements' do
111
+ expect(subject.to_format(params)).to eq expected_params
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::ModelParsers do
6
+ let(:model_parsers) { described_class.new }
7
+ let(:parser) { Class.new }
8
+ let(:parser2) { Class.new }
9
+ let(:parser3) { Class.new }
10
+
11
+ describe '#register' do
12
+ describe 'successfully register new parser' do
13
+ before do
14
+ model_parsers.register(parser, Class)
15
+ end
16
+
17
+ specify do
18
+ expect(model_parsers.to_a).to eq([[parser, 'Class']])
19
+ end
20
+ end
21
+
22
+ describe 'should be empty if no registered parsers' do
23
+ specify do
24
+ expect(model_parsers.to_a).to be_empty
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#insert_before' do
30
+ describe 'SomeModelParser2 should be first parser' do
31
+ before do
32
+ model_parsers.register(parser, Class)
33
+ model_parsers.register(parser3, Class)
34
+ model_parsers.insert_before(parser, parser2, Class)
35
+ end
36
+
37
+ specify do
38
+ expect(model_parsers.count).to eq(3)
39
+ expect(model_parsers.to_a.first).to eq([parser2, Class])
40
+ end
41
+ end
42
+
43
+ describe 'SomeModelParser2 should be inserted anyway if SomeModelParser not registered' do
44
+ before do
45
+ model_parsers.register(parser3, Class)
46
+ model_parsers.insert_before(parser, parser2, Class)
47
+ end
48
+
49
+ specify do
50
+ expect(model_parsers.count).to eq(2)
51
+ expect(model_parsers.to_a).to include([parser2, Class])
52
+ end
53
+ end
54
+
55
+ describe 'SomeModelParser2 should be inserted anyway if model parsers is empty' do
56
+ before do
57
+ model_parsers.insert_before(parser, parser2, Class)
58
+ end
59
+
60
+ specify do
61
+ expect(model_parsers.count).to eq(1)
62
+ expect(model_parsers.to_a).to include([parser2, Class])
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#insert_after' do
68
+ describe 'SomeModelParser2 should be second parser' do
69
+ before do
70
+ model_parsers.register(parser, Class)
71
+ model_parsers.register(parser3, Class)
72
+ model_parsers.insert_after(parser, parser2, Class)
73
+ end
74
+
75
+ specify do
76
+ expect(model_parsers.count).to eq(3)
77
+ expect(model_parsers.to_a[1]).to eq([parser2, Class])
78
+ end
79
+ end
80
+
81
+ describe 'SomeModelParser2 should be inserted anyway if SomeModelParser not registered' do
82
+ before do
83
+ model_parsers.register(parser3, Class)
84
+ model_parsers.insert_after(parser, parser2, Class)
85
+ end
86
+
87
+ specify do
88
+ expect(model_parsers.count).to eq(2)
89
+ expect(model_parsers.to_a).to include([parser2, Class])
90
+ end
91
+ end
92
+
93
+ describe 'SomeModelParser2 should be inserted anyway if model parsers is empty' do
94
+ before do
95
+ model_parsers.insert_after(parser, parser2, Class)
96
+ end
97
+
98
+ specify do
99
+ expect(model_parsers.count).to eq(1)
100
+ expect(model_parsers.to_a).to include([parser2, Class])
101
+ end
102
+ end
103
+ end
104
+ end