Skip to content

Commit

Permalink
Merge a78deaa into b0d1659
Browse files Browse the repository at this point in the history
  • Loading branch information
san983 committed Apr 22, 2021
2 parents b0d1659 + a78deaa commit 4496970
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 69 deletions.
15 changes: 2 additions & 13 deletions .rubocop.yml
Expand Up @@ -12,17 +12,6 @@ AllCops:
- '*.gemspec'
- 'Rakefile'

# [codesmell]
# It's irrelevant here, but it could be a code smell.
# Hence keep it disabled, but don't include it in the DNSimple suite.
Lint/Loop:
Enabled: false

# It doesn't seem to work as expected.
Style/IfUnlessModifier:
Enabled: false

# This rule suggest to use safe navigation (&.) operator which was introduced
# with Ruby 2.3. Because we are supporting Ruby 2.0+ we can't use this operator.
Style/SafeNavigation:
# This rule conflicts with our specs codebase using Ruby 2.x and 3.x
Lint/NonDeterministicRequireOrder:
Enabled: false
33 changes: 7 additions & 26 deletions .rubocop_todo.yml
@@ -1,20 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-04-05 15:23:33 UTC using RuboCop version 1.12.1.
# on 2021-04-21 14:55:39 UTC using RuboCop version 1.13.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/dnsimple/client/domains_collaborators_spec.rb'
- 'spec/dnsimple/options/list_options_spec.rb'

# Offense count: 70
# Offense count: 71
# Configuration parameters: Max.
RSpec/ExampleLength:
Enabled: false
Expand All @@ -24,26 +16,21 @@ RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/dnsimple/client/client_service_spec.rb'

# Offense count: 21
# Offense count: 11
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 117
# Offense count: 112
RSpec/MultipleExpectations:
Max: 16
Max: 15

# Offense count: 374
# Offense count: 375
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Enabled: false

# Offense count: 10
RSpec/StubbedMock:
Exclude:
- 'spec/dnsimple/client_spec.rb'

# Offense count: 16
RSpec/SubjectStub:
Exclude:
Expand All @@ -60,13 +47,7 @@ RSpec/SubjectStub:
- 'spec/dnsimple/client/zones_spec.rb'
- 'spec/dnsimple/client_spec.rb'

# Offense count: 5
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/dnsimple/client_spec.rb'

# Offense count: 39
# Offense count: 37
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,8 +1,8 @@
dist: bionic

language: ruby

rvm:
- 2.4
- 2.5
- 2.6
- 2.7
- 3.0
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).

## main

- CHANGED: Minimum Ruby version is now 2.6

## 6.0.0

- NEW: Added `registrar.get_domain_prices` to retrieve whether a domain is premium and the prices to register, transfer, and renew. (dnsimple/dnsimple-ruby#230)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -5,7 +5,7 @@ source 'https://rubygems.org'
gemspec

gem 'coveralls', require: false
gem 'rubocop', '1.12.1', require: false
gem 'rubocop', '1.13.0', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'rubocop-rspec', require: false
2 changes: 1 addition & 1 deletion dnsimple.gemspec
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.summary = 'The DNSimple API client for Ruby'
s.description = 'The DNSimple API client for Ruby.'

s.required_ruby_version = ">= 2.4"
s.required_ruby_version = ">= 2.6"

s.require_paths = ['lib']
s.files = `git ls-files`.split("\n")
Expand Down
5 changes: 3 additions & 2 deletions lib/dnsimple/client/clients.rb
Expand Up @@ -98,14 +98,15 @@ def paginate(method, *args)
options = args.pop
response = nil

begin
loop do
current_page += 1
query = Extra.deep_merge(options, query: { page: current_page, per_page: 100 })

response = send(method, *(args + [query]))
total_pages ||= response.total_pages
collection.concat(response.data)
end while current_page < total_pages
break unless current_page < total_pages
end

CollectionResponse.new(response.http_response, collection)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dnsimple/error.rb
Expand Up @@ -18,7 +18,7 @@ def initialize(http_response)

def message_from(http_response)
content_type = http_response.headers["Content-Type"]
if content_type && content_type.start_with?("application/json")
if content_type&.start_with?("application/json")
http_response.parsed_response["message"]
else
net_http_response = http_response.response
Expand Down
2 changes: 1 addition & 1 deletion lib/dnsimple/extra.rb
Expand Up @@ -55,7 +55,7 @@ def self.deep_merge!(this, other, &block)
# @raise [ArgumentError]
def self.validate_mandatory_attributes(attributes, required)
required.each do |name|
attributes && attributes.key?(name) or raise(ArgumentError, ":#{name} is required")
attributes&.key?(name) or raise(ArgumentError, ":#{name} is required")
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/dnsimple/client/domains_collaborators_spec.rb
Expand Up @@ -63,7 +63,7 @@
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }

context "invite user already registered on DNSimple" do
context "when inviting a user already registered on DNSimple" do
before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/collaborators$})
.to_return(read_http_fixture("addCollaborator/success.http"))
Expand Down Expand Up @@ -93,7 +93,7 @@
end
end

context "invite not registered on DNSimple" do
context "when inviting a user not registered on DNSimple" do
before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/collaborators$})
.to_return(read_http_fixture("addCollaborator/invite-success.http"))
Expand Down
30 changes: 15 additions & 15 deletions spec/dnsimple/client_spec.rb
Expand Up @@ -49,35 +49,35 @@

describe "#get" do
it "delegates to #request" do
expect(subject).to receive(:execute).with(:get, "path", nil, foo: "bar").and_return(:returned)
allow(subject).to receive(:execute).with(:get, "path", nil, foo: "bar").and_return(:returned)
expect(subject.get("path", foo: "bar")).to eq(:returned)
end
end

describe "#post" do
it "delegates to #request" do
expect(subject).to receive(:execute).with(:post, "path", { foo: "bar" }, {}).and_return(:returned)
allow(subject).to receive(:execute).with(:post, "path", { foo: "bar" }, {}).and_return(:returned)
expect(subject.post("path", foo: "bar")).to eq(:returned)
end
end

describe "#put" do
it "delegates to #request" do
expect(subject).to receive(:execute).with(:put, "path", { foo: "bar" }, {}).and_return(:returned)
allow(subject).to receive(:execute).with(:put, "path", { foo: "bar" }, {}).and_return(:returned)
expect(subject.put("path", foo: "bar")).to eq(:returned)
end
end

describe "#patch" do
it "delegates to #request" do
expect(subject).to receive(:execute).with(:patch, "path", { foo: "bar" }, {}).and_return(:returned)
allow(subject).to receive(:execute).with(:patch, "path", { foo: "bar" }, {}).and_return(:returned)
expect(subject.patch("path", foo: "bar")).to eq(:returned)
end
end

describe "#delete" do
it "delegates to #request" do
expect(subject).to receive(:execute).with(:delete, "path", { foo: "bar" }, {}).and_return(:returned)
allow(subject).to receive(:execute).with(:delete, "path", { foo: "bar" }, {}).and_return(:returned)
expect(subject.delete("path", foo: "bar")).to eq(:returned)
end
end
Expand Down Expand Up @@ -126,20 +126,20 @@
it "delegates to HTTParty" do
stub_request(:get, %r{/foo})

expect(HTTParty).to receive(:get)
allow(HTTParty).to receive(:get)
.with(
"#{subject.base_url}foo",
format: :json,
basic_auth: { username: "user", password: "pass" },
headers: { 'Accept' => 'application/json', 'User-Agent' => Dnsimple::Default::USER_AGENT }
)
.and_return(double('response', code: 200))
.and_return(instance_double('response', code: 200))

subject.request(:get, 'foo')
end

it "properly extracts processes options and encodes data" do
expect(HTTParty).to receive(:put)
allow(HTTParty).to receive(:put)
.with(
"#{subject.base_url}foo",
format: :json,
Expand All @@ -148,48 +148,48 @@
basic_auth: { username: "user", password: "pass" },
headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => Dnsimple::Default::USER_AGENT, "Custom" => "Header" }
)
.and_return(double('response', code: 200))
.and_return(instance_double('response', code: 200))

subject.request(:put, 'foo', { something: "else" }, { query: { foo: "bar" }, headers: { "Custom" => "Header" } })
end

it "handles non application/json content types" do
expect(HTTParty).to receive(:post)
allow(HTTParty).to receive(:post)
.with(
"#{subject.base_url}foo",
format: :json,
body: { something: "else" },
basic_auth: { username: "user", password: "pass" },
headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => Dnsimple::Default::USER_AGENT }
)
.and_return(double('response', code: 200))
.and_return(instance_double('response', code: 200))

subject.request(:post, 'foo', { something: "else" }, { headers: { "Content-Type" => "application/x-www-form-urlencoded" } })
end

it "includes options for proxy support" do
expect(HTTParty).to receive(:get)
allow(HTTParty).to receive(:get)
.with(
"#{subject.base_url}test",
format: :json,
http_proxyaddr: "example-proxy.com",
http_proxyport: "4321",
headers: { 'Accept' => 'application/json', 'User-Agent' => Dnsimple::Default::USER_AGENT }
)
.and_return(double('response', code: 200))
.and_return(instance_double('response', code: 200))

subject = described_class.new(proxy: "example-proxy.com:4321")
subject.request(:get, "test", nil, {})
end

it "supports custom user agent" do
expect(HTTParty).to receive(:get)
allow(HTTParty).to receive(:get)
.with(
"#{subject.base_url}test",
format: :json,
headers: hash_including("User-Agent" => "customAgent #{Dnsimple::Default::USER_AGENT}")
)
.and_return(double("response", code: 200))
.and_return(instance_double("response", code: 200))

subject = described_class.new(user_agent: "customAgent")
subject.request(:get, "test", nil)
Expand Down
8 changes: 4 additions & 4 deletions spec/dnsimple/options/list_options_spec.rb
Expand Up @@ -14,14 +14,14 @@
expect(options.to_h).to eq({})
end

context 'query' do
describe 'query' do
it 'adds "query" key if given options are filled' do
options = described_class.new(a: 1)
expect(options.to_h).to have_key(:query)
end
end

context 'pagination' do
describe 'pagination' do
it 'adds "page" to "query"' do
raw = { page: '23' }
expected = { query: raw }
Expand All @@ -47,7 +47,7 @@
end
end

context 'sorting' do
describe 'sorting' do
it 'adds sorting policy to "query"' do
raw = { sort: 'name:desc' }
expected = { query: raw }
Expand All @@ -73,7 +73,7 @@
end
end

context 'filtering' do
describe 'filtering' do
it 'adds filtering policy to "query"' do
raw = { filter: { name_like: 'example' } }
expected = { query: raw.fetch(:filter) }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -14,4 +14,4 @@
SPEC_ROOT = File.expand_path(__dir__)
end

Dir[File.join(SPEC_ROOT, "support/**/*.rb")].sort.each { |f| require f }
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].each { |f| require f }

0 comments on commit 4496970

Please sign in to comment.