Skip to content

Commit

Permalink
Merge pull request #103 from raszi/chore/rubocop
Browse files Browse the repository at this point in the history
chore: fix RuboCop issues
  • Loading branch information
raszi authored Dec 14, 2021
2 parents a706b89 + f6937f2 commit 62c0919
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 174 deletions.
15 changes: 14 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require: rubocop-rake
require:
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
Expand All @@ -24,6 +26,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Exclude:
- 'spec/**/*'
- '**/*.gemspec'
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Expand All @@ -32,6 +35,16 @@ Metrics/ParameterLists:
Naming/AccessorMethodName:
Enabled: false

RSpec/FilePath:
Enabled: false
RSpec/NestedGroups:
Enabled: false
RSpec/MultipleMemoizedHelpers:
Enabled: false
RSpec/MultipleExpectations:
Exclude:
- 'spec/concerns/authentication_spec.rb'

Style/ClassAndModuleChildren:
Enabled: false
Style/Documentation:
Expand Down
13 changes: 8 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GEM
crack (0.4.5)
rexml
diff-lcs (1.4.4)
docile (1.3.5)
docile (1.4.0)
faraday (1.8.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand All @@ -43,7 +43,7 @@ GEM
method_source (1.0.0)
multipart-post (2.1.1)
parallel (1.21.0)
parser (3.0.2.0)
parser (3.0.3.2)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
Expand All @@ -54,7 +54,7 @@ GEM
public_suffix (4.0.6)
rainbow (3.0.0)
rake (13.0.6)
regexp_parser (2.1.1)
regexp_parser (2.2.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
Expand All @@ -68,7 +68,7 @@ GEM
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rspec-support (3.10.3)
rubocop (1.23.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
Expand All @@ -78,10 +78,12 @@ GEM
rubocop-ast (>= 1.12.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.13.0)
rubocop-ast (1.15.0)
parser (>= 3.0.1.1)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.6.0)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
Expand All @@ -108,6 +110,7 @@ DEPENDENCIES
rspec (~> 3.2)
rubocop (~> 1.23.0)
rubocop-rake (~> 0.6.0)
rubocop-rspec (~> 2.6)
simplecov (~> 0.21.2)
webmock (~> 3.1)

Expand Down
2 changes: 1 addition & 1 deletion lib/mrkt/concerns/crud_program_members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def describe_program_members

def createupdate_program_members(program_id, lead_ids, status)
post_json("/rest/v1/programs/#{program_id}/members/status.json") do
params = {
{
statusName: status,
input: lead_ids.map { |lead_id| { leadId: lead_id } }
}
Expand Down
3 changes: 3 additions & 0 deletions mrkt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = %w[lib]

spec.metadata['rubygems_mfa_required'] = 'true'

spec.required_ruby_version = '>= 2.5'

spec.add_dependency 'faraday', '~> 1.0'
Expand All @@ -29,6 +31,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.2'
spec.add_development_dependency 'rubocop', '~> 1.23.0'
spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
spec.add_development_dependency 'rubocop-rspec', '~> 2.6'
spec.add_development_dependency 'simplecov', '~> 0.21.2'
spec.add_development_dependency 'webmock', '~> 3.1'
end
65 changes: 31 additions & 34 deletions spec/concerns/authentication_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
describe Mrkt::Authentication do
include_context 'initialized client'
include_context 'with an initialized client'

describe '#authenticate' do
subject { client.authenticate }
subject(:action) { client.authenticate }

context 'on a successful response' do
context 'with on a successful response' do
it { is_expected.to be_success }
end

Expand All @@ -16,21 +16,28 @@
}
end

it 'should raise an Error' do
expect { subject }.to raise_error(Mrkt::Errors::Error, 'Bad client credentials')
it 'raises an Error' do
expect { action }.to raise_error(Mrkt::Errors::Error, 'Bad client credentials')
end
end
end

describe '#authenticate!' do
it 'should authenticate and then be authenticated?' do
expect(client.authenticated?).to_not be true
it 'authenticates the client' do
expect(client.authenticated?).not_to be true

client.authenticate!
expect(client.authenticated?).to be true
end

context 'with optional partner_id client option' do
before { remove_request_stub(@authentication_request_stub) }
subject(:client) { Mrkt::Client.new(client_options) }

before do
stub_request(:get, "https://#{host}/identity/oauth/token")
.with(query: query)
.to_return(json_stub(authentication_stub))
end

let(:partner_id) { SecureRandom.uuid }

Expand All @@ -52,23 +59,22 @@
}
end

subject(:client) { Mrkt::Client.new(client_options) }

before do
stub_request(:get, "https://#{host}/identity/oauth/token")
.with(query: query)
.to_return(json_stub(authentication_stub))
end

it 'should authenticate and then be authenticated?' do
expect(client.authenticated?).to_not be true
it 'authenticates the client' do
expect(client.authenticated?).not_to be true
client.authenticate!
expect(client.authenticated?).to be true
end
end

context 'when the token has expired and @retry_authentication = true' do
before { remove_request_stub(@authentication_request_stub) }
subject(:client) { Mrkt::Client.new(client_options) }

before do
stub_request(:get, "https://#{host}/identity/oauth/token")
.with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' })
.to_return(json_stub(expired_authentication_stub)).times(3).then
.to_return(json_stub(valid_authentication_stub))
end

let(:retry_count) { 3 }

Expand All @@ -90,26 +96,17 @@
}
end

subject(:client) { Mrkt::Client.new(client_options) }

before do
stub_request(:get, "https://#{host}/identity/oauth/token")
.with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' })
.to_return(json_stub(expired_authentication_stub)).times(3).then
.to_return(json_stub(valid_authentication_stub))
end

it 'should retry until getting valid token and then be authenticated?' do
expect(client.authenticated?).to_not be true
it 'retries until it gets a valid token' do
expect(client.authenticated?).not_to be true
client.authenticate!
expect(client.authenticated?).to be true
end

context 'when retry_authentication_count is low' do
let(:retry_count) { 2 }

it 'should stop retrying after @retry_authentication_count tries and then raise an error' do
expect(client.authenticated?).to_not be true
it 'stops retrying after a while' do
expect(client.authenticated?).not_to be true

expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated')
end
Expand All @@ -120,11 +117,11 @@
describe '#authenticated?' do
subject { client.authenticated? }

context 'before authentication' do
context 'when authentication has not been done' do
it { is_expected.to be_falsey }
end

context 'after authentication' do
context 'when authentication has been done' do
before { client.authenticate }

it { is_expected.to be_truthy }
Expand Down
33 changes: 20 additions & 13 deletions spec/concerns/crud_activities_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
describe Mrkt::CrudActivities do
include_context 'initialized client'
include_context 'with an initialized client'

describe '#get_activity_types' do
subject { client.get_activity_types }

let(:response_stub) do
{
requestId: 'c245#14cd6830ae2',
Expand Down Expand Up @@ -29,7 +31,6 @@
success: true
}
end
subject { client.get_activity_types }

before do
stub_request(:get, "https://#{host}/rest/v1/activities/types.json")
Expand All @@ -40,6 +41,8 @@
end

describe '#get_paging_token' do
subject { client.get_paging_token(since_datetime) }

let(:since_datetime) { Time.utc(2017, 1, 1, 4, 30) }
let(:response_stub) do
{
Expand All @@ -48,7 +51,6 @@
nextPageToken: '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA===='
}
end
subject { client.get_paging_token(since_datetime) }

before do
stub_request(:get, "https://#{host}/rest/v1/activities/pagingtoken.json")
Expand All @@ -60,6 +62,8 @@
end

describe '#get_activities' do
subject { client.get_activities(token) }

let(:activity_type_ids) { [1, 2] }
let(:lead_ids) { [100, 102] }
let(:token) { '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA====' }
Expand Down Expand Up @@ -106,7 +110,6 @@
moreResult: false
}
end
subject { client.get_activities(token) }

before do
stub_request(:get, "https://#{host}/rest/v1/activities.json")
Expand All @@ -116,7 +119,9 @@

it { is_expected.to eq(response_stub) }

context 'specifying activity type ids' do
context 'when specifying activity type ids' do
subject { client.get_activities(token, activity_type_ids: activity_type_ids) }

let(:response_stub) do
{
data: {
Expand Down Expand Up @@ -147,7 +152,6 @@
moreResult: false
}
end
subject { client.get_activities(token, activity_type_ids: activity_type_ids) }

before do
stub_request(:get, "https://#{host}/rest/v1/activities.json")
Expand All @@ -161,7 +165,9 @@
it { is_expected.to eq(response_stub) }
end

context 'specifying lead ids' do
context 'when specifying lead ids' do
subject { client.get_activities(token, lead_ids: lead_ids) }

let(:response_stub) do
{
data: {
Expand Down Expand Up @@ -192,7 +198,6 @@
moreResult: false
}
end
subject { client.get_activities(token, lead_ids: lead_ids) }

before do
stub_request(:get, "https://#{host}/rest/v1/activities.json")
Expand All @@ -203,13 +208,14 @@
it { is_expected.to eq(response_stub) }
end

context 'specifying arrays values as empty strings' do
let(:activity_type_ids) { '' }
let(:lead_ids) { '' }
context 'when specifying arrays values as empty strings' do
subject do
client.get_activities(token, activity_type_ids: activity_type_ids, lead_ids: lead_ids)
end

let(:activity_type_ids) { '' }
let(:lead_ids) { '' }

before do
stub_request(:get, "https://#{host}/rest/v1/activities.json")
.with(query: { nextPageToken: token })
Expand All @@ -219,7 +225,7 @@
it { is_expected.to eq(response_stub) }
end

context 'specifying all options' do
context 'when specifying all options' do
subject do
client.get_activities(token, activity_type_ids: activity_type_ids, lead_ids: lead_ids)
end
Expand All @@ -239,6 +245,8 @@
end

describe '#get_deleted_leads' do
subject { client.get_deleted_leads(token) }

let(:token) { '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA====' }
let(:response_stub) do
{
Expand Down Expand Up @@ -266,7 +274,6 @@
moreResult: false
}
end
subject { client.get_deleted_leads(token) }

before do
stub_request(:get, "https://#{host}/rest/v1/activities/deletedleads.json")
Expand Down
Loading

0 comments on commit 62c0919

Please sign in to comment.