Skip to content
This repository has been archived by the owner on Mar 10, 2018. It is now read-only.

Commit

Permalink
Don't raise ActiveRecord::RecordNotFound for missing attachments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Oct 10, 2015
1 parent 89b870f commit f16cd8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/coupons/globalid_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ def self.load(attachments)
attachments = JSON.load(attachments)

attachments.each_with_object({}) do |(key, uri), buffer|
buffer[key.to_sym] = GlobalID::Locator.locate(uri)
buffer[key.to_sym] = GlobalID::Locator
.locate_many([uri], ignore_missing: true)
.first
end
end

Expand Down
13 changes: 13 additions & 0 deletions spec/models/coupons/models/coupon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,18 @@

expect(coupon.reload.attachments[:category]).to eq(category)
end

it 'returns missing attachments as nil' do
coupon = create_coupon(
amount: 10,
type: 'amount',
attachments: {category: category}
)

category.destroy
coupon.reload

expect(coupon.attachments[:category]).to be_nil
end
end
end

0 comments on commit f16cd8e

Please sign in to comment.