Oops, fix bug when loading species with no alt styles in the Studio
This commit is contained in:
parent
3ed1c46b64
commit
b245690a60
2 changed files with 13 additions and 1 deletions
|
@ -65,7 +65,10 @@ module Neopets::NCMall
|
||||||
|
|
||||||
begin
|
begin
|
||||||
data = JSON.parse(response.read).deep_symbolize_keys
|
data = JSON.parse(response.read).deep_symbolize_keys
|
||||||
data.fetch(:styles).values
|
|
||||||
|
# HACK: styles is a hash, unless it's empty, in which case it's an
|
||||||
|
# array? Weird. Normalize this by converting to hash.
|
||||||
|
data.fetch(:styles).to_h.values
|
||||||
rescue JSON::ParserError, KeyError
|
rescue JSON::ParserError, KeyError
|
||||||
raise UnexpectedResponseFormat
|
raise UnexpectedResponseFormat
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,6 +55,15 @@ RSpec.describe Neopets::NCMall, type: :model do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles the NC Mall's odd API behavior for zero styles" do
|
||||||
|
stub_styles_request.to_return(
|
||||||
|
# You'd think styles would be `{}` in this case, but it's `[]`. Huh!
|
||||||
|
body: '{"success":true,"styles":[]}',
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(styles).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
it "raises an error if the request returns a non-200 status" do
|
it "raises an error if the request returns a non-200 status" do
|
||||||
stub_styles_request.to_return(status: 400)
|
stub_styles_request.to_return(status: 400)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue