Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Do not include hidden GoodsNomenclature in Heading commodity tree.

  • Loading branch information...
commit 33c566f1ba24c0ed2abdd935ccafc7df2d31ab96 1 parent c5511c2
@saulius saulius authored
View
4 app/controllers/api/v1/headings_controller.rb
@@ -32,7 +32,9 @@ def show
:measure_partial_temporary_stop).all, @heading).validate!
else
@commodities = GoodsNomenclatureMapper.new(@heading.commodities_dataset.eager(:goods_nomenclature_indent,
- :goods_nomenclature_description).all).all
+ :goods_nomenclature_description)
+ .all
+ .delete_if{|c| c.goods_nomenclature_item_id =~ HiddenGoodsNomenclature.to_pattern}).all
end
View
16 spec/controllers/api/v1/headings_controller_spec.rb
@@ -21,11 +21,25 @@
context 'when record is present' do
it 'returns rendered record' do
get :show, id: heading, format: :json
-
response.body.should match_json_expression pattern
end
end
+ context 'when record is present and commodity has hidden commodities' do
+ let!(:commodity1) { create :commodity, :with_indent, :with_description, :with_chapter, :declarable, goods_nomenclature_item_id: "#{heading.short_code}010000"}
+ let!(:commodity2) { create :commodity, :with_indent, :with_description, :with_chapter, :declarable, goods_nomenclature_item_id: "#{heading.short_code}020000"}
+
+ let!(:hidden_goods_nomenclature) { create :hidden_goods_nomenclature, goods_code_identifier: commodity2.goods_nomenclature_item_id }
+
+ it 'does not include hidden commodities in the response' do
+ get :show, id: heading, format: :json
+
+ body = JSON.parse(response.body)
+ body["commodities"].map{|c| c["goods_nomenclature_item_id"] }.should include commodity1.goods_nomenclature_item_id
+ body["commodities"].map{|c| c["goods_nomenclature_item_id"] }.should_not include commodity2.goods_nomenclature_item_id
+ end
+ end
+
context 'when record is not present' do
it 'returns not found if record was not found' do
expect { get :show, id: "5555", format: :json }.to raise_error Sequel::RecordNotFound
Please sign in to comment.
Something went wrong with that request. Please try again.