wt-rspec-grape 0.3.0 → 0.4.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: d335b8193d4ac649846cc892cefa101024e3cbb12c7c3298fb298e27af479fc3
4
- data.tar.gz: c93816828f2c1ae7501991dc4d3e69528810d7de728c63dc44f3de8a4ec44ead
3
+ metadata.gz: 557b54745719600189a9b4ae344430fc6c426ed0fd9b72a63307a5c707c47faf
4
+ data.tar.gz: eb71e02ea97135769162b523699e4092cf9ee37bd5ef7447e9806f9adb11cee2
5
5
  SHA512:
6
- metadata.gz: 73bd17120280ce221b3000eb820fba7c4910abfb3e8b7da46c547b50be0e582c6ef51bd0ada045cd3b0023fb815a7923b9a5e9218bcf98aa64fa3e366cbc772e
7
- data.tar.gz: e7c0d79bdc99367f2d724b917659e3fff3e15b8e2d0d7c17455622d6351a4266c636c0b703b4458d35ee1a3caa998073723904c80bfba3c572b4ed2eb36c86c7
6
+ metadata.gz: '083d403ab5d91ccab4bac5b98013f5ceba01b35b45a5bfd63f7e4b353fe1497a294a585207ccd271ec7af0c5564307a5a323cf571cb94515353c2306d54afdc7'
7
+ data.tar.gz: ecaa68b2d9dcb7641383ca8ab7572664f995300b40182cce7ede30a08b7305767dae113ecc106a317d60cc65b6a40a69787f5046393c2ace502be8aa8a3b3068
data/README.md CHANGED
@@ -88,6 +88,12 @@ Params can be passed to `call_api` method:
88
88
  call_api({foo: :bar})
89
89
  ```
90
90
 
91
+ Body params are sent as JSON. When params contain a `Rack::Test::UploadedFile` (at any nesting level), they are sent as `multipart/form-data` instead:
92
+
93
+ ```ruby
94
+ call_api(file: Rack::Test::UploadedFile.new('spec/fixtures/doc.pdf', 'application/pdf'))
95
+ ```
96
+
91
97
  ### Stubbing API helpers
92
98
 
93
99
  rspec-grape provides two methods to stub API helpers: `expect_endpoint_to` and `expect_endpoint_not_to`. You can easily write:
@@ -41,7 +41,7 @@ module RSpec
41
41
  url = api_url
42
42
  end
43
43
 
44
- if %w[GET HEAD DELETE].include?(api_method.to_s.upcase) || params.empty?
44
+ if %w[GET HEAD DELETE].include?(api_method.to_s.upcase) || params.empty? || file_upload?(params)
45
45
  self.send(api_method, url, params)
46
46
  else
47
47
  self.send(api_method, url, {}, { 'CONTENT_TYPE' => 'application/json', input: params.to_json })
@@ -66,6 +66,15 @@ module RSpec
66
66
  def parameterized_url?
67
67
  api_url =~ /\/:/
68
68
  end
69
+
70
+ def file_upload?(value)
71
+ case value
72
+ when Rack::Test::UploadedFile then true
73
+ when Hash then value.values.any? { |v| file_upload?(v) }
74
+ when Array then value.any? { |v| file_upload?(v) }
75
+ else false
76
+ end
77
+ end
69
78
  end
70
79
  end
71
80
  end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Grape
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wt-rspec-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tarapon