committee 0.4.8 → 0.4.9

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.
@@ -3,6 +3,7 @@ module Committee::Middleware
3
3
  def initialize(app, options={})
4
4
  super
5
5
  @cache = {}
6
+ @call = options[:call]
6
7
  @prefix = options[:prefix]
7
8
  end
8
9
 
@@ -10,11 +11,17 @@ module Committee::Middleware
10
11
  request = Rack::Request.new(env)
11
12
  link_schema, type_schema = @router.routes_request?(request, prefix: @prefix)
12
13
  if type_schema
13
- str = cache(link_schema["method"], link_schema["href"]) do
14
- data = Committee::ResponseGenerator.new(@schema, type_schema, link_schema).call
15
- MultiJson.encode(data, pretty: true)
14
+ headers = { "Content-Type" => "application/json" }
15
+ data = cache(link_schema["method"], link_schema["href"]) do
16
+ Committee::ResponseGenerator.new(@schema, type_schema, link_schema).call
16
17
  end
17
- [200, { "Content-Type" => "application/json" }, [str]]
18
+ if @call
19
+ env["committee.response"] = data
20
+ _, call_headers, _ = @app.call(env)
21
+ headers.merge!(call_headers)
22
+ end
23
+ status = link_schema["rel"] == "create" ? 201 : 200
24
+ [status, headers, [MultiJson.encode(data, pretty: true)]]
18
25
  else
19
26
  @app.call(env)
20
27
  end
@@ -15,6 +15,20 @@ describe Committee::Middleware::Stub do
15
15
  assert_equal ValidApp.keys.sort, data.keys.sort
16
16
  end
17
17
 
18
+ it "responds with 201 on create actions" do
19
+ @app = new_rack_app
20
+ post "/apps"
21
+ assert_equal 201, last_response.status
22
+ end
23
+
24
+ it "optionally calls into application" do
25
+ @app = new_rack_app(call: true)
26
+ get "/apps/heroku-api"
27
+ assert_equal 200, last_response.status
28
+ assert_equal ValidApp,
29
+ MultiJson.decode(last_response.headers["Committee-Response"])
30
+ end
31
+
18
32
  it "takes a prefix" do
19
33
  @app = new_rack_app(prefix: "/v1")
20
34
  get "/v1/apps/heroku-api"
@@ -31,8 +45,9 @@ describe Committee::Middleware::Stub do
31
45
  }.merge(options)
32
46
  Rack::Builder.new {
33
47
  use Committee::Middleware::Stub, options
34
- run lambda { |_|
35
- [200, {}, []]
48
+ run lambda { |env|
49
+ headers = { "Committee-Response" => MultiJson.encode(env["committee.response"]) }
50
+ [200, headers, []]
36
51
  }
37
52
  }
38
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: committee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: