evil-client 0.3.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +0 -11
- data/.gitignore +1 -0
- data/.rspec +0 -1
- data/.rubocop.yml +22 -19
- data/.travis.yml +1 -0
- data/CHANGELOG.md +251 -6
- data/LICENSE.txt +3 -1
- data/README.md +47 -81
- data/docs/helpers/body.md +93 -0
- data/docs/helpers/connection.md +19 -0
- data/docs/helpers/headers.md +72 -0
- data/docs/helpers/http_method.md +39 -0
- data/docs/helpers/let.md +14 -0
- data/docs/helpers/logger.md +24 -0
- data/docs/helpers/middleware.md +56 -0
- data/docs/helpers/operation.md +103 -0
- data/docs/helpers/option.md +50 -0
- data/docs/helpers/path.md +37 -0
- data/docs/helpers/query.md +59 -0
- data/docs/helpers/response.md +40 -0
- data/docs/helpers/scope.md +121 -0
- data/docs/helpers/security.md +102 -0
- data/docs/helpers/validate.md +68 -0
- data/docs/index.md +70 -78
- data/docs/license.md +5 -1
- data/docs/rspec.md +96 -0
- data/evil-client.gemspec +10 -8
- data/lib/evil/client.rb +126 -72
- data/lib/evil/client/builder.rb +47 -0
- data/lib/evil/client/builder/operation.rb +40 -0
- data/lib/evil/client/builder/scope.rb +31 -0
- data/lib/evil/client/chaining.rb +17 -0
- data/lib/evil/client/connection.rb +60 -20
- data/lib/evil/client/container.rb +66 -0
- data/lib/evil/client/container/operation.rb +23 -0
- data/lib/evil/client/container/scope.rb +28 -0
- data/lib/evil/client/exceptions/definition_error.rb +15 -0
- data/lib/evil/client/exceptions/name_error.rb +32 -0
- data/lib/evil/client/exceptions/response_error.rb +42 -0
- data/lib/evil/client/exceptions/type_error.rb +29 -0
- data/lib/evil/client/exceptions/validation_error.rb +27 -0
- data/lib/evil/client/formatter.rb +49 -0
- data/lib/evil/client/formatter/form.rb +45 -0
- data/lib/evil/client/formatter/multipart.rb +33 -0
- data/lib/evil/client/formatter/part.rb +66 -0
- data/lib/evil/client/formatter/text.rb +21 -0
- data/lib/evil/client/resolver.rb +84 -0
- data/lib/evil/client/resolver/body.rb +22 -0
- data/lib/evil/client/resolver/format.rb +30 -0
- data/lib/evil/client/resolver/headers.rb +46 -0
- data/lib/evil/client/resolver/http_method.rb +34 -0
- data/lib/evil/client/resolver/middleware.rb +36 -0
- data/lib/evil/client/resolver/query.rb +39 -0
- data/lib/evil/client/resolver/request.rb +96 -0
- data/lib/evil/client/resolver/response.rb +26 -0
- data/lib/evil/client/resolver/security.rb +113 -0
- data/lib/evil/client/resolver/uri.rb +35 -0
- data/lib/evil/client/rspec.rb +127 -0
- data/lib/evil/client/schema.rb +105 -0
- data/lib/evil/client/schema/operation.rb +177 -0
- data/lib/evil/client/schema/scope.rb +73 -0
- data/lib/evil/client/settings.rb +172 -0
- data/lib/evil/client/settings/validator.rb +64 -0
- data/mkdocs.yml +21 -15
- data/spec/features/custom_connection_spec.rb +17 -0
- data/spec/features/operation/middleware_spec.rb +50 -0
- data/spec/features/operation/options_spec.rb +71 -0
- data/spec/features/operation/request_spec.rb +94 -0
- data/spec/features/operation/response_spec.rb +48 -0
- data/spec/features/scope/options_spec.rb +52 -0
- data/spec/fixtures/locales/en.yml +16 -0
- data/spec/fixtures/test_client.rb +76 -0
- data/spec/spec_helper.rb +18 -6
- data/spec/support/fixtures_helper.rb +7 -0
- data/spec/unit/builder/operation_spec.rb +90 -0
- data/spec/unit/builder/scope_spec.rb +84 -0
- data/spec/unit/client_spec.rb +137 -0
- data/spec/unit/connection_spec.rb +78 -0
- data/spec/unit/container/operation_spec.rb +81 -0
- data/spec/unit/container/scope_spec.rb +61 -0
- data/spec/unit/container_spec.rb +107 -0
- data/spec/unit/exceptions/definition_error_spec.rb +15 -0
- data/spec/unit/exceptions/name_error_spec.rb +77 -0
- data/spec/unit/exceptions/response_error_spec.rb +22 -0
- data/spec/unit/exceptions/type_error_spec.rb +71 -0
- data/spec/unit/exceptions/validation_error_spec.rb +13 -0
- data/spec/unit/formatter/form_spec.rb +27 -0
- data/spec/unit/formatter/multipart_spec.rb +23 -0
- data/spec/unit/formatter/part_spec.rb +49 -0
- data/spec/unit/formatter/text_spec.rb +37 -0
- data/spec/unit/formatter_spec.rb +46 -0
- data/spec/unit/resolver/body_spec.rb +65 -0
- data/spec/unit/resolver/format_spec.rb +66 -0
- data/spec/unit/resolver/headers_spec.rb +93 -0
- data/spec/unit/resolver/http_method_spec.rb +67 -0
- data/spec/unit/resolver/middleware_spec.rb +83 -0
- data/spec/unit/resolver/query_spec.rb +85 -0
- data/spec/unit/resolver/request_spec.rb +121 -0
- data/spec/unit/resolver/response_spec.rb +64 -0
- data/spec/unit/resolver/security_spec.rb +156 -0
- data/spec/unit/resolver/uri_spec.rb +117 -0
- data/spec/unit/rspec_spec.rb +342 -0
- data/spec/unit/schema/operation_spec.rb +309 -0
- data/spec/unit/schema/scope_spec.rb +110 -0
- data/spec/unit/schema_spec.rb +157 -0
- data/spec/unit/settings/validator_spec.rb +128 -0
- data/spec/unit/settings_spec.rb +248 -0
- metadata +192 -135
- data/docs/base_url.md +0 -38
- data/docs/documentation.md +0 -9
- data/docs/headers.md +0 -59
- data/docs/http_method.md +0 -31
- data/docs/model.md +0 -173
- data/docs/operation.md +0 -0
- data/docs/overview.md +0 -0
- data/docs/path.md +0 -48
- data/docs/query.md +0 -99
- data/docs/responses.md +0 -66
- data/docs/security.md +0 -102
- data/docs/settings.md +0 -32
- data/lib/evil/client/connection/net_http.rb +0 -57
- data/lib/evil/client/dsl.rb +0 -127
- data/lib/evil/client/dsl/base.rb +0 -26
- data/lib/evil/client/dsl/files.rb +0 -37
- data/lib/evil/client/dsl/headers.rb +0 -16
- data/lib/evil/client/dsl/http_method.rb +0 -24
- data/lib/evil/client/dsl/operation.rb +0 -91
- data/lib/evil/client/dsl/operations.rb +0 -41
- data/lib/evil/client/dsl/path.rb +0 -25
- data/lib/evil/client/dsl/query.rb +0 -16
- data/lib/evil/client/dsl/response.rb +0 -61
- data/lib/evil/client/dsl/responses.rb +0 -29
- data/lib/evil/client/dsl/scope.rb +0 -27
- data/lib/evil/client/dsl/security.rb +0 -57
- data/lib/evil/client/dsl/verifier.rb +0 -35
- data/lib/evil/client/middleware.rb +0 -81
- data/lib/evil/client/middleware/base.rb +0 -11
- data/lib/evil/client/middleware/merge_security.rb +0 -20
- data/lib/evil/client/middleware/normalize_headers.rb +0 -17
- data/lib/evil/client/middleware/stringify_form.rb +0 -40
- data/lib/evil/client/middleware/stringify_json.rb +0 -19
- data/lib/evil/client/middleware/stringify_multipart.rb +0 -36
- data/lib/evil/client/middleware/stringify_multipart/part.rb +0 -36
- data/lib/evil/client/middleware/stringify_query.rb +0 -35
- data/lib/evil/client/operation.rb +0 -34
- data/lib/evil/client/operation/request.rb +0 -26
- data/lib/evil/client/operation/response.rb +0 -39
- data/lib/evil/client/operation/response_error.rb +0 -13
- data/lib/evil/client/operation/unexpected_response_error.rb +0 -19
- data/spec/features/instantiation_spec.rb +0 -68
- data/spec/features/middleware_spec.rb +0 -79
- data/spec/features/operation_with_documentation_spec.rb +0 -41
- data/spec/features/operation_with_files_spec.rb +0 -40
- data/spec/features/operation_with_form_body_spec.rb +0 -158
- data/spec/features/operation_with_headers_spec.rb +0 -99
- data/spec/features/operation_with_http_method_spec.rb +0 -45
- data/spec/features/operation_with_json_body_spec.rb +0 -156
- data/spec/features/operation_with_nested_responses_spec.rb +0 -95
- data/spec/features/operation_with_path_spec.rb +0 -47
- data/spec/features/operation_with_query_spec.rb +0 -84
- data/spec/features/operation_with_security_spec.rb +0 -228
- data/spec/features/scoping_spec.rb +0 -48
- data/spec/support/test_client.rb +0 -15
- data/spec/unit/evil/client/connection/net_http_spec.rb +0 -38
- data/spec/unit/evil/client/dsl/files_spec.rb +0 -37
- data/spec/unit/evil/client/dsl/operation_spec.rb +0 -374
- data/spec/unit/evil/client/dsl/operations_spec.rb +0 -29
- data/spec/unit/evil/client/dsl/scope_spec.rb +0 -32
- data/spec/unit/evil/client/dsl/security_spec.rb +0 -135
- data/spec/unit/evil/client/middleware/merge_security_spec.rb +0 -32
- data/spec/unit/evil/client/middleware/normalize_headers_spec.rb +0 -17
- data/spec/unit/evil/client/middleware/stringify_form_spec.rb +0 -63
- data/spec/unit/evil/client/middleware/stringify_json_spec.rb +0 -61
- data/spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb +0 -59
- data/spec/unit/evil/client/middleware/stringify_multipart_spec.rb +0 -62
- data/spec/unit/evil/client/middleware/stringify_query_spec.rb +0 -40
- data/spec/unit/evil/client/middleware_spec.rb +0 -46
- data/spec/unit/evil/client/operation/request_spec.rb +0 -49
- data/spec/unit/evil/client/operation/response_spec.rb +0 -63
@@ -1,29 +0,0 @@
|
|
1
|
-
describe Evil::Client::DSL::Operations do
|
2
|
-
let(:operations) { described_class.new }
|
3
|
-
let(:settings) do
|
4
|
-
double(:settings, version: 1, user: "foo", password: "bar")
|
5
|
-
end
|
6
|
-
|
7
|
-
before do
|
8
|
-
operations.register(nil) do |settings|
|
9
|
-
http_method :post
|
10
|
-
security { basic_auth settings.user, settings.password }
|
11
|
-
end
|
12
|
-
|
13
|
-
operations.register(:find_user) do |_|
|
14
|
-
http_method :get
|
15
|
-
path { |id:, **| "/users/#{id}" }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
subject { operations.finalize(settings) }
|
20
|
-
|
21
|
-
it "builds a proper schema" do
|
22
|
-
find_user = subject[:find_user]
|
23
|
-
|
24
|
-
expect(find_user[:method].call).to eq "get"
|
25
|
-
expect(find_user[:path].call(id: 7)).to eq "users/7"
|
26
|
-
expect(find_user[:security].call)
|
27
|
-
.to eq headers: { "authorization" => "Basic Zm9vOmJhcg==" }
|
28
|
-
end
|
29
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::DSL, ".scope" do
|
2
|
-
before do
|
3
|
-
class Test::Foo
|
4
|
-
extend Evil::Client::DSL
|
5
|
-
|
6
|
-
base_url { "https://example.com" }
|
7
|
-
|
8
|
-
scope :foo do
|
9
|
-
param :bar
|
10
|
-
|
11
|
-
scope do
|
12
|
-
param :baz
|
13
|
-
|
14
|
-
def find
|
15
|
-
qux(bar: bar, baz: baz)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def qux(bar:, baz:)
|
21
|
-
"#{bar}/#{baz}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:client) { Test::Foo.new }
|
27
|
-
subject { client.foo("users")[54].find }
|
28
|
-
|
29
|
-
it "provides access to params and methods via nested scopes" do
|
30
|
-
expect(subject).to eq "users/54"
|
31
|
-
end
|
32
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::DSL::Security do
|
2
|
-
subject { described_class.new(&block).call }
|
3
|
-
|
4
|
-
context "from block without definitions:" do
|
5
|
-
let(:block) { proc {} }
|
6
|
-
|
7
|
-
it "provides an empty schema" do
|
8
|
-
expect(subject).to eq({})
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "from block with #key_auth using headers:" do
|
13
|
-
let(:block) do
|
14
|
-
proc do
|
15
|
-
key_auth "foo", "bar"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "provides a schema" do
|
20
|
-
expect(subject).to eq headers: { "foo" => "bar" }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "from block with #key_auth using body:" do
|
25
|
-
let(:block) do
|
26
|
-
proc do
|
27
|
-
key_auth "foo", "bar", using: :body
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "provides a schema" do
|
32
|
-
expect(subject).to eq body: { "foo" => "bar" }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "from block with #key_auth using query:" do
|
37
|
-
let(:block) do
|
38
|
-
proc do
|
39
|
-
key_auth "foo", "bar", using: :query
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "provides a schema" do
|
44
|
-
expect(subject).to eq query: { "foo" => "bar" }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "from block with #key_auth using unknown part:" do
|
49
|
-
let(:block) do
|
50
|
-
proc do
|
51
|
-
key_auth "foo", "bar", using: :unknown
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it "raises" do
|
56
|
-
expect { subject }.to raise_error ArgumentError
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "from block with #token_auth using headers:" do
|
61
|
-
let(:block) do
|
62
|
-
proc do
|
63
|
-
token_auth "foo"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it "provides a schema" do
|
68
|
-
expect(subject).to eq headers: { "authorization" => "foo" }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "from block with #token_auth with a prefix:" do
|
73
|
-
let(:block) do
|
74
|
-
proc do
|
75
|
-
token_auth "foo", prefix: "Digest"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it "provides a schema" do
|
80
|
-
expect(subject).to eq headers: { "authorization" => "Digest foo" }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "from block with #token_auth using body:" do
|
85
|
-
let(:block) do
|
86
|
-
proc do
|
87
|
-
token_auth "foo", using: :body
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it "provides a schema" do
|
92
|
-
expect(subject).to eq body: { "access_token" => "foo" }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "from block with #token_auth using query:" do
|
97
|
-
let(:block) do
|
98
|
-
proc do
|
99
|
-
token_auth "foo", using: :query
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it "provides a schema" do
|
104
|
-
expect(subject).to eq query: { "access_token" => "foo" }
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "from block with #basic_auth:" do
|
109
|
-
let(:block) do
|
110
|
-
proc do
|
111
|
-
basic_auth "foo", "bar"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "provides a schema" do
|
116
|
-
expect(subject)
|
117
|
-
.to eq headers: { "authorization" => "Basic Zm9vOmJhcg==" }
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "from block with several definitions:" do
|
122
|
-
let(:block) do
|
123
|
-
proc do
|
124
|
-
basic_auth "foo", "bar"
|
125
|
-
token_auth "baz", using: :query
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
it "provides a full schema" do
|
130
|
-
expect(subject).to eq \
|
131
|
-
headers: { "authorization" => "Basic Zm9vOmJhcg==" },
|
132
|
-
query: { "access_token" => "baz" }
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::Middleware::MergeSecurity do
|
2
|
-
let(:stack) { described_class.new(app) }
|
3
|
-
let(:app) { double :app }
|
4
|
-
|
5
|
-
def update!(env)
|
6
|
-
@result = env
|
7
|
-
end
|
8
|
-
|
9
|
-
before { allow(app).to receive(:call) { |env, *| update! env } }
|
10
|
-
subject { stack.call env, {}, {} }
|
11
|
-
|
12
|
-
let(:env) do
|
13
|
-
{
|
14
|
-
body: { "foo" => :FOO, "access_key" => :FOO },
|
15
|
-
query: { "bar" => :BAR, "access_key" => :FOO },
|
16
|
-
headers: { "baz" => :BAZ, "authorization" => :FOO },
|
17
|
-
security: {
|
18
|
-
body: { "access_key" => :QUX },
|
19
|
-
query: { "access_key" => :ZYX },
|
20
|
-
headers: { "authorization" => "Basic 3ou08314tq==" }
|
21
|
-
}
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
it "merges security schema to env" do
|
26
|
-
subject
|
27
|
-
expect(@result).to eq \
|
28
|
-
body: { "foo" => :FOO, "access_key" => :QUX },
|
29
|
-
query: { "bar" => :BAR, "access_key" => :ZYX },
|
30
|
-
headers: { "baz" => :BAZ, "authorization" => "Basic 3ou08314tq==" }
|
31
|
-
end
|
32
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::Middleware::NormalizeHeaders do
|
2
|
-
let(:stack) { described_class.new(app) }
|
3
|
-
let(:app) { double :app }
|
4
|
-
let(:env) { { headers: { Foo: :BAR } } }
|
5
|
-
|
6
|
-
def update!(env)
|
7
|
-
@result = env
|
8
|
-
end
|
9
|
-
|
10
|
-
before { allow(app).to receive(:call) { |env, *| update! env } }
|
11
|
-
subject { stack.call env, {}, {} }
|
12
|
-
|
13
|
-
it "normalizes headers" do
|
14
|
-
subject
|
15
|
-
expect(@result[:headers]).to eq "foo" => "BAR"
|
16
|
-
end
|
17
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::Middleware::StringifyForm do
|
2
|
-
let(:stack) { described_class.new(app) }
|
3
|
-
let(:app) { double :app }
|
4
|
-
|
5
|
-
def update!(env)
|
6
|
-
@result = env
|
7
|
-
end
|
8
|
-
|
9
|
-
before { allow(app).to receive(:call) { |env, *| update! env } }
|
10
|
-
subject { stack.call env, {}, {} }
|
11
|
-
|
12
|
-
context "with a non-empty body:" do
|
13
|
-
let(:env) do
|
14
|
-
{
|
15
|
-
body: { foo: :FOO, bar: [:BAR], baz: { qux: :QUX }, qux: nil },
|
16
|
-
format: "form"
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
it "stringifies the body" do
|
21
|
-
subject
|
22
|
-
expect(@result[:body_string]).to eq "foo=FOO&bar[]=BAR&baz[qux]=QUX&qux="
|
23
|
-
end
|
24
|
-
|
25
|
-
it "adds content-type header" do
|
26
|
-
subject
|
27
|
-
expect(@result[:headers])
|
28
|
-
.to eq "content-type" => "application/x-www-form-urlencoded"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when format is not a form:" do
|
33
|
-
let(:env) do
|
34
|
-
{
|
35
|
-
body: { foo: :FOO, bar: [:BAR], baz: { qux: :QUX }, qux: nil },
|
36
|
-
format: "json"
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
it "does nothing" do
|
41
|
-
subject
|
42
|
-
expect(@result).to eq env
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with empty body:" do
|
47
|
-
let(:env) { { body: {}, format: "form" } }
|
48
|
-
|
49
|
-
it "does nothing" do
|
50
|
-
subject
|
51
|
-
expect(@result).to eq env
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "without a body:" do
|
56
|
-
let(:env) { { format: "form" } }
|
57
|
-
|
58
|
-
it "does nothing" do
|
59
|
-
subject
|
60
|
-
expect(@result).to eq env
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::Middleware::StringifyJson do
|
2
|
-
def update!(result)
|
3
|
-
@result = result
|
4
|
-
end
|
5
|
-
|
6
|
-
let(:app) { double :app }
|
7
|
-
|
8
|
-
before { allow(app).to receive(:call) { |env, *| update!(env) } }
|
9
|
-
subject { described_class.new(app).call(env, {}, {}) }
|
10
|
-
|
11
|
-
context "with a body:" do
|
12
|
-
let(:env) { { format: "json", body: { foo: :bar } } }
|
13
|
-
|
14
|
-
it "stringifies a body" do
|
15
|
-
subject
|
16
|
-
expect(@result[:body_string]).to eq '{"foo":"bar"}'
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets content-type" do
|
20
|
-
subject
|
21
|
-
expect(@result[:headers]).to eq "content-type" => "application/json"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when format is not json:" do
|
26
|
-
let(:env) { { format: "form", body: { foo: :bar } } }
|
27
|
-
|
28
|
-
it "does nothing" do
|
29
|
-
subject
|
30
|
-
expect(@result).to eq env
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with empty body:" do
|
35
|
-
let(:env) { { format: "json", body: {} } }
|
36
|
-
|
37
|
-
it "stringifies an empty body" do
|
38
|
-
subject
|
39
|
-
expect(@result[:body_string]).to eq "{}"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "sets content-type" do
|
43
|
-
subject
|
44
|
-
expect(@result[:headers]).to eq "content-type" => "application/json"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "without a body:" do
|
49
|
-
let(:env) { { format: "json" } }
|
50
|
-
|
51
|
-
it "stringifies an empty body" do
|
52
|
-
subject
|
53
|
-
expect(@result[:body_string]).to eq "{}"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "sets content-type" do
|
57
|
-
subject
|
58
|
-
expect(@result[:headers]).to eq "content-type" => "application/json"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::Middleware::StringifyMultipart::Part do
|
2
|
-
let(:file) { StringIO.new "Hello!" }
|
3
|
-
let(:type) { MIME::Types["text/html"].first }
|
4
|
-
let(:charset) { "utf-8" }
|
5
|
-
let(:part) do
|
6
|
-
described_class.new(file: file, type: type, charset: charset)
|
7
|
-
end
|
8
|
-
|
9
|
-
subject { part.to_s }
|
10
|
-
|
11
|
-
shared_examples :building_part do
|
12
|
-
it "includes content disposition" do
|
13
|
-
expect(subject).to include \
|
14
|
-
'Content-Disposition: form-data; name="AttachedFile"; filename='
|
15
|
-
end
|
16
|
-
|
17
|
-
it "includes content type" do
|
18
|
-
expect(subject).to include "Content-Type: text/html; charset=utf-8"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "includes content" do
|
22
|
-
expect(subject).to include "Hello!"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with a name" do
|
27
|
-
let(:part) { described_class.new(file: file, name: "UploadedFile") }
|
28
|
-
|
29
|
-
it "includes part name" do
|
30
|
-
expect(subject).to include 'name="UploadedFile"'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with a filename" do
|
35
|
-
let(:part) { described_class.new(file: file, filename: "weird_thing.json") }
|
36
|
-
|
37
|
-
it "includes part name" do
|
38
|
-
expect(subject).to include 'filename="weird_thing.json"'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "from file" do
|
43
|
-
let(:file) { instance_double ::File, path: "foo/bar.html", read: "Hello!" }
|
44
|
-
it_behaves_like :building_part
|
45
|
-
|
46
|
-
it "includes filename" do
|
47
|
-
expect(subject).to include 'filename="bar.html"'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "from io" do
|
52
|
-
it_behaves_like :building_part
|
53
|
-
end
|
54
|
-
|
55
|
-
context "from text" do
|
56
|
-
let(:file) { "Hello!" }
|
57
|
-
it_behaves_like :building_part
|
58
|
-
end
|
59
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
RSpec.describe Evil::Client::Middleware::StringifyMultipart do
|
2
|
-
let(:app) { double :app }
|
3
|
-
let(:type) { "file" }
|
4
|
-
let(:env) do
|
5
|
-
{
|
6
|
-
format: "multipart",
|
7
|
-
headers: {},
|
8
|
-
files: [
|
9
|
-
{
|
10
|
-
file: StringIO.new('{"text":"Hello!"}'),
|
11
|
-
type: MIME::Types["application/json"].first,
|
12
|
-
charset: "utf-16",
|
13
|
-
filename: "greetings.json"
|
14
|
-
}
|
15
|
-
]
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def update!(result)
|
20
|
-
@result = result
|
21
|
-
end
|
22
|
-
|
23
|
-
before { allow(app).to receive(:call) { |env, *| update!(env) } }
|
24
|
-
subject { described_class.new(app).call(env, {}, {}) }
|
25
|
-
|
26
|
-
context "with a multipart format:" do
|
27
|
-
let(:body_string) { @result[:body_string] }
|
28
|
-
|
29
|
-
it "builds multipart body_string" do
|
30
|
-
subject
|
31
|
-
expect(body_string).to include '{"text":"Hello!"}'
|
32
|
-
end
|
33
|
-
|
34
|
-
it "uses name and filename" do
|
35
|
-
subject
|
36
|
-
expect(body_string).to include "Content-Disposition: form-data;" \
|
37
|
-
' name="AttachedFile1";' \
|
38
|
-
' filename="greetings.json"'
|
39
|
-
end
|
40
|
-
|
41
|
-
it "uses content-type and charset" do
|
42
|
-
subject
|
43
|
-
expect(body_string)
|
44
|
-
.to include "Content-Type: application/json; charset=utf-16"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "adds the header" do
|
48
|
-
subject
|
49
|
-
expect(@result[:headers]["content-type"])
|
50
|
-
.to include "multipart/form-data; boundary="
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "with non-multipart format:" do
|
55
|
-
before { env[:format] = "json" }
|
56
|
-
|
57
|
-
it "does nothing" do
|
58
|
-
subject
|
59
|
-
expect(@result).to eq env
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|