From 50747d14aabffa674396923f8c54d5dbef9bc588 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 20 Nov 2025 05:28:52 +0000 Subject: [PATCH 1/2] Fix Site initialization to handle hash arguments from Evil::Client::Dictionary --- lib/ebay_api/models/site.rb | 9 ++++++++ spec/models/site_spec.rb | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/ebay_api/models/site.rb b/lib/ebay_api/models/site.rb index 5f95ee8..a251b72 100644 --- a/lib/ebay_api/models/site.rb +++ b/lib/ebay_api/models/site.rb @@ -44,6 +44,15 @@ def merge(other) # Enumberable collection of the eBay marketplaces class << self + # Override new to handle hash argument from Evil::Client::Dictionary + def new(attributes = {}) + if attributes.is_a?(Hash) && !attributes.empty? + super(**attributes) + else + super + end + end + sites_file = File.join(GEM_ROOT, %w[config sites.yml]) include Evil::Client::Dictionary[sites_file] diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index d58c174..f9dcbfb 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -73,4 +73,47 @@ expect(subject).to eq "Canadian" end end + + describe ".new" do + context "when initialized with a hash argument" do + let(:hash_attrs) do + { + id: 0, + code: "EBAY-US", + country: "US", + host: "www.ebay.com", + key: "EBAY_US", + currencies: ["USD"], + languages: ["en-US"] + } + end + + it "properly initializes attributes from hash" do + site = described_class.new(hash_attrs) + expect(site.id).to eq(0) + expect(site.code).to eq("EBAY-US") + expect(site.country).to eq("US") + expect(site.host).to eq("www.ebay.com") + expect(site.key).to eq("EBAY_US") + expect(site.currencies.first.code).to eq("USD") + expect(site.languages.first).to eq("en-US") + end + end + + context "when initialized with keyword arguments" do + it "properly initializes attributes from keywords" do + site = described_class.new( + id: 0, + code: "EBAY-US", + country: "US", + host: "www.ebay.com", + key: "EBAY_US" + ) + expect(site.id).to eq(0) + expect(site.code).to eq("EBAY-US") + expect(site.country).to eq("US") + expect(site.host).to eq("www.ebay.com") + end + end + end end From 9b724d1037869bfa1502901b7907bd53007d4cef Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 20 Nov 2025 05:31:12 +0000 Subject: [PATCH 2/2] Configure I18n load path for eBay API locale files --- lib/ebay_api.rb | 2 ++ spec/spec_helper.rb | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 26afe31..3628be7 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -27,6 +27,8 @@ class EbayAPI < Evil::Client require_relative "ebay_api/middlewares" require_relative "ebay_api/exceptions" + I18n.load_path += Dir[File.join(GEM_ROOT, *%w[config locales ** *.{yml,yaml}])] + class << self attr_accessor :logger end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 44c0fcb..24d7bd9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,3 @@ config.filter_run focus: true config.run_all_when_everything_filtered = true end - -I18n.available_locales = %i[en] -I18n.locale = :en -I18n.load_path += ["config/locales/en.yml"]