apiculture 0.0.17 → 0.0.18

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
  SHA1:
3
- metadata.gz: 917fb8bfc86e8bc1d1a9d02729434c6af8398c1b
4
- data.tar.gz: 4c73cab2e1f0a8dfb2756175f1037f32a8336d0b
3
+ metadata.gz: d0376c2d819d808e7c8857d3eb6eeea9bc057c7d
4
+ data.tar.gz: 52015f4360aa39a19c0a037f978568ac793a00c7
5
5
  SHA512:
6
- metadata.gz: d0d6b8796a963cd7814bba03afc1904efeb23e901084eab438ce2af8a6379f5e7b5d1474f89cee53401e6d58d94c68be5290c8ed9677b169b9fd85df98cd4117
7
- data.tar.gz: 33a2024a4918f561da343f6df0aa0876b1c458f5ffc9f02d1393284f64af5b5c06811cd65022cb26fa28d9407c332d52f048adcdafdbaa7f7bfc990c52a1eb58
6
+ metadata.gz: '09068eb0cca7bb8d66806bd501220921418d8a7dc02d5e82f8570f18e3014f6b1c0c929bab30c15118b90b7c3534f4226e66c1eb36ebd6b415208d93cfefbead'
7
+ data.tar.gz: f6d7f01b4d95527ca815e1eeaccfbc4e19d28ae6dc8aeaa1281fe50f14166d66bb7895081bb2f4c993d75483dcd5ff8e914f72756b4691f1a2e82b0bcd36f1b6
data/apiculture.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: apiculture 0.0.17 ruby lib
5
+ # stub: apiculture 0.0.18 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "apiculture"
9
- s.version = "0.0.17"
9
+ s.version = "0.0.18"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -3,12 +3,13 @@ require 'json'
3
3
  # Some sugary methods for use within Sinatra, when responding to a request/rendering JSON
4
4
  module Apiculture::SinatraInstanceMethods
5
5
  NEWLINE = "\n"
6
+ DEFAULT = :__default__
6
7
 
7
8
  # Convert the given structure to JSON, set the content-type and
8
9
  # return the JSON string
9
- def json_response(structure, status: 200)
10
+ def json_response(structure, status: DEFAULT)
10
11
  content_type :json
11
- status status
12
+ status(status) unless status == DEFAULT
12
13
  JSON.pretty_generate(structure)
13
14
  end
14
15
 
@@ -1,3 +1,3 @@
1
1
  module Apiculture
2
- VERSION = '0.0.17'
2
+ VERSION = '0.0.18'
3
3
  end
@@ -201,12 +201,16 @@ describe "Apiculture" do
201
201
  api_method :post, '/api-thing/:id_of_thing' do |id|
202
202
  raise 'id_of_thing must be passed' unless id == '123456'
203
203
  raise "id_of_thing must be present in params, but they were #{params.inspect}" unless params.keys.include?('id_of_thing')
204
+ raise "id_of_thing must be string-accessible in params" unless params['id_of_thing'] == '123456'
205
+ raise "id_of_thing must be symbol-accessible in params" unless params[:id_of_thing] == '123456'
204
206
  'All is well'
205
207
  end
206
208
 
207
209
  post '/vanilla-thing/:id_of_thing' do |id|
208
210
  raise 'id_of_thing must be passed' unless id == '123456'
209
211
  raise "id_of_thing must be present in params, but they were #{params.inspect}" unless params.keys.include?('id_of_thing')
212
+ raise "id_of_thing must be string-accessible in params" unless params['id_of_thing'] == '123456'
213
+ raise "id_of_thing must be symbol-accessible in params" unless params[:id_of_thing] == '123456'
210
214
  'All is well'
211
215
  end
212
216
  end
@@ -218,6 +222,22 @@ describe "Apiculture" do
218
222
  expect(last_response).to be_ok
219
223
  end
220
224
 
225
+ it 'does not clobber the status set in a separate mutating call when using json_response' do
226
+ @app_class = Class.new(Sinatra::Base) do
227
+ settings.show_exceptions = false
228
+ settings.raise_errors = true
229
+ extend Apiculture
230
+
231
+ api_method :post, '/api/:id' do
232
+ status 201
233
+ json_response({was_created: true})
234
+ end
235
+ end
236
+
237
+ post '/api/123'
238
+ expect(last_response.status).to eq(201)
239
+ end
240
+
221
241
  it 'raises when describing a route parameter that is not included in the path' do
222
242
  expect {
223
243
  Class.new(Sinatra::Base) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiculture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov