rspec-rails-api 0.9.1 → 0.9.2

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: 6251737040f42f5fb8d436ac54ad1c9da02bac286989fcb75496b59e5d96ba18
4
- data.tar.gz: 3c56e86b0ea039a78be9def4601d63f17d4ca92636efab13b4cc07795a243ae5
3
+ metadata.gz: 36fe79a8d00eac7bac5fcf841239e39a73ff8a7c47db046bbe18590e0db4085a
4
+ data.tar.gz: 59e955a181a272b105015901e94268fab2cd67c0119f7cbcef8cc153a8e47450
5
5
  SHA512:
6
- metadata.gz: 8668ae63bca7e69f197d32bdc8347b1c4268b69ce2b6f50ed5e51da5ff5cd472e32ad3b88ed5b1de89148223b6efa51ab7cd321f36a9ef6b1e09d337b34eae37
7
- data.tar.gz: 2c8844c43969bed287cd78ff88dc78f054f5a9fd247737e0d7065d08e604dfd093c6e243a9ff6e9a7be59343f7959d09be32ca24d10d98af888b42d07eed5604
6
+ metadata.gz: e164de7f7023e524ce047c87883d569e82559c0fbfc7311bbdfff4b0fbefa68aceaf653ffc3d7232c750092cdd17d75c1a57837c10c3c34fecf8d650f2507578
7
+ data.tar.gz: 21cef61f13ceeb836165e4779ae0b191577ab31d78ad8677fc53afdbdb10a5880f7a8b6dc557b25d4b9bf3b6e95c8eadae3c9090a58d8cb3f05edda2ee5a7951
data/CHANGELOG.md CHANGED
@@ -18,6 +18,14 @@ Maintenance, in case of rework, dependencies change
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [0.9.2] - 2026-06-14
22
+
23
+ ### Changed
24
+
25
+ - Improved support for `file`s upload : when a payload contains a `Rack::Test::UploadedFile`, it will not be transformed to JSON
26
+ and the example, while not representing a `multipart/form-data` payload, will display something like
27
+ `'<file content: file_name.txt>'` instead of the UploadedFile representation.
28
+
21
29
  ## [0.9.1] - 2025-12-12
22
30
 
23
31
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-rails-api (0.9.1)
4
+ rspec-rails-api (0.9.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,7 +5,7 @@ module RSpec
5
5
  module Api
6
6
  module DSL
7
7
  # These methods will be available in examples (i.e.: 'for_code')
8
- module Example
8
+ module Example # rubocop:disable Metrics/ModuleLength
9
9
  ##
10
10
  # Visits the current example and tests the response
11
11
  #
@@ -101,7 +101,19 @@ module RSpec
101
101
  status_code: status_code,
102
102
  response: response,
103
103
  path_params: request_params[:path_params],
104
- params: request_params[:params])
104
+ params: strip_files(request_params[:params]))
105
+ end
106
+
107
+ # Replaces Rack::Test::UploadedFile content by a string
108
+ #
109
+ # @param data - Data to use in an API call
110
+ # @return Same object with UploadedFile replaced by a string
111
+ def strip_files(data)
112
+ return data.map { |d| strip_files(d) } if data.is_a?(Array)
113
+ return data.transform_values { |v| strip_files(v) } if data.is_a?(Hash)
114
+ return "<file content: #{data.original_filename}>" if data.is_a?(Rack::Test::UploadedFile)
115
+
116
+ data
105
117
  end
106
118
 
107
119
  ##
@@ -113,11 +125,13 @@ module RSpec
113
125
  # @param request_headers [Hash] Custom headers
114
126
  #
115
127
  # @return [Hash] Options for the request
116
- def prepare_request_params(description, request_params = {}, payload = {}, request_headers = {})
128
+ def prepare_request_params(description, request_params = {}, payload = {}, request_headers = {}) # rubocop:disable Metrics/MethodLength
117
129
  example_params = description.split
118
130
  verb = example_params[0].downcase
119
131
 
120
- payload = payload.to_json if verb != 'get'
132
+ has_form_data = contains_file?(payload)
133
+ payload = payload.to_json if verb != 'get' && !has_form_data
134
+ request_headers['Content-Type'] = 'multipart/form-data' if has_form_data
121
135
 
122
136
  {
123
137
  action: verb,
@@ -202,6 +216,21 @@ module RSpec
202
216
  def rra_metadata
203
217
  self.class.metadata[:rra]
204
218
  end
219
+
220
+ # Checks if provided data contains a Rack::Test::UploadedFile
221
+ #
222
+ # @param data - Data used in an API call
223
+ # @return [Boolean]
224
+ def contains_file?(data) # rubocop:disable Metrics/CyclomaticComplexity
225
+ return false unless data.is_a?(Hash) || data.is_a?(Array)
226
+
227
+ iterator = data.is_a?(Hash) ? data.values : data
228
+ iterator.each do |v|
229
+ return true if v.is_a?(Rack::Test::UploadedFile) || (v.is_a?(Hash) && contains_file?(v))
230
+ end
231
+
232
+ false
233
+ end
205
234
  end
206
235
  end
207
236
  end
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Rails
5
5
  module Api
6
- VERSION = '0.9.1'
6
+ VERSION = '0.9.2'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Tancoigne
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-06-14 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: |
13
14
  Create acceptance tests to check the Rails API responses and generate
@@ -53,6 +54,7 @@ metadata:
53
54
  bug_tracker_uri: https://gitlab.com/experimentslabs/rspec-rails-api/issues
54
55
  changelog_uri: https://gitlab.com/experimentslabs/rspec-rails-api/blob/master/CHANGELOG.md
55
56
  rubygems_mfa_required: 'true'
57
+ post_install_message:
56
58
  rdoc_options: []
57
59
  require_paths:
58
60
  - lib
@@ -67,7 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  - !ruby/object:Gem::Version
68
70
  version: '0'
69
71
  requirements: []
70
- rubygems_version: 3.6.9
72
+ rubygems_version: 3.5.22
73
+ signing_key:
71
74
  specification_version: 4
72
75
  summary: Tests standard Rails API responses and generate doc
73
76
  test_files: []