Skip to content

Commit

Permalink
Only handle browse block items whose block id/slug exists.
Browse files Browse the repository at this point in the history
This is a temporary fix to stop errors being thrown on edit pages.  A more permanent solution should be implemented in the future.
  • Loading branch information
jkeck committed Nov 1, 2017
1 parent 02b4c3f commit 290538c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/sir_trevor_rails/blocks/browse_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def as_json

result[:data][:item] ||= {}

# TODO: This is a temporary fix that simply removes any item if the search identifier does not exist
# We should have a more permanent solution that will allow browse blocks to be updated without erroring
result[:data][:item].select! { |_, v| parent.exhibit.searches.exists?(v['id']) }

result[:data][:item].each_value do |v|
v['thumbnail_image_url'] = parent.exhibit.searches.find(v['id']).thumbnail_image_url
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
expect(subject.as_json[:data]).to include items: nil
end
end

context 'when the id of a browse category does not exist' do
it 'is not included the returned items hash' do
search = FactoryGirl.create(:search, exhibit: page.exhibit)
block_data[:item] = { item_0: { 'id' => 'abc123' }, item_1: { 'id' => search.slug } }

expect(subject.as_json[:data][:item]).not_to have_key :item_0
expect(subject.as_json[:data][:item]).to have_key :item_1
end
end
end
end

0 comments on commit 290538c

Please sign in to comment.