Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Drop elasticsearch search tag

Spawn server for each spec run
  • Loading branch information...
commit a633f48645056ad7f2b24cffb06dbc7331c5ee94 1 parent 5452484
@saulius saulius authored
View
2  spec/controllers/api/v1/chapters/search_references_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Api::V1::Chapters::SearchReferencesController, elasticsearch: true do
+describe Api::V1::Chapters::SearchReferencesController do
it_behaves_like 'search references controller' do
let(:search_reference_parent) { create :chapter }
let(:search_reference) { create :search_reference, chapter_id: search_reference_parent.short_code }
View
2  spec/controllers/api/v1/commodities/search_references_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Api::V1::Commodities::SearchReferencesController, elasticsearch: true do
+describe Api::V1::Commodities::SearchReferencesController do
it_behaves_like 'search references controller' do
let(:search_reference_parent) { create :commodity, :declarable }
let(:search_reference) { create :search_reference, commodity_id: search_reference_parent.code }
View
2  spec/controllers/api/v1/headings/search_references_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Api::V1::Headings::SearchReferencesController, elasticsearch: true do
+describe Api::V1::Headings::SearchReferencesController do
it_behaves_like 'search references controller' do
let(:search_reference_parent) { create :heading }
let(:search_reference) { create :search_reference, heading_id: search_reference_parent.short_code }
View
4 spec/controllers/api/v1/search_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Api::V1::SearchController, "POST #search", elasticsearch: true do
+describe Api::V1::SearchController, "POST #search" do
describe 'exact matching' do
let(:chapter) { create :chapter }
let(:pattern) {
@@ -23,7 +23,7 @@
end
end
- describe 'fuzzy matching', vcr: { cassette_name: "search#search_fuzzy", match_requests_on: [:uri], erb: true } do
+ describe 'fuzzy matching' do
let(:chapter) { create :chapter, :with_description, description: "horse", validity_start_date: Date.today }
let(:pattern) {
{
View
2  spec/controllers/api/v1/sections/search_references_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Api::V1::Sections::SearchReferencesController, elasticsearch: true do
+describe Api::V1::Sections::SearchReferencesController do
it_behaves_like 'search references controller' do
let(:search_reference_parent) { create :section }
let(:search_reference) { create :search_reference, section_id: search_reference_parent.id }
View
9 spec/factories/goods_nomenclature_factory.rb
@@ -45,8 +45,9 @@
end
trait :with_description do
- after(:create) { |gono, evaluator|
+ before(:create) { |gono, evaluator|
FactoryGirl.create(:goods_nomenclature_description, goods_nomenclature_sid: gono.goods_nomenclature_sid,
+ goods_nomenclature_item_id: gono.goods_nomenclature_item_id,
validity_start_date: gono.validity_start_date,
validity_end_date: gono.validity_end_date,
description: evaluator.description)
@@ -133,12 +134,12 @@
description { Forgery(:basic).text }
goods_nomenclature_description_period_sid { generate(:sid) }
- after(:create) { |gono_description, evaluator|
+ before(:create) { |gono_description, evaluator|
FactoryGirl.create(:goods_nomenclature_description_period, goods_nomenclature_description_period_sid: gono_description.goods_nomenclature_description_period_sid,
goods_nomenclature_sid: gono_description.goods_nomenclature_sid,
goods_nomenclature_item_id: gono_description.goods_nomenclature_item_id,
- validity_start_date: evaluator.valid_at,
- validity_end_date: evaluator.valid_to)
+ validity_start_date: evaluator.validity_start_date,
+ validity_end_date: evaluator.validity_end_date)
}
end
end
View
2  spec/factories/search_reference_factory.rb
@@ -6,6 +6,6 @@
factory :search_reference do
title { Forgery(:basic).text }
- association :heading
+ referenced { create :heading }
end
end
View
4 spec/interactors/create_search_reference_spec.rb
@@ -6,7 +6,7 @@
describe '#call' do
context 'search reference valid' do
let(:section) { create :section }
- let(:search_reference_params) { attributes_for(:search_reference, section_id: section.id) }
+ let(:search_reference_params) { attributes_for(:search_reference, referenced: section) }
it 'persists search reference to the database' do
interactor = CreateSearchReference.new(search_reference_params)
@@ -28,7 +28,7 @@
end
context 'search reference is not valid' do
- let(:search_reference_params) { attributes_for(:search_reference, section_id: nil) }
+ let(:search_reference_params) { attributes_for(:search_reference, referenced: nil) }
it 'does not persist search reference to the database' do
CreateSearchReference.create(search_reference_params)
View
6 spec/models/search_reference_spec.rb
@@ -4,7 +4,7 @@
describe '#referenced' do
context "matching heading regexp" do
let(:heading) { create :heading, goods_nomenclature_item_id: "1212000000" }
- let(:search_reference) { create :search_reference, heading_id: heading.short_code }
+ let(:search_reference) { create :search_reference, referenced: heading }
it 'returns referenced Heading object' do
heading
@@ -15,7 +15,7 @@
context 'matching Chapter regexp' do
let(:chapter) { create :chapter, goods_nomenclature_item_id: "1200000000" }
- let(:search_reference) { create :search_reference, chapter_id: chapter.short_code, heading: nil }
+ let(:search_reference) { create :search_reference, referenced: chapter }
it 'returns Chapter object' do
chapter
@@ -26,7 +26,7 @@
context 'matching Seciont regexp' do
let(:section) { create :section, position: 12 }
- let(:search_reference) { create :search_reference, section: section, heading: nil }
+ let(:search_reference) { create :search_reference, referenced: section }
it 'returns Section object' do
section
View
5 spec/serializers/search_reference_serializer_spec.rb
@@ -4,7 +4,7 @@
describe "#to_json" do
context 'when there is a valid referenced object' do
let(:section) { create :section, position: 12 }
- let(:search_reference) { described_class.new(create :search_reference, section_id: section.id, heading: nil) }
+ let(:search_reference) { described_class.new(create :search_reference, referenced: section) }
let(:pattern) {
{
title: search_reference.title,
@@ -28,7 +28,8 @@
create :search_reference,
section_id: nil,
chapter_id: nil,
- heading_id: nil
+ heading_id: nil,
+ referenced: nil
)
}
View
83 spec/services/search_service_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe SearchService, elasticsearch: true do
+describe SearchService do
describe 'initialization' do
let(:query) { Forgery(:basic).text }
@@ -267,6 +267,11 @@
describe 'fuzzy search' do
context 'filtering by date' do
context 'with goods codes that have bounded validity period' do
+ let!(:heading) { create :heading, :with_description,
+ goods_nomenclature_item_id: "2851000000",
+ validity_start_date: Date.new(1972,1,1),
+ validity_end_date: Date.new(2006,12,31),
+ description: 'Other inorganic compounds (including distilled or conductivity water and water of similar purity);' }
# heading that has validity period of 1972-01-01 to 2006-12-31
let(:heading_pattern) {
@@ -274,73 +279,87 @@
type: 'fuzzy_match',
goods_nomenclature_match: {
headings: [
- { "goods_nomenclature_item_id"=>"2851000000" }.ignore_extra_keys!
+ { "_source" => {
+ "goods_nomenclature_item_id" => "2851000000"
+ }.ignore_extra_keys! }.ignore_extra_keys!
].ignore_extra_values!
}.ignore_extra_keys!
}.ignore_extra_keys!
}
it 'returns goods code if search date falls within validity period' do
- VCR.use_cassette("search#fuzzy_date_filter_for_2851000000_2005") do
- @result = SearchService.new(t: "water",
- as_of: "2005-01-01").to_json
+ @result = SearchService.new(t: "water",
+ as_of: "2005-01-01").to_json
- @result.should match_json_expression heading_pattern
- end
+ @result.should match_json_expression heading_pattern
end
it 'does not return goods code if search date does not fall within validity period' do
- VCR.use_cassette("search#fuzzy_date_filter_for_2851000000_2007") do
- @result = SearchService.new(t: "water",
- as_of: "2007-01-01").to_json
+ @result = SearchService.new(t: "water",
+ as_of: "2007-01-01").to_json
- @result.should_not match_json_expression heading_pattern
- end
+ @result.should_not match_json_expression heading_pattern
end
end
context 'with goods codes that have unbounded validity period' do
+ let!(:heading) { create :heading, :with_description,
+ goods_nomenclature_item_id: "0102000000",
+ validity_start_date: Date.new(1972,1,1),
+ validity_end_date: nil,
+ description: 'Live bovine animals' }
+
# heading that has validity period starting from 1972-01-01
let(:heading_pattern) {
{
type: 'fuzzy_match',
goods_nomenclature_match: {
headings: [
- { "goods_nomenclature_item_id"=>"0102000000" }.ignore_extra_keys!
+ { "_source" => {
+ "goods_nomenclature_item_id" => "0102000000"
+ }.ignore_extra_keys!
+ }.ignore_extra_keys!
].ignore_extra_values!
}.ignore_extra_keys!
}.ignore_extra_keys!
}
it 'returns goods code if search date is greater than start of validity period' do
- VCR.use_cassette("search#fuzzy_date_filter_for_0102000000_2007") do
- @result = SearchService.new(t: "animal products",
- as_of: "2007-01-01").to_json
+ @result = SearchService.new(t: "animal products",
+ as_of: "2007-01-01").to_json
- @result.should match_json_expression heading_pattern
- end
+ @result.should match_json_expression heading_pattern
end
it 'does not return goods code if search date is less than start of validity period' do
- VCR.use_cassette("search#fuzzy_date_filter_for_0102000000_1970") do
- @result = SearchService.new(t: "animal products",
- as_of: "1970-01-01").to_json
+ @result = SearchService.new(t: "animal products",
+ as_of: "1970-01-01").to_json
- @result.should_not match_json_expression heading_pattern
- end
+ @result.should_not match_json_expression heading_pattern
end
end
end
end
context 'reference search' do
+ let!(:heading) { create :heading, :with_description,
+ goods_nomenclature_item_id: "2851000000",
+ validity_start_date: Date.new(1972,1,1),
+ validity_end_date: Date.new(2006,12,31),
+ description: 'Test' }
+ let!(:search_reference) { create :search_reference,
+ referenced: heading,
+ title: 'water' }
+
let(:heading_pattern) {
{
type: 'fuzzy_match',
reference_match: {
headings: [
{
- reference: { "goods_nomenclature_item_id"=>"2851000000" }.ignore_extra_keys!
+ "_source" => {
+ reference: { "goods_nomenclature_item_id"=>"2851000000" }.ignore_extra_keys!
+ }.ignore_extra_keys!
}.ignore_extra_keys!
].ignore_extra_values!
}.ignore_extra_keys!
@@ -348,21 +367,17 @@
}
it 'returns goods code if search date falls within validity period' do
- VCR.use_cassette("search#fuzzy_date_filter_for_2851000000_2005") do
- @result = SearchService.new(t: "water",
- as_of: "2005-01-01").to_json
+ @result = SearchService.new(t: "water",
+ as_of: "2005-01-01").to_json
- @result.should match_json_expression heading_pattern
- end
+ @result.should match_json_expression heading_pattern
end
it 'does not return goods code if search date does not fall within validity period' do
- VCR.use_cassette("search#fuzzy_date_filter_for_2851000000_2007") do
- @result = SearchService.new(t: "water",
- as_of: "2007-01-01").to_json
+ @result = SearchService.new(t: "water",
+ as_of: "2007-01-01").to_json
- @result.should_not match_json_expression heading_pattern
- end
+ @result.should_not match_json_expression heading_pattern
end
end
end
View
1  spec/spec_helper.rb
@@ -28,7 +28,6 @@
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.treat_symbols_as_metadata_keys_with_true_values = true
- config.filter_run_excluding elasticsearch: true unless ENV['ELASTICSEARCH']
config.alias_it_should_behave_like_to :it_results_in, "it results in"
config.alias_it_should_behave_like_to :it_is_associated, "it is associated"
config.include RSpec::Rails::RequestExampleGroup, type: :request,
View
18 spec/support/elasticsearch.rb
@@ -1,17 +1,15 @@
RSpec.configure do |config|
config.before(:suite) do
- unless config.exclusion_filter[:elasticsearch]
- Elasticsearch::Extensions::Test::Cluster.start \
- cluster_name: "#{Rails.application.class.parent_name}-testing-cluster",
- nodes: 1,
- port: 9350
- end
+ Elasticsearch::Extensions::Test::Cluster.start \
+ cluster_name: TradeTariffBackend.search_namespace,
+ nodes: 1,
+ port: TradeTariffBackend.search_port
+
+ TradeTariffBackend.search_client.reindex
end
config.after(:suite) do
- unless config.exclusion_filter[:elasticsearch]
- Elasticsearch::Extensions::Test::Cluster.stop \
- port: 9350
- end
+ Elasticsearch::Extensions::Test::Cluster.stop \
+ port: TradeTariffBackend.search_port
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.