Skip to content

Commit 18064fd

Browse files
committed
Add spec for including image and terms
1 parent ee63efc commit 18064fd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

spec/requests/items_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@
297297
expect(terms_data).to contain_exactly(*expected_terms_data)
298298
end
299299

300-
it 'includes the image' do
300+
it 'can include both image and terms' do
301301
item = Item.take
302302

303-
get item_url(item), params: { include: 'image' }
303+
get item_url(item), params: { include: 'image,terms' }
304304
parsed_response = JSON.parse(response.body)
305305
data = parsed_response['data']
306306

@@ -312,6 +312,13 @@
312312

313313
expected_data = ImageSerializer.new(item.image).serializable_hash[:data]
314314
expect(included[0]).to deep_eq_hash(expected_data, indifferent: true)
315+
316+
item.terms.each do |t|
317+
expected_term_data = TermSerializer.new(t).serializable_hash[:data]
318+
actual_term_data = included.find { |h| h['type'] == 'term' && h['id'] == t.id.to_s }
319+
expect(actual_term_data).not_to(be_nil)
320+
expect(actual_term_data).to deep_eq_hash(expected_term_data, indifferent: true)
321+
end
315322
end
316323
end
317324
end

0 commit comments

Comments
 (0)