Skip to content

Commit

Permalink
Merge pull request #2542 from pulibrary/graphql_resource_thumbnail
Browse files Browse the repository at this point in the history
Handle thumbnail returning nil in GraphQL
  • Loading branch information
tpendragon committed Feb 6, 2019
2 parents 58e0c1b + 2f7ffe6 commit c378fca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/graphql/types/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def helper
end

def thumbnail
return if object.try(:thumbnail_id).blank? || thumbnail_resource.blank?
return if object.try(:thumbnail_id).blank? || thumbnail_resource.blank? || helper.figgy_thumbnail_path(thumbnail_resource).blank?
{
id: thumbnail_resource.id.to_s,
thumbnail_url: helper.figgy_thumbnail_path(thumbnail_resource),
Expand Down
4 changes: 4 additions & 0 deletions spec/graphql/types/scanned_resource_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
id: file_set.id.to_s
)
end
it "returns nil if the helper fails to return a thumbnail path" do
allow(type.helper).to receive(:figgy_thumbnail_path).and_return(nil)
expect(type.thumbnail).to be_nil
end
end
context "when a bad thumbnail is set" do
let(:scanned_resource) do
Expand Down

0 comments on commit c378fca

Please sign in to comment.