Skip to content

Commit

Permalink
Issue 278: context should be an array, not a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tworrall committed Nov 7, 2019
1 parent 281799b commit 7e0ff28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
44 changes: 18 additions & 26 deletions lib/qa/authorities/discogs/generic_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,22 @@ def check_for_msg_response(release_resp, master_resp)

# @param [Hash] the http response from discogs
# @example returns parsed discogs data with context
# {
# [{
# "uri": "https://api.discogs.com/releases/4212473",
# "id": "4212473",
# "label": "Frank Sinatra And The Modernaires - Sorry / Why Remind Me",
# }
# "context": {
# "Image URL": [
# "https://img.discogs.com/2e-YoNr0dvmMgbzEN0hjHD6X0sU=/fit-in/600x580/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-4212473-1358693671-5430.jpeg.jpg"
# ],
# "Year": [
# "1950"
# ],
# "Record Labels": [
# "Columbia"
# ],
# "Formats": [
# "Shellac",
# "10\"",
# "78 RPM"
# ],
# "Type": [
# "release"
# ]
# }
# "context": [{
# "Image URL": ["https://img.discogs.com/2e-YoNr0d=/fit-in/600x580/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-4212473.jpg"]
# }, {
# "Year": ["1950"]
# }, {
# "Record Labels": ["Columbia"]
# }, {
# "Formats": ["Shellac", "10\"", "78 RPM"]
# }, {
# "Type": ["release"]
# }]
# }]
def parse_authority_response(response)
response['results'].map do |result|
{ 'uri' => build_uri(result),
Expand All @@ -141,11 +133,11 @@ def build_uri(result)

# @param [Hash] the results hash from the JSON returned by Discogs
def assemble_search_context(result)
{ "Image URL" => get_context_for_string(result['cover_image']),
"Year" => get_context_for_string(result['year']),
"Record Labels" => get_context_for_array(result['label']),
"Formats" => get_context_for_array(result['format']),
"Type" => get_context_for_string(result['type']) }
[{ "Image URL" => get_context_for_string(result['cover_image']) },
{ "Year" => get_context_for_string(result['year']) },
{ "Record Labels" => get_context_for_array(result['label']) },
{ "Formats" => get_context_for_array(result['format']) },
{ "Type" => get_context_for_string(result['type']) }]
end

# checks if the param is null, returns appropriate value
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/authorities/discogs/generic_authority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@
expect(results.first["uri"]).to eq("https://www.discogs.com/Melody-Gardot-Who-Will-Comfort-Me-Over-The-Rainbow/release/1750352")
expect(results.first["id"]).to eq "1750352"
expect(results.first["label"]).to eq "Melody Gardot - Who Will Comfort Me / Over The Rainbow"
expect(results.first["context"]["Year"]).to eq ['2009']
expect(results.first["context"]["Formats"][0]).to eq "Vinyl"
expect(results.first["context"]["Record Labels"][1]).to eq "Universal Music Classics & Jazz"
expect(results.first["context"]["Type"][0]).to eq "release"
expect(results.first["context"][1]["Year"]).to eq ["2009"]
expect(results.first["context"][3]["Formats"][0]).to eq "Vinyl"
expect(results.first["context"][2]["Record Labels"][1]).to eq "Universal Music Classics & Jazz"
expect(results.first["context"][4]["Type"][0]).to eq "release"
end
end

Expand All @@ -299,9 +299,9 @@
expect(results.first['uri']).to eq "https://www.discogs.com/Wes-Montgomery-Bumpin-On-Sunset-Tequila/master/606116"
expect(results.first['id']).to eq "606116"
expect(results.first['label']).to eq "Wes Montgomery - Bumpin' On Sunset / Tequila"
expect(results.first['context']["Year"]).to eq ['1966']
expect(results.first['context']["Formats"][2]).to eq "45 RPM"
expect(results.first["context"]["Type"][0]).to eq "master"
expect(results.first['context'][1]["Year"]).to eq ['1966']
expect(results.first['context'][3]["Formats"][2]).to eq "45 RPM"
expect(results.first["context"][4]["Type"][0]).to eq "master"
end
end

Expand Down

0 comments on commit 7e0ff28

Please sign in to comment.