|
153 | 153 | body: "compressed file") |
154 | 154 | end |
155 | 155 |
|
156 | | - it "should return result" do |
157 | | - assert_kind_of Tinify::Result, Tinify::Source.from_buffer("png file").result |
| 156 | + it 'has a `Tinify::Result`' do |
| 157 | + assert_kind_of(Tinify::Result, |
| 158 | + Tinify::Source.from_buffer("png file").result) |
| 159 | + end |
| 160 | + |
| 161 | + it 'has result data' do |
| 162 | + assert_equal('compressed file', |
| 163 | + Tinify::Source.from_buffer("png file").result.data) |
| 164 | + end |
| 165 | + |
| 166 | + it 'is a :get request' do |
| 167 | + Tinify::Source.from_buffer("png file").result |
| 168 | + |
| 169 | + assert_requested(:get, "https://api.tinify.com/some/location", |
| 170 | + times: 1) |
| 171 | + end |
| 172 | + |
| 173 | + it 'is a :post request' do |
| 174 | + stub_request(:post, "https://api.tinify.com/some/location") |
| 175 | + .with(basic_auth: ['api', 'valid'], |
| 176 | + body: '{"preserve":["copyright","location"]}') |
| 177 | + .to_return(status: 200, body: "copyrighted file") |
| 178 | + |
| 179 | + Tinify::Source.from_buffer("png file") |
| 180 | + .preserve("copyright", "location") |
| 181 | + .result |
| 182 | + |
| 183 | + assert_requested(:post, "https://api.tinify.com/some/location", |
| 184 | + times: 1) |
158 | 185 | end |
159 | 186 | end |
160 | 187 |
|
|
167 | 194 | headers: { Location: "https://api.tinify.com/some/location" }, |
168 | 195 | body: '{}') |
169 | 196 |
|
170 | | - stub_request(:get, "https://api.tinify.com/some/location") |
| 197 | + stub_request(:post, "https://api.tinify.com/some/location") |
171 | 198 | .with( |
172 | 199 | basic_auth: ['api', 'valid'], |
173 | 200 | body: '{"preserve":["copyright","location"]}') |
|
192 | 219 | end |
193 | 220 |
|
194 | 221 | it "should include other options if set" do |
195 | | - stub_request(:get, "https://api.tinify.com/some/location") |
| 222 | + stub_request(:post, "https://api.tinify.com/some/location") |
196 | 223 | .with( |
197 | 224 | basic_auth: ['api', 'valid'], |
198 | 225 | body: '{"resize":{"width":400},"preserve":["copyright","location"]}') |
|
214 | 241 | headers: { Location: "https://api.tinify.com/some/location" }, |
215 | 242 | body: '{}') |
216 | 243 |
|
217 | | - stub_request(:get, "https://api.tinify.com/some/location") |
| 244 | + stub_request(:post, "https://api.tinify.com/some/location") |
218 | 245 | .with( |
219 | 246 | basic_auth: ['api', 'valid'], |
220 | 247 | body: '{"resize":{"width":400}}') |
|
241 | 268 | headers: { Location: "https://api.tinify.com/some/location" }, |
242 | 269 | body: '{}') |
243 | 270 |
|
244 | | - stub_request(:get, "https://api.tinify.com/some/location") |
| 271 | + stub_request(:post, "https://api.tinify.com/some/location") |
245 | 272 | .with( |
246 | 273 | basic_auth: ['api', 'valid'], |
247 | 274 | body: '{"convert":{"type":["image/webp"]}}') |
|
268 | 295 | headers: { Location: "https://api.tinify.com/some/location" }, |
269 | 296 | body: '{}') |
270 | 297 |
|
271 | | - stub_request(:get, "https://api.tinify.com/some/location") |
| 298 | + stub_request(:post, "https://api.tinify.com/some/location") |
272 | 299 | .with( |
273 | 300 | basic_auth: ['api', 'valid'], |
274 | 301 | body: '{"transform":{"color":"black"}}') |
|
286 | 313 | end |
287 | 314 |
|
288 | 315 | it "should include other options if set" do |
289 | | - |
290 | | - stub_request(:get, "https://api.tinify.com/some/location"). |
291 | | - with(:body => '{"convert":{"type":["image/webp"]},"transform":{"color":"black"}}', |
292 | | - ). |
293 | | - to_return(:status => 200, :body => "trans-formed-and-coded", :headers => {}) |
| 316 | + stub_request(:post, "https://api.tinify.com/some/location") |
| 317 | + .with(:body => '{"convert":{"type":["image/webp"]},"transform":{"color":"black"}}') |
| 318 | + .to_return(:status => 200, :body => "trans-formed-and-coded", :headers => {}) |
294 | 319 |
|
295 | 320 | result = Tinify::Source.from_buffer("png file").convert(type: ["image/webp"]).transform(color: "black") |
296 | 321 | assert_equal "trans-formed-and-coded", result.to_buffer |
|
0 commit comments