Skip to content

Commit

Permalink
fix: change rack.version to rack.release (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Jan 9, 2025
1 parent 4145eb8 commit 8f63aed
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: sudo apt-get install libpq-dev

- name: Install Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1.61.1
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and cache
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ drastically in many important details.

### [BREAKING] Changed

- There is no more differencies between "root" DSL, DSL of scope and
- There is no more differences between "root" DSL, DSL of scope and
operation. All scopes use exactly the same methods. All operations
uses just the same methods except for `#operation` and `#scope` that
provide further nesting.
Expand Down Expand Up @@ -463,7 +463,7 @@ formats will be added.
```

This time response handler will try processing a response using various
definitions (in order of their declaration) until some suits. The hanlder
definitions (in order of their declaration) until some suits. The handler
returns `ResponseError` in case no definition proves suitable.

Names (the first param) are unique. When several definitions use the same name,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CatsClient < Evil::Client
end

# Parses json response, wraps it into model with [#error] and raises
# an exception where [ResponseError#response] contains the model istance
# an exception where [ResponseError#response] contains the model instance
response(400, 422) { |(status, *)| raise "#{status}: Record invalid" }
end
end
Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CatsClient < Evil::Client
end
```

Remember that you can define header values as a flat array instead of the string. Inside an array all the values are counted as srings.
Remember that you can define header values as a flat array instead of the string. Inside an array all the values are counted as strings.

```ruby
headers { "Language" => ["ru_RU", "charset=utf-8"] }
Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The user of custom client sends a request by invoking some operation by name on

```ruby
client = CatsClient.new
cats = client.cats # scope for the `fetch` operaton
cats = client.cats # scope for the `fetch` operation

cats.fetch id: 44 # sends request and returns a processed response
```
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CatsClient < Evil::Client
end

# Parses json response, wraps it into model with [#error] and raises
# an exception where [ResponseError#response] contains the model istance
# an exception where [ResponseError#response] contains the model instance
response(400, 422) { |(status, *)| raise "#{status}: Record invalid" }
end
end
Expand Down
2 changes: 1 addition & 1 deletion docs/rspec.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
When you provide a client to remote API, you would provide some means for its users to test their operations.

Surely, they could use [webmock] to check the ultimate requests that are sent to the server. But doing this, they would inadvertedly specify not their own code, but your client's code too. What do they actually need is a means to stub and check invocations of your client's operations. This way they would back on correctness of your client, and take its interface as an endpoint.
Surely, they could use [webmock] to check the ultimate requests that are sent to the server. But doing this, they would inadvertently specify not their own code, but your client's code too. What do they actually need is a means to stub and check invocations of your client's operations. This way they would back on correctness of your client, and take its interface as an endpoint.

For this reason, we support a special RSpec stubs and expectations. sThey are not loaded by default, so you must require it first, and then include the module:

Expand Down
1 change: 1 addition & 0 deletions evil-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = ">= 2.6"

gem.add_runtime_dependency "base64", ">= 0.2.0", "< 0.3"
gem.add_runtime_dependency "dry-initializer", ">= 2.1"
gem.add_runtime_dependency "mime-types", ">= 3.1"
gem.add_runtime_dependency "rack", ">= 2"
Expand Down
8 changes: 8 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output:
- execution_info

pre-commit:
jobs:
- run: bundle exec rubocop
glob: "*.{rb,gemspec}"
stage_fixed: true
2 changes: 1 addition & 1 deletion lib/evil/client/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Evil::Client
class Builder
Names.clean(self) # Remove unnecessary methods from the instance

# Load concrete implementations for the abstact builder
# Load concrete implementations for the abstract builder
require_relative "builder/scope"
require_relative "builder/operation"

Expand Down
2 changes: 1 addition & 1 deletion lib/evil/client/resolver/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def environment
"SERVER_NAME" => uri.host,
"SERVER_PORT" => uri.port,
"HTTP_Variables" => headers,
"rack.version" => Rack.release,
"rack.release" => Rack.release,
"rack.url_scheme" => uri.scheme,
"rack.input" => Formatter.call(body, format, boundary: boundary),
"rack.multithread" => false,
Expand Down
4 changes: 2 additions & 2 deletions lib/evil/client/schema/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def headers(value = nil, &block)
# Adds query definition to the schema
#
# Query should be a nested hash.
# Wnen subscope or operation reloads previously defined query,
# When subscope or operation reloads previously defined query,
# new definition are merged deeply to older one. You can populate
# a query step-by-step from client root to an operation.
#
Expand All @@ -117,7 +117,7 @@ def query(value = nil, &block)
#
# It is expected the body to correspond to [#format].
#
# When a format is :json, the body should be convertable to json
# When a format is :json, the body should be convertible to json
# When a format is :text, the body should be stringified
# When a format is :form, the body should be a hash
# When a format is :multipart, the body can be object or array of objects
Expand Down
9 changes: 0 additions & 9 deletions spec/features/scope/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@
end
end

context "when required options missed" do
subject { client.crm }

it "raises StandardError" do
expect { subject }
.to raise_error StandardError, /version/
end
end

context "when some validation failed" do
subject { crm.users(token: nil) }

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Client < Evil::Client
response(500) { raise "Server error" }

scope :crm do
option :version, defaul: proc { 1 }
option :version, default: proc { 1 }
format { version.to_i > 2 ? :json : :form }
path { "crm/v#{version}" }

Expand Down
44 changes: 31 additions & 13 deletions spec/unit/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Authorization" => "Bearer eoiqopr==",
"Content-Type" => "application/json"
},
"rack.version" => Rack.release,
"rack.release" => Rack.release,
"rack.input" => "name=Andrew&age=46",
"rack.url_scheme" => "https",
"rack.multithread" => false,
Expand Down Expand Up @@ -57,22 +57,40 @@
it "logs the request" do
subject

<<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
|INFO -- Evil::Client::Connection: sending request:
|INFO -- Evil::Client::Connection: Url | https://foo.com/api/v77/users/43?version=77&verbose=true
|INFO -- Evil::Client::Connection: Headers | {"Foo"=>"BAR", "Baz"=>"QUX", "Authorization"=>"Bearer eoiqopr==", "Content-Type"=>"application/json"}
|INFO -- Evil::Client::Connection: Body | name=Andrew&age=46
LOG
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4.0")
<<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
|INFO -- Evil::Client::Connection: sending request:
|INFO -- Evil::Client::Connection: Url | https://foo.com/api/v77/users/43?version=77&verbose=true
|INFO -- Evil::Client::Connection: Headers | {"Foo"=>"BAR", "Baz"=>"QUX", "Authorization"=>"Bearer eoiqopr==", "Content-Type"=>"application/json"}
|INFO -- Evil::Client::Connection: Body | name=Andrew&age=46
LOG
else
<<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
|INFO -- Evil::Client::Connection: sending request:
|INFO -- Evil::Client::Connection: Url | https://foo.com/api/v77/users/43?version=77&verbose=true
|INFO -- Evil::Client::Connection: Headers | {"Foo" => "BAR", "Baz" => "QUX", "Authorization" => "Bearer eoiqopr==", "Content-Type" => "application/json"}
|INFO -- Evil::Client::Connection: Body | name=Andrew&age=46
LOG
end
end

it "logs the response" do
subject

<<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
|INFO -- Evil::Client::Connection: receiving response:
|INFO -- Evil::Client::Connection: Status | 200
|INFO -- Evil::Client::Connection: Headers | {\"content-language\"=>[\"en_AU\"]}
|INFO -- Evil::Client::Connection: Body | [\"Done!\"]
LOG
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4.0")
<<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
|INFO -- Evil::Client::Connection: receiving response:
|INFO -- Evil::Client::Connection: Status | 200
|INFO -- Evil::Client::Connection: Headers | {"content-language"=>["en_AU"]}
|INFO -- Evil::Client::Connection: Body | ["Done!"]
LOG
else
<<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
|INFO -- Evil::Client::Connection: receiving response:
|INFO -- Evil::Client::Connection: Status | 200
|INFO -- Evil::Client::Connection: Headers | {"content-language" => ["en_AU"]}
|INFO -- Evil::Client::Connection: Body | ["Done!"]
LOG
end
end
end
2 changes: 1 addition & 1 deletion spec/unit/container/operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def call(env)
expect(subject).to eq "result" => "success"
end

context "whe a client has custom connection" do
context "when a client has custom connection" do
let(:connection) { double call: [200, {}, %w[{"result":"wow"}]] }

it "sends request to selected connection" do
Expand Down
6 changes: 5 additions & 1 deletion spec/unit/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
let(:format) { :text }

it "returns formatted body as plain text" do
expect(subject).to eq "{:foo=>:bar}"
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4.0")
expect(subject).to eq "{:foo=>:bar}"
else
expect(subject).to eq "{foo: :bar}"
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/resolver/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Test::Baz; end
end
end

context "when middleware defintion has wrong format" do
context "when middleware definition has wrong format" do
before { schema.definitions[:middleware] = proc { 1323 } }

it "raises Evil::Client::DefinitionError" do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/resolver/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
end
end

context "when query defintion returns neither hash nor nil" do
context "when query definition returns neither hash nor nil" do
before { schema.definitions[:query] = proc { 1323 } }

it "raises Evil::Client::DefinitionError" do
Expand Down
9 changes: 7 additions & 2 deletions spec/unit/resolver/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"Authorization" => "Bearer eoiqopr==",
"Content-Type" => "application/json"
},
"rack.version" => Rack.release,
"rack.release" => Rack.release,
"rack.input" => '{"version":"v77"}',
"rack.url_scheme" => "https",
"rack.multithread" => false,
Expand Down Expand Up @@ -82,7 +82,12 @@
context "with :text format" do
before do
schema.definitions[:format] = -> { :text }
environment["rack.input"] = '{:version=>"v77"}'
environment["rack.input"] =
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4.0")
'{:version=>"v77"}'
else
'{version: "v77"}'
end
environment["HTTP_Variables"]["Content-Type"] = "text/plain"
end

Expand Down
10 changes: 5 additions & 5 deletions spec/unit/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,31 @@
describe ".name" do
subject { klass.name }

it "represents settins class in a human-friendly manner" do
it "represents settings class in a human-friendly manner" do
expect(subject).to eq "Test::Api.users.update"
end
end

describe ".inspect" do
subject { klass.inspect }

it "represents settins class in a human-friendly manner" do
it "represents settings class in a human-friendly manner" do
expect(subject).to eq "Test::Api.users.update"
end
end

describe ".to_s" do
subject { klass.to_s }

it "represents settins class in a human-friendly manner" do
it "represents settings class in a human-friendly manner" do
expect(subject).to eq "Test::Api.users.update"
end
end

describe ".to_str" do
subject { klass.to_str }

it "represents settins class in a human-friendly manner" do
it "represents settings class in a human-friendly manner" do
expect(subject).to eq "Test::Api.users.update"
end
end
Expand Down Expand Up @@ -230,7 +230,7 @@
end
end

context "with unparseable value" do
context "with unparsable value" do
let(:value) { "foo" }

it "raises ArgumentError" do
Expand Down

0 comments on commit 8f63aed

Please sign in to comment.