Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ GEM
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.18.1)
json-schema (5.2.2)
addressable (~> 2.8)
bigdecimal (~> 3.1)
jwt (3.1.2)
base64
language_server-protocol (3.17.0.5)
Expand All @@ -100,6 +103,8 @@ GEM
net-imap
net-pop
net-smtp
mcp (0.7.1)
json-schema (>= 4.1)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.26.0)
Expand Down Expand Up @@ -130,7 +135,7 @@ GEM
version_gem (~> 1.1, >= 1.1.9)
openssl (3.3.2)
parallel (1.27.0)
parser (3.3.10.1)
parser (3.3.10.2)
ast (~> 2.4.1)
racc
pp (0.6.3)
Expand Down Expand Up @@ -172,10 +177,11 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.6)
rubocop (1.84.2)
rubocop (1.85.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
mcp (~> 0.6)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
Expand Down
4 changes: 2 additions & 2 deletions lib/ioki/apis/endpoints/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def self.url_elements(path, *args)
raise ArgumentError, 'path: must consist of Strings and Symbols only'
end

unless path.select { |element| element.is_a?(Symbol) }.size <= args.size
unless path.grep(Symbol).size <= args.size
raise ArgumentError, "args: must have an argument for every symbol in :path. path: #{path}, args: #{args}"
end

interpolation_args = path.select { |inner_element| inner_element.is_a?(Symbol) }.zip(args).reverse
interpolation_args = path.grep(Symbol).zip(args).reverse
interpolation_path = path.map { |element| element.is_a?(String) ? element : interpolation_args.pop }
interpolation_path.map do |path_element, arg|
next path_element if path_element.is_a?(String)
Expand Down
6 changes: 1 addition & 5 deletions lib/open_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ def schema_path
end

def file_lines
@file_lines ||= model_file.readlines.to_a
end

def model_file
File.open file_path
@file_lines ||= File.read(file_path).lines
end

def file_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ def setup_driver_client(client_name)
end
end

module IncludedClientHelpers
def with_platform_client(&block)
platform_client = Ioki::PlatformClient.new
block.call(platform_client)
end

def with_passenger_client(&block)
passenger_client = Ioki::PassengerClient.new
block.call(passenger_client)
end

def with_driver_client(&block)
driver_client = Ioki::DriverClient.new
block.call(driver_client)
end
end

RSpec.configure do |c|
c.extend ExtendedClientHelpers
c.include IncludedClientHelpers
end
22 changes: 22 additions & 0 deletions spec/helper/included_client_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module IncludedClientHelpers
def with_platform_client(&block)
platform_client = Ioki::PlatformClient.new
block.call(platform_client)
end

def with_passenger_client(&block)
passenger_client = Ioki::PassengerClient.new
block.call(passenger_client)
end

def with_driver_client(&block)
driver_client = Ioki::DriverClient.new
block.call(driver_client)
end
end

RSpec.configure do |c|
c.include IncludedClientHelpers
end
26 changes: 14 additions & 12 deletions spec/ioki/faraday_retry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
require 'spec_helper'
require 'ioki/apis/endpoints/endpoints'

class DummyModel < Ioki::Model::Base
attribute :value, on: :read, type: :integer
end
RSpec.describe Faraday do
let(:dummy_model) do
Class.new(Ioki::Model::Base) do
attribute :value, on: :read, type: :integer
end
end

let(:client) { Ioki::Client.new(Ioki::Configuration.new, DummyApi) }

class DummyApi
ENDPOINTS =
[
before do
stub_const('DummyApi', Class.new)
stub_const('DummyApi::ENDPOINTS', [
Ioki::Endpoints::Index.new(
:ping,
base_path: ['driver'],
model_class: DummyModel
model_class: dummy_model
)
].freeze
end

RSpec.describe Faraday do
let(:client) { Ioki::Client.new(Ioki::Configuration.new, DummyApi) }
].freeze)
end

it 'does not retry on 404 errors' do
ping_request = stub_request(:get, 'https://app.io.ki/api/driver/ping')
Expand Down
2 changes: 1 addition & 1 deletion spec/ioki/open_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Example < Base
let(:model_file_path) { 'lib/ioki/model/platform/example.rb' }

before do
allow(File).to receive(:open).with(model_file_path).and_return(StringIO.new(model_definition))
allow(File).to receive(:read).with(model_file_path).and_return(StringIO.new(model_definition).string)
allow(File).to receive(:write)
allow(specification).to receive(:definition_json).and_return(specification_json)
# unset Ioki::Model::Platform::Example constant:
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
require 'vcr'
require 'webmock/rspec'
require 'helper/string_helper'
require 'helper/client_helpers'
require 'helper/included_client_helpers'
require 'helper/extended_client_helpers'
require 'helper/define_attribute_matcher'

RSpec.configure do |config|
Expand Down