batch_api 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/changelog.md +14 -0
- data/lib/batch_api/configuration.rb +1 -1
- data/lib/batch_api/internal_middleware/decode_json_body.rb +7 -3
- data/lib/batch_api/operation/rack.rb +4 -1
- data/lib/batch_api/version.rb +1 -1
- data/readme.md +2 -2
- data/spec/dummy/Gemfile +1 -0
- data/spec/dummy/Gemfile.lock +8 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +6 -37
- data/spec/dummy/config/boot.rb +2 -9
- data/spec/dummy/config/environment.rb +3 -3
- data/spec/dummy/config/environments/development.rb +22 -18
- data/spec/dummy/config/environments/production.rb +46 -34
- data/spec/dummy/config/environments/test.rb +19 -14
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +6 -5
- data/spec/dummy/config/initializers/mime_types.rb +0 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -6
- data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
- data/spec/dummy/config/locales/en.yml +20 -2
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/log/test.log +7369 -46081
- data/spec/lib/batch_api_spec.rb +3 -3
- data/spec/lib/batch_error_spec.rb +3 -3
- data/spec/lib/configuration_spec.rb +3 -3
- data/spec/lib/error_wrapper_spec.rb +20 -20
- data/spec/lib/internal_middleware/decode_json_body_spec.rb +13 -6
- data/spec/lib/internal_middleware/response_filter_spec.rb +3 -3
- data/spec/lib/internal_middleware_spec.rb +15 -13
- data/spec/lib/operation/rack_spec.rb +58 -50
- data/spec/lib/operation/rails_spec.rb +10 -10
- data/spec/lib/processor/executor_spec.rb +5 -5
- data/spec/lib/processor/sequential_spec.rb +10 -10
- data/spec/lib/processor_spec.rb +23 -21
- data/spec/lib/rack_middleware_spec.rb +17 -17
- data/spec/lib/response_spec.rb +9 -9
- data/spec/{integration → rack-integration}/rails_spec.rb +3 -3
- data/spec/{integration → rack-integration}/shared_examples.rb +24 -18
- data/spec/{integration → rack-integration}/sinatra_integration_spec.rb +5 -0
- data/spec/spec_helper.rb +15 -1
- data/spec/support/sinatra_xhr.rb +13 -0
- metadata +47 -135
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -1742
data/spec/lib/batch_api_spec.rb
CHANGED
@@ -4,17 +4,17 @@ require 'batch_api'
|
|
4
4
|
describe BatchApi do
|
5
5
|
describe ".config" do
|
6
6
|
it "has a reader for config" do
|
7
|
-
BatchApi.config.
|
7
|
+
expect(BatchApi.config).not_to be_nil
|
8
8
|
end
|
9
9
|
|
10
10
|
it "provides a default config" do
|
11
|
-
BatchApi.config.
|
11
|
+
expect(BatchApi.config).to be_a(BatchApi::Configuration)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe ".rails?" do
|
16
16
|
it "returns a value we can't test based on whether Rails is defined" do
|
17
|
-
BatchApi.rails
|
17
|
+
expect(BatchApi.rails?).not_to be_nil
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -9,15 +9,15 @@ describe BatchApi::Errors::BatchError do
|
|
9
9
|
BatchApi::Errors::MalformedOperationError
|
10
10
|
].each do |klass|
|
11
11
|
it "provides a #{klass} error based on ArgumentError" do
|
12
|
-
klass.superclass.
|
12
|
+
expect(klass.superclass).to eq(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "is is also a BatchError" do
|
16
|
-
klass.new.
|
16
|
+
expect(klass.new).to be_a(BatchApi::Errors::BatchError)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "has a status code of 422" do
|
20
|
-
klass.new.status_code.
|
20
|
+
expect(klass.new.status_code).to eq(422)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -15,13 +15,13 @@ module BatchApi
|
|
15
15
|
opt, defa = option, default
|
16
16
|
describe "##{opt}" do
|
17
17
|
it "has an accessor for #{opt}" do
|
18
|
-
stubby =
|
18
|
+
stubby = double
|
19
19
|
config.send("#{opt}=", stubby)
|
20
|
-
config.send(opt).
|
20
|
+
expect(config.send(opt)).to eq(stubby)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "defaults #{opt} to #{defa.inspect}" do
|
24
|
-
config.send(opt).
|
24
|
+
expect(config.send(opt)).to eq(defa)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -12,57 +12,57 @@ describe BatchApi::ErrorWrapper do
|
|
12
12
|
|
13
13
|
describe "#body" do
|
14
14
|
it "includes the message in the body" do
|
15
|
-
error.body[:error][:message].
|
15
|
+
expect(error.body[:error][:message]).to eq(exception.message)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "includes the backtrace if it should be there" do
|
19
|
-
error.
|
20
|
-
error.body[:error][:backtrace].
|
19
|
+
allow(error).to receive(:expose_backtrace?).and_return(true)
|
20
|
+
expect(error.body[:error][:backtrace]).to eq(exception.backtrace)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "includes the backtrace if it should be there" do
|
24
|
-
error.
|
25
|
-
error.body[:backtrace].
|
24
|
+
allow(error).to receive(:expose_backtrace?).and_return(false)
|
25
|
+
expect(error.body[:backtrace]).to be_nil
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#render" do
|
30
30
|
it "returns the appropriate status" do
|
31
|
-
status =
|
32
|
-
error.
|
33
|
-
error.render[0].
|
31
|
+
status = double
|
32
|
+
allow(error).to receive(:status_code).and_return(status)
|
33
|
+
expect(error.render[0]).to eq(status)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "returns appropriate content type" do
|
37
|
-
ctype =
|
38
|
-
BatchApi::RackMiddleware.
|
39
|
-
error.render[1].
|
37
|
+
ctype = double
|
38
|
+
allow(BatchApi::RackMiddleware).to receive(:content_type).and_return(ctype)
|
39
|
+
expect(error.render[1]).to eq(ctype)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "returns the JSONified body as the 2nd" do
|
43
|
-
error.render[2].
|
43
|
+
expect(error.render[2]).to eq([MultiJson.dump(error.body)])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#status_code" do
|
48
48
|
it "returns 500 by default" do
|
49
|
-
error.status_code.
|
49
|
+
expect(error.status_code).to eq(500)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "returns another status code if the error supports that" do
|
53
53
|
err = StandardError.new
|
54
|
-
code =
|
55
|
-
err.
|
56
|
-
BatchApi::ErrorWrapper.new(err).status_code.
|
54
|
+
code = double
|
55
|
+
allow(err).to receive(:status_code).and_return(code)
|
56
|
+
expect(BatchApi::ErrorWrapper.new(err).status_code).to eq(code)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe ".expose_backtrace?" do
|
61
61
|
it "returns false if Rails.env.production?" do
|
62
|
-
Rails.
|
63
|
-
BatchApi::ErrorWrapper.expose_backtrace
|
64
|
-
Rails.env.
|
65
|
-
BatchApi::ErrorWrapper.expose_backtrace
|
62
|
+
allow(Rails).to receive(:env).and_return(double(test?: false, production?: true, development?: false))
|
63
|
+
expect(BatchApi::ErrorWrapper.expose_backtrace?).to be_falsey
|
64
|
+
allow(Rails.env).to receive(:production?).and_return(false)
|
65
|
+
expect(BatchApi::ErrorWrapper.expose_backtrace?).to be_truthy
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BatchApi::InternalMiddleware::DecodeJsonBody do
|
4
|
-
let(:app) {
|
4
|
+
let(:app) { double("app", call: result) }
|
5
5
|
let(:decoder) { BatchApi::InternalMiddleware::DecodeJsonBody.new(app) }
|
6
|
-
let(:env) {
|
6
|
+
let(:env) { double("env") }
|
7
7
|
let(:json) { {"data" => "is_json", "more" => {"hi" => "there"} } }
|
8
8
|
let(:result) {
|
9
9
|
BatchApi::Response.new([
|
@@ -17,20 +17,27 @@ describe BatchApi::InternalMiddleware::DecodeJsonBody do
|
|
17
17
|
context "for json results" do
|
18
18
|
it "decodes JSON results for application/json responses" do
|
19
19
|
result = decoder.call(env)
|
20
|
-
result.body.
|
20
|
+
expect(result.body).to eq(json)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't change anything else" do
|
24
24
|
result = decoder.call(env)
|
25
|
-
result.status.
|
26
|
-
result.headers.
|
25
|
+
expect(result.status).to eq(200)
|
26
|
+
expect(result.headers).to eq({"Content-Type" => "application/json"})
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context "for non-JSON responses" do
|
31
31
|
it "doesn't decode" do
|
32
32
|
result.headers = {"Content-Type" => "text/html"}
|
33
|
-
decoder.call(env).body.
|
33
|
+
expect(decoder.call(env).body).to eq(MultiJson.dump(json))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "for empty responses" do
|
38
|
+
it "doesn't try to parse" do
|
39
|
+
result.body = ""
|
40
|
+
expect(decoder.call(env).body).to eq("")
|
34
41
|
end
|
35
42
|
end
|
36
43
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BatchApi::InternalMiddleware::ResponseFilter do
|
4
|
-
let(:app) {
|
4
|
+
let(:app) { double("app", call: result) }
|
5
5
|
let(:surpressor) { BatchApi::InternalMiddleware::ResponseFilter.new(app) }
|
6
6
|
let(:env) { {
|
7
|
-
op:
|
7
|
+
op: double("operation", options: {"silent" => true})
|
8
8
|
} }
|
9
9
|
|
10
10
|
let(:result) {
|
@@ -20,7 +20,7 @@ describe BatchApi::InternalMiddleware::ResponseFilter do
|
|
20
20
|
context "for successful (200-299) results" do
|
21
21
|
it "empties the response so its as_json is empty" do
|
22
22
|
surpressor.call(env)
|
23
|
-
result.as_json.
|
23
|
+
expect(result.as_json).to eq({})
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -20,7 +20,7 @@ describe BatchApi::InternalMiddleware do
|
|
20
20
|
builder.instance_eval(
|
21
21
|
&BatchApi::InternalMiddleware::DEFAULT_BATCH_MIDDLEWARE
|
22
22
|
)
|
23
|
-
builder.middlewares.
|
23
|
+
expect(builder.middlewares).to be_empty
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "internal middleware defaults" do
|
@@ -31,38 +31,40 @@ describe BatchApi::InternalMiddleware do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "builds a per-op middleware with the response silencer" do
|
34
|
-
builder.middlewares[0].
|
34
|
+
expect(builder.middlewares[0]).to eq(
|
35
35
|
[BatchApi::InternalMiddleware::ResponseFilter, []]
|
36
|
+
)
|
36
37
|
end
|
37
38
|
|
38
39
|
it "builds a per-op middleware with the JSON decoder" do
|
39
|
-
builder.middlewares[1].
|
40
|
+
expect(builder.middlewares[1]).to eq(
|
40
41
|
[BatchApi::InternalMiddleware::DecodeJsonBody, []]
|
42
|
+
)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
describe ".batch_stack" do
|
45
47
|
# we can't use stubs inside the procs since they're instance_eval'd
|
46
48
|
let(:global_config) { Proc.new { use "Global" } }
|
47
|
-
let(:strategy) {
|
48
|
-
let(:processor) {
|
49
|
+
let(:strategy) { double("strategy") }
|
50
|
+
let(:processor) { double("processor", strategy: strategy) }
|
49
51
|
let(:stack) { BatchApi::InternalMiddleware.batch_stack(processor) }
|
50
52
|
|
51
53
|
before :each do
|
52
|
-
BatchApi.config.
|
54
|
+
allow(BatchApi.config).to receive(:batch_middleware).and_return(global_config)
|
53
55
|
stub_const("Middleware::Builder", FakeBuilder)
|
54
56
|
end
|
55
57
|
|
56
58
|
it "builds the stack with the right number of wares" do
|
57
|
-
stack.middlewares.length.
|
59
|
+
expect(stack.middlewares.length).to eq(2)
|
58
60
|
end
|
59
61
|
|
60
62
|
it "builds a middleware stack starting with the configured global wares" do
|
61
|
-
stack.middlewares[0].first.
|
63
|
+
expect(stack.middlewares[0].first).to eq("Global")
|
62
64
|
end
|
63
65
|
|
64
66
|
it "inserts the appropriate strategy from the processor" do
|
65
|
-
stack.middlewares[1].first.
|
67
|
+
expect(stack.middlewares[1].first).to eq(strategy)
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
@@ -72,20 +74,20 @@ describe BatchApi::InternalMiddleware do
|
|
72
74
|
let(:stack) { BatchApi::InternalMiddleware.operation_stack }
|
73
75
|
|
74
76
|
before :each do
|
75
|
-
BatchApi.config.
|
77
|
+
allow(BatchApi.config).to receive(:operation_middleware).and_return(op_config)
|
76
78
|
stub_const("Middleware::Builder", FakeBuilder)
|
77
79
|
end
|
78
80
|
|
79
81
|
it "builds the stack with the right number of wares" do
|
80
|
-
stack.middlewares.length.
|
82
|
+
expect(stack.middlewares.length).to eq(2)
|
81
83
|
end
|
82
84
|
|
83
85
|
it "builds a middleware stack including the configured per-op wares" do
|
84
|
-
stack.middlewares[0].first.
|
86
|
+
expect(stack.middlewares[0].first).to eq("Op")
|
85
87
|
end
|
86
88
|
|
87
89
|
it "builds a middleware stack ending with the executor" do
|
88
|
-
stack.middlewares[1].first.
|
90
|
+
expect(stack.middlewares[1].first).to eq(BatchApi::Processor::Executor)
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
@@ -12,7 +12,7 @@ describe BatchApi::Operation::Rack do
|
|
12
12
|
|
13
13
|
# for env, see bottom of file - it's long
|
14
14
|
let(:operation) { BatchApi::Operation::Rack.new(op_params, env, app) }
|
15
|
-
let(:app) {
|
15
|
+
let(:app) { double("application", call: [200, {}, ["foo"]]) }
|
16
16
|
|
17
17
|
describe "accessors" do
|
18
18
|
[
|
@@ -21,9 +21,9 @@ describe BatchApi::Operation::Rack do
|
|
21
21
|
].each do |a|
|
22
22
|
attr = a
|
23
23
|
it "has an accessor for #{attr}" do
|
24
|
-
value =
|
24
|
+
value = double
|
25
25
|
operation.send("#{attr}=", value)
|
26
|
-
operation.send(attr).
|
26
|
+
expect(operation.send(attr)).to eq(value)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -32,38 +32,38 @@ describe BatchApi::Operation::Rack do
|
|
32
32
|
["method", "url", "params", "headers"].each do |a|
|
33
33
|
attr = a
|
34
34
|
it "extracts the #{attr} information from the operation params" do
|
35
|
-
operation.send(attr).
|
35
|
+
expect(operation.send(attr)).to eq(op_params[attr])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
it "sets options to the op" do
|
40
|
-
operation.options.
|
40
|
+
expect(operation.options).to eq(op_params)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "defaults method to get if not provided" do
|
44
44
|
op = BatchApi::Operation::Rack.new(op_params.except("method"), env, app)
|
45
|
-
op.method.
|
45
|
+
expect(op.method).to eq("get")
|
46
46
|
end
|
47
47
|
|
48
48
|
it "defaults params to {} if not provided" do
|
49
49
|
op = BatchApi::Operation::Rack.new(op_params.except("params"), env, app)
|
50
|
-
op.params.
|
50
|
+
expect(op.params).to eq({})
|
51
51
|
end
|
52
52
|
|
53
53
|
it "defaults headers to {} if not provided" do
|
54
54
|
op = BatchApi::Operation::Rack.new(op_params.except("headers"), env, app)
|
55
|
-
op.headers.
|
55
|
+
expect(op.headers).to eq({})
|
56
56
|
end
|
57
57
|
|
58
58
|
it "does a deep dup of the env" do
|
59
|
-
operation.env.
|
59
|
+
expect(operation.env).to eq(env)
|
60
60
|
|
61
61
|
flat_env = env.to_a.flatten
|
62
62
|
operation.env.to_a.flatten.each_with_index do |obj, index|
|
63
63
|
# this is a rough test for deep dup -- make sure the objects
|
64
64
|
# that aren't symbols aren't actually the same objects in memory
|
65
65
|
if obj.is_a?(Hash) || obj.is_a?(Array)
|
66
|
-
obj.object_id.
|
66
|
+
expect(obj.object_id).not_to eq(flat_env[index].object_id)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -79,64 +79,72 @@ describe BatchApi::Operation::Rack do
|
|
79
79
|
describe "#process_env" do
|
80
80
|
let(:processed_env) { operation.tap {|o| o.process_env}.env }
|
81
81
|
|
82
|
+
before { BatchApi.config.stub(endpoint: '/api/batch') }
|
83
|
+
|
82
84
|
it "merges any headers in in the right format" do
|
83
85
|
key = "HTTP_FOO" # as defined above in op_params
|
84
86
|
|
85
|
-
processed_env[key].
|
87
|
+
expect(processed_env[key]).not_to eq(env[key])
|
86
88
|
# in this case, it's a batch controller
|
87
|
-
processed_env[key].
|
89
|
+
expect(processed_env[key]).to eq(op_params["headers"]["foo"])
|
88
90
|
end
|
89
91
|
|
90
92
|
it "preserves existing headers" do
|
91
|
-
processed_env["HTTP_PREVIOUS_HEADERS"].
|
93
|
+
expect(processed_env["HTTP_PREVIOUS_HEADERS"]).to eq(env["HTTP_PREVIOUS_HEADERS"])
|
92
94
|
end
|
93
95
|
|
94
96
|
it "updates the method" do
|
95
97
|
key = "REQUEST_METHOD"
|
96
|
-
processed_env[key].
|
97
|
-
processed_env[key].
|
98
|
+
expect(processed_env[key]).not_to eq(env[key])
|
99
|
+
expect(processed_env[key]).to eq("POST")
|
98
100
|
end
|
99
101
|
|
100
102
|
it "updates the REQUEST_URI" do
|
101
103
|
key = "REQUEST_URI"
|
102
|
-
processed_env[key].
|
103
|
-
processed_env[key].
|
104
|
+
expect(processed_env[key]).not_to eq(env[key])
|
105
|
+
expect(processed_env[key]).to eq("http://localhost:3000#{op_params["url"]}")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "works if REQUEST_URI is blank" do
|
109
|
+
key = "REQUEST_URI"
|
110
|
+
env.delete(key)
|
111
|
+
expect(processed_env[key]).to be_nil
|
104
112
|
end
|
105
113
|
|
106
114
|
it "updates the REQUEST_PATH with the path component (w/o params)" do
|
107
115
|
key = "REQUEST_PATH"
|
108
|
-
processed_env[key].
|
109
|
-
processed_env[key].
|
116
|
+
expect(processed_env[key]).not_to eq(env[key])
|
117
|
+
expect(processed_env[key]).to eq(op_params["url"].split("?").first)
|
110
118
|
end
|
111
119
|
|
112
120
|
it "updates the original fullpath" do
|
113
121
|
key = "ORIGINAL_FULLPATH"
|
114
|
-
processed_env[key].
|
115
|
-
processed_env[key].
|
122
|
+
expect(processed_env[key]).not_to eq(env[key])
|
123
|
+
expect(processed_env[key]).to eq(op_params["url"])
|
116
124
|
end
|
117
125
|
|
118
126
|
it "updates the PATH_INFO" do
|
119
127
|
key = "PATH_INFO"
|
120
|
-
processed_env[key].
|
121
|
-
processed_env[key].
|
128
|
+
expect(processed_env[key]).not_to eq(env[key])
|
129
|
+
expect(processed_env[key]).to eq(op_params["url"])
|
122
130
|
end
|
123
131
|
|
124
132
|
it "updates the rack query string" do
|
125
133
|
key = "rack.request.query_string"
|
126
|
-
processed_env[key].
|
127
|
-
processed_env[key].
|
134
|
+
expect(processed_env[key]).not_to eq(env[key])
|
135
|
+
expect(processed_env[key]).to eq(op_params["url"].split("?").last)
|
128
136
|
end
|
129
137
|
|
130
138
|
it "updates the QUERY_STRING" do
|
131
139
|
key = "QUERY_STRING"
|
132
|
-
processed_env[key].
|
133
|
-
processed_env[key].
|
140
|
+
expect(processed_env[key]).not_to eq(env[key])
|
141
|
+
expect(processed_env[key]).to eq(op_params["url"].split("?").last)
|
134
142
|
end
|
135
143
|
|
136
144
|
it "updates the form hash" do
|
137
145
|
key = "rack.request.form_hash"
|
138
|
-
processed_env[key].
|
139
|
-
processed_env[key].
|
146
|
+
expect(processed_env[key]).not_to eq(env[key])
|
147
|
+
expect(processed_env[key]).to eq(op_params["params"])
|
140
148
|
end
|
141
149
|
|
142
150
|
context "query_hash" do
|
@@ -144,14 +152,14 @@ describe BatchApi::Operation::Rack do
|
|
144
152
|
operation.method = "get"
|
145
153
|
processed_env = operation.tap {|o| o.process_env}.env
|
146
154
|
key = "rack.request.query_hash"
|
147
|
-
processed_env[key].
|
148
|
-
processed_env[key].
|
155
|
+
expect(processed_env[key]).not_to eq(env[key])
|
156
|
+
expect(processed_env[key]).to eq(op_params["params"])
|
149
157
|
end
|
150
158
|
|
151
159
|
it "sets it to nil for a POST" do
|
152
160
|
key = "rack.request.query_hash"
|
153
|
-
processed_env[key].
|
154
|
-
processed_env[key].
|
161
|
+
expect(processed_env[key]).not_to eq(env[key])
|
162
|
+
expect(processed_env[key]).to be_nil
|
155
163
|
end
|
156
164
|
end
|
157
165
|
end
|
@@ -161,39 +169,39 @@ describe BatchApi::Operation::Rack do
|
|
161
169
|
let(:result) { [
|
162
170
|
200,
|
163
171
|
{header: "footer"},
|
164
|
-
|
172
|
+
double(body: "{\"data\":2}", cookies: nil)
|
165
173
|
] }
|
166
|
-
let(:processed_env) {
|
174
|
+
let(:processed_env) { double }
|
167
175
|
|
168
176
|
before :each do
|
169
|
-
operation.
|
177
|
+
allow(operation).to receive(:process_env) { operation.env = processed_env }
|
170
178
|
end
|
171
179
|
|
172
180
|
it "executes the call with the application" do
|
173
|
-
app.
|
181
|
+
expect(app).to receive(:call).with(processed_env)
|
174
182
|
operation.execute
|
175
183
|
end
|
176
184
|
|
177
185
|
it "returns a BatchAPI::Response made from the result" do
|
178
|
-
response =
|
179
|
-
app.
|
180
|
-
BatchApi::Response.
|
181
|
-
operation.execute.
|
186
|
+
response = double
|
187
|
+
allow(app).to receive(:call).and_return(result)
|
188
|
+
expect(BatchApi::Response).to receive(:new).with(result).and_return(response)
|
189
|
+
expect(operation.execute).to eq(response)
|
182
190
|
end
|
183
191
|
|
184
192
|
it "returns a BatchApi::Response from an ErrorWrapper for errors" do
|
185
193
|
err = StandardError.new
|
186
|
-
result, rendered, response =
|
187
|
-
b_err =
|
194
|
+
result, rendered, response = double, double, double
|
195
|
+
b_err = double("batch error", render: rendered)
|
188
196
|
|
189
197
|
# simulate the error
|
190
|
-
app.
|
198
|
+
allow(app).to receive(:call).and_raise(err)
|
191
199
|
# we'll create the BatchError
|
192
|
-
BatchApi::ErrorWrapper.
|
200
|
+
expect(BatchApi::ErrorWrapper).to receive(:new).with(err).and_return(b_err)
|
193
201
|
# render that as the response
|
194
|
-
BatchApi::Response.
|
202
|
+
expect(BatchApi::Response).to receive(:new).with(rendered).and_return(response)
|
195
203
|
# and return the response overall
|
196
|
-
operation.execute.
|
204
|
+
expect(operation.execute).to eq(response)
|
197
205
|
end
|
198
206
|
end
|
199
207
|
end
|
@@ -208,7 +216,7 @@ describe BatchApi::Operation::Rack do
|
|
208
216
|
"REMOTE_ADDR"=>"127.0.0.1",
|
209
217
|
"REMOTE_HOST"=>"1035.spotilocal.com",
|
210
218
|
"REQUEST_METHOD"=>"REPORT",
|
211
|
-
"REQUEST_URI"=>"http://localhost:3000/batch",
|
219
|
+
"REQUEST_URI"=>"http://localhost:3000/api/batch",
|
212
220
|
"SCRIPT_NAME"=>"",
|
213
221
|
"SERVER_NAME"=>"localhost",
|
214
222
|
"SERVER_PORT"=>"3000",
|
@@ -226,8 +234,8 @@ describe BatchApi::Operation::Rack do
|
|
226
234
|
"rack.run_once"=>false,
|
227
235
|
"rack.url_scheme"=>"http",
|
228
236
|
"HTTP_VERSION"=>"HTTP/1.1",
|
229
|
-
"REQUEST_PATH"=>"/batch",
|
230
|
-
"ORIGINAL_FULLPATH"=>"/batch",
|
237
|
+
"REQUEST_PATH"=>"/api/batch",
|
238
|
+
"ORIGINAL_FULLPATH"=>"/api/batch",
|
231
239
|
"rack.request.form_input"=>StringIO.new("{\"ops\":{}}"),
|
232
240
|
"rack.request.form_hash"=>{"{\"ops\":{}}"=>nil},
|
233
241
|
"rack.request.form_vars"=>"{\"ops\":{}}",
|