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
2 changes: 2 additions & 0 deletions lib/ebay_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/ebay_api/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to support two ways of initialization? Wdyt about keeping only one, which would be easier to maintain?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid affecting other parts. As you mentioned, the fork is far behind the upstream version, and I prefer not to investigate or apply fixes if we plan to rebase onto the original gem.


sites_file = File.join(GEM_ROOT, %w[config sites.yml])
include Evil::Client::Dictionary[sites_file]

Expand Down
43 changes: 43 additions & 0 deletions spec/models/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,47 @@
expect(subject).to eq "Canadian"
end
end

describe ".new" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the test actually checking whether everything is loaded correctly it's needed to remove I8n.load_path from the spec helper. Otherwise the test will be always green regardless of the fix.

I18n.load_path += ["config/locales/en.yml"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot! thanks

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
4 changes: 0 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]