This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add commodity codes to be hidden.

Prevent 'clever' search from fiding hidden chapters/headings/commodities.
  • Loading branch information...
1 parent 37df738 commit 7251ca8dfd820d184d0764dce85ae99c1db2406a @saulius saulius committed Dec 4, 2012
@@ -122,9 +122,13 @@ class GoodsNomenclature < Sequel::Model
foreign_key: :goods_nomenclature_sid
dataset_module do
- def declarable
+ def declarable
filter(producline_suffix: 80)
end
+
+ def non_hidden
+ filter(~{goods_nomenclature_item_id: HiddenGoodsNomenclature.codes})
+ end
end
# TODO
@@ -26,17 +26,47 @@ class ExactSearch < BaseSearch
def search!
@results = case query_string
when /^[0-9]{1,3}$/
- Chapter.actual.by_code(query_string).first
+ Chapter.actual
+ .by_code(query_string)
+ .non_hidden
+ .first
when /^[0-9]{4,9}$/
- Heading.actual.by_code(query_string).first
+ Heading.actual
+ .by_code(query_string)
+ .non_hidden
+ .first
when /^[0-9]{10}$/
- Commodity.actual.by_code(query_string).declarable.first.presence ||
- Heading.actual.by_declarable_code(query_string).declarable.first.presence
+ Commodity.actual
+ .by_code(query_string)
+ .non_hidden
+ .declarable
+ .first
+ .presence ||
+ Heading.actual
+ .by_declarable_code(query_string)
+ .declarable
+ .non_hidden
+ .first
+ .presence
when /^\d{2}\s*\d{2}\s*\d{2}\s*\d{2}\s*\d{2}$/
- Commodity.actual.by_code(query_string.gsub(/\s+/, '')).declarable.first.presence ||
- Heading.actual.by_declarable_code(query_string.gsub(/\s+/, '')).declarable.first.presence
+ Commodity.actual
+ .by_code(query_string.gsub(/\s+/, ''))
+ .declarable
+ .non_hidden
+ .first
+ .presence ||
+ Heading.actual
+ .by_declarable_code(query_string.gsub(/\s+/, ''))
+ .declarable
+ .non_hidden
+ .first
+ .presence
when /^[0-9]{11,12}$/
- Commodity.actual.by_code(query_string).declarable.first
+ Commodity.actual
+ .by_code(query_string)
+ .non_hidden
+ .declarable
+ .first
end
self
@@ -0,0 +1,29 @@
+Sequel.migration do
+ CODES =
+ ["9900000000",
+ "9905000000",
+ "9905000000",
@matthewford

matthewford Dec 4, 2012

Contributor

not that this actually makes much difference but this looks like a duplicate

@saulius

saulius Dec 4, 2012

Contributor

Ah sorry, should have been distinct codes. 9905000000 has two producline suffixes.

+ "9919000000",
+ "9930000000",
+ "9930240000",
+ "9930270000",
+ "9930990000",
+ "9931000000",
+ "9931240000",
+ "9931270000",
+ "9931990000",
+ "9950000000"]
+
+ up do
+ CODES.each do |code|
+ HiddenGoodsNomenclature.create(goods_nomenclature_item_id: code)
+ end
+ end
+
+ down do
+ CODES.each do |code|
+ HiddenGoodsNomenclature.where(goods_nomenclature_item_id: code)
+ .delete
+ end
+ end
+end
View
@@ -1554,6 +1554,7 @@
self[:schema_migrations].insert(:filename => "20121109121219_remove_invalid_measures.rb")
self[:schema_migrations].insert(:filename => "20121129094209_add_invalidated_columns_to_measures.rb")
self[:schema_migrations].insert(:filename => "20121204130816_create_hidden_goods_nomenclatures.rb")
+ self[:schema_migrations].insert(:filename => "20121204143748_add_hidden_commodities.rb")
create_table(:search_references) do
primary_key :id, :type=>"int(11)"
@@ -13,6 +13,10 @@
let!(:heading3) { create :heading, goods_nomenclature_item_id: "#{chapter.goods_nomenclature_item_id.first(2)}30000000",
validity_start_date: 10.years.ago,
validity_end_date: 8.years.ago }
+ let!(:heading4) { create :heading, goods_nomenclature_item_id: "#{chapter.goods_nomenclature_item_id.first(2)}40000000",
+ validity_start_date: 10.years.ago,
+ validity_end_date: nil }
+ let!(:hidden_gono) { create :hidden_goods_nomenclature, goods_nomenclature_item_id: heading4.goods_nomenclature_item_id }
around(:each) do |example|
TimeMachine.at(1.year.ago) do
@@ -31,6 +35,10 @@
it 'does not return heading that is irrelevant to given time' do
chapter.headings.should_not include heading3
end
+
+ it 'does not include hidden commodity' do
+ chapter.headings.should_not include heading4
+ end
end
end
@@ -4,6 +4,7 @@
describe 'associations' do
describe 'chapters' do
it 'does not include HiddenGoodsNomenclatures' do
+ pending
end
end
end

0 comments on commit 7251ca8

Please sign in to comment.