Skip to content

Loading…

Chief transformer refactor #37

Merged
merged 2 commits into from

2 participants

@saulius

Okay this fix was long due. It is related to the email I sent a while ago. Two major things here:

  1. Certain TARIC updates may invalidate national measures apparently. GoodsNomenclature associated to Measure should span its validity dates (ME8 conformance test). So say we create Measure for GoodsNomenclature that has open ended validity end date. Later Taric updates that GoodsNomenclature to have certain validity date. Some of the national Measures can become invalid. On top of that, CHIEF may try to update those invalid measures later on (just what happened actually). So to prevent it we check for national measure validity after GoodsNomeclature gets updated and do a soft delete (set invalidated by to Taric transaction id) for the measure. Later on, we ignore validations for such measures in case CHIEF will try to update them, so we just allow that. I found that there were 56 national measures invalidated up to 29th of Nov.

  2. Consolidate update application and transformation, so that transformation is invoked after CHIEF updates get applied. This would eventually become an issue for snapshot recreation (in case of need) process. We used to apply all Taric updates, then all CHIEF updates and then do transformation in one go for all CHIEF records. Imagine a scenario where Taric introduces Commodity on 1st of July, CHIEF adds national measures on say the 2nd of July and Taric removes Commodity on 1st of August. If we would apply all Taric's updates then we wouldn't even create CHIEF measure as if that Commodity was never there.

@saulius

I added a snapshot (snapshot_for_29-11-2012.sql.bz2) that has up to date data including invalidated measures.

@jabley

Where possible I would like to add associated tests in smokey or similar. Currently some of our tests are ping-like (is the service there?) rather than checking the content of the page.

@saulius

I'm not sure tests on content are a good thing. Both CHIEF and Taric change that data from time to time so tests may fail even if nothing wrong happened. Do you still want me to list some examples?

@jabley jabley merged commit 1d8a549 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 28, 2012
  1. @saulius

    Fix validation errors.

    saulius committed
Commits on Nov 29, 2012
  1. @saulius
View
5 app/models/goods_nomenclature.rb
@@ -113,6 +113,9 @@ class GoodsNomenclature < Sequel::Model
actual(ExportRefundNomenclature).where(goods_nomenclature_sid: goods_nomenclature_sid)
}
+ one_to_many :measures, key: :goods_nomenclature_sid,
+ foreign_key: :goods_nomenclature_sid
+
dataset_module do
def declarable
filter(producline_suffix: 80)
@@ -121,6 +124,8 @@ def declarable
# TODO
validates do
+ # NIG30 When a goods nomenclature is used in a goods measure then the validity period of the goods nomenclature must span the validity period of the goods measure.
+ # associated :measures, ensure: :measures_are_valid
# NIG4
validity_dates
end
View
21 app/models/measure.rb
@@ -229,15 +229,15 @@ class Measure < Sequel::Model
presence_of :measure_type, :geographical_area_sid, :goods_nomenclature_sid, :measure_generating_regulation_id, :measure_generating_regulation_role
# ME1
# TODO
- # uniqueness_of [:measure_type, :geographical_area_sid, :goods_nomenclature_sid, :additional_code_type, :additional_code, :ordernumber, :reduction_indicator, :validity_start_date]
+ uniqueness_of [:measure_type, :geographical_area_sid, :goods_nomenclature_sid, :additional_code_type, :additional_code, :ordernumber, :reduction_indicator, :validity_start_date]
# ME3 ME5 ME8 ME115 ME18 ME114 ME15
# TODO
- # validity_date_span_of :geographical_area, :type, :goods_nomenclature, :additional_code
+ validity_date_span_of :geographical_area, :type, :goods_nomenclature, :additional_code
# ME25
# TODO
- # validity_dates
+ validity_dates
# ME7 ME88
- # associated :goods_nomenclature, ensure: :qualified_goods_nomenclature?
+ associated :goods_nomenclature, ensure: :qualified_goods_nomenclature?
# ME10
associated :quota_order_number, ensure: :quota_order_number_present?,
if: :type_order_number_capture_code_permitted?
@@ -319,6 +319,15 @@ def is_ended?
validity_end_date.present?
end
+ # Soft-deleted
+ def invalidated?
+ invalidated_by.present?
+ end
+
+ def validate
+ model.validate(self) unless self.invalidated?
+ end
+
######### Conformance validations 430
# def validate
# super
@@ -509,6 +518,10 @@ def expired_before(candidate_measure)
where("validity_start_date < ?", candidate_measure.validity_start_date).
where(validity_end_date: nil)
end
+
+ def non_invalidated
+ where(measures__invalidated_at: nil)
+ end
end
def_column_accessor :effective_end_date, :effective_start_date
View
38 app/views/chief_transformer/mailer/failed_transformation_notice.html.erb
@@ -1,20 +1,42 @@
<p>Hello,</p>
<p>
-Trade Tariff failed to transform pending CHIEF records at <%= Time.now %>.
+Trade Tariff stumbled upon invalid CHIEF operation.
</p>
<p>
- Changes that were possibly made by the following operation were reverted (each operation is wrapped in transaction). Operation is left in pending state.
+ The following operation was not marked as processed. Either fix it or remove the operation entry to not receive this letter again.
</p>
-<p>
- <strong>Failed operation:</strong> <%= @operation.inspect %>
-</p>
+<h3>Operation:</h3>
-<p>
- <strong>Exception: <%= @exception %></strong>
-</p>
+<pre>
+ <%= @operation.inspect %>
+</pre>
+
+<% if @model.present? %>
+ <h3>Model:</h3>
+
+ <pre>
+ <%= @model.inspect %>
+ </pre>
+<% end %>
+
+<% if @errors.present? %>
+ <h3>Errors:</h3>
+
+ <pre>
+ <%= @errors.inspect %>
+ </pre>
+<% end %>
+
+<h3>Exception</h3>
+
+<pre>
+ <%= @exception %>
+</pre>
+
+<h3>Backtrace</h3>
<pre>
<%= @exception.backtrace.join("\n") %>
View
4 config/schedule.rb
@@ -4,10 +4,6 @@
rake "tariff:sync:apply"
end
-every 1.day, at: '6am' do
- rake "tariff:sync:transform"
-end
-
every 1.day, at: '10pm' do
rake "tariff:support:clean_national_measures"
end
View
8 db/migrate/20121129094209_add_invalidated_columns_to_measures.rb
@@ -0,0 +1,8 @@
+Sequel.migration do
+ change do
+ alter_table :measures do
+ add_column :invalidated_by, Integer
+ add_column :invalidated_at, DateTime
+ end
+ end
+end
View
3 db/schema.rb
@@ -1081,6 +1081,8 @@
column :updated_at, "datetime"
column :national, "tinyint(1)"
column :tariff_measure_number, "varchar(10)"
+ column :invalidated_by, "int(11)"
+ column :invalidated_at, "datetime"
index [:additional_code_sid], :name=>:index_measures_on_additional_code_sid
index [:geographical_area_sid], :name=>:index_measures_on_geographical_area_sid
@@ -1544,6 +1546,7 @@
self[:schema_migrations].insert(:filename => "20121109110125_create_update_measure_explosions.rb")
self[:schema_migrations].insert(:filename => "20121109121107_fix_chief_last_effective_dates.rb")
self[:schema_migrations].insert(:filename => "20121109121219_remove_invalid_measures.rb")
+ self[:schema_migrations].insert(:filename => "20121129094209_add_invalidated_columns_to_measures.rb")
create_table(:search_references) do
primary_key :id, :type=>"int(11)"
View
7 lib/chief_transformer/candidate_measure.rb
@@ -51,7 +51,7 @@ def before_validation
# must happen after validity dates are set, depends on start date
self.additional_code_sid = AdditionalCode.where(additional_code_type_id: additional_code_type,
additional_code: additional_code)
- .where("validity_start_date >= ? AND (validity_end_date <= ? OR validity_end_date IS NULL)", validity_start_date, validity_end_date)
+ .where("validity_start_date <= ? AND (validity_end_date >= ? OR validity_end_date IS NULL)", validity_start_date, validity_end_date)
.first
.try(:additional_code_sid)
# needs to throw errors about invalid geographical area
@@ -70,6 +70,7 @@ def before_validation
# needs to throw errors about invalid goods nomenclature item found
self.goods_nomenclature_sid = GoodsNomenclature.where(goods_nomenclature_item_id: goods_nomenclature_item_id)
+ .where("validity_start_date <= ? AND (validity_end_date >= ? OR validity_end_date IS NULL)", validity_start_date, validity_end_date)
.declarable
.order(:validity_start_date.desc)
.first
@@ -125,6 +126,10 @@ def rebuild
callbacks
end
+ def self.validations
+ []
+ end
+
def validate
super
View
10 lib/chief_transformer/logger.rb
@@ -23,9 +23,13 @@ def process(event)
end
end
- def exception(event)
- error "Could not transform: #{event.payload[:operation].inspect}. \n #{event.payload[:exception]} \nBacktrace: \n#{event.payload[:exception].backtrace.join("\n")}"
- Mailer.failed_transformation_notice(event.payload[:exception], event.payload[:operation]).deliver
+ def invalid_operation(event)
+ error "Could not transform #{event.payload[:operation].inspect}. \nFailed model: #{event.payload[:model].inspect}. \nErrors: #{event.payload[:errors].inspect}. \nException: #{event.payload[:exception]}. \nBacktrace: #{event.payload[:exception].backtrace.join("\n")}"
+
+ Mailer.failed_transformation_notice(event.payload[:operation],
+ event.payload[:exception],
+ event.payload[:model],
+ event.payload[:errors]).deliver
end
end
end
View
6 lib/chief_transformer/mailer.rb
@@ -7,9 +7,11 @@ def successful_transformation_notice
mail subject: '[info] Successful CHIEF transformation'
end
- def failed_transformation_notice(exception, operation)
- @exception = exception
+ def failed_transformation_notice(operation, exception, model, errors)
@operation = operation
+ @exception = exception
+ @model = model
+ @errors = errors
mail subject: '[error] Failed CHIEF transformation'
end
View
1 lib/chief_transformer/operations/mfcm_delete.rb
@@ -7,6 +7,7 @@ def process
Measure.with_measure_type(record.measure_type)
.with_gono_id(record.cmdty_code)
.valid_to(record.fe_tsmp)
+ .not_terminated
.each do |measure|
end_date = (measure.goods_nomenclature.validity_end_date.present? && record.fe_tsmp > measure.goods_nomenclature.validity_end_date) ? measure.goods_nomenclature.validity_end_date : record.fe_tsmp
measure.update validity_end_date: end_date
View
11 lib/chief_transformer/processor.rb
@@ -16,9 +16,16 @@ def process
operator_for(operation).new(operation).process
operation.mark_as_processed!
+ rescue Sequel::ValidationFailed => exception
+ ActiveSupport::Notifications.instrument("invalid_operation.chief_transformer", operation: operation,
+ exception: exception,
+ model: exception.model,
+ errors: exception.errors)
+
+ raise ChiefTransformer::TransformException.new("Could not transform: #{operation.inspect}. \nModel: #{exception.model.inspect}. \nErrors: #{exception.errors.inspect} \nBacktrace: \n#{exception.backtrace.join("\n")}", exception)
rescue Exception => exception
- ActiveSupport::Notifications.instrument("exception.chief_transformer", operation: operation,
- exception: exception)
+ ActiveSupport::Notifications.instrument("invalid_operation.chief_transformer", operation: operation,
+ exception: exception)
raise ChiefTransformer::TransformException.new("Could not transform: #{operation.inspect}. \n #{exception} \nBacktrace: \n#{exception.backtrace.join("\n")}", exception)
end
View
2 lib/sequel/plugins/national.rb
@@ -3,7 +3,7 @@ module Plugins
module National
module DatasetMethods
def national
- where("#{model.primary_key} < 0").order(model.primary_key.desc)
+ where(Sequel.qualify(model.table_name, model.primary_key) < 0).order(Sequel.qualify(model.table_name, model.primary_key).desc)
end
end
View
16 lib/tariff_importer/importers/taric_importer/strategies/base_strategy.rb
@@ -3,12 +3,14 @@ module Strategies
class BaseStrategy
include TaricImporter::Helpers::StringHelper
- attr_accessor :xml, :operation, :processor, :attributes, :record_attributes
+ attr_accessor :xml, :operation, :processor, :attributes, :record_attributes,
+ :klass, :primary_key, :transaction_id
def initialize(xml)
self.xml = xml
self.operation = xml.xpath("record/update.type").text
self.attributes = xml.xpath("record/update.type/following-sibling::*").first.children
+ self.transaction_id = xml.xpath("record/transaction.id").text
self.record_attributes = {
record_code: xml.xpath("record/record.code").text,
subrecord_code: xml.xpath("record/subrecord.code").text,
@@ -36,6 +38,9 @@ def operation=(operation)
def processors; self.class.processors; end
def process!
+ @klass = "::#{self.class.name.demodulize}".constantize
+ @primary_key = [klass.primary_key].flatten.map(&:to_s)
+
# execute either defined or default strategy process action
if processors.has_key?(operation) &&
processors[operation].is_a?(Proc)
@@ -50,17 +55,14 @@ def process!
private
def default_process
- klass = "::#{self.class.name.demodulize}".constantize
- primary_key = [klass.primary_key].flatten.map(&:to_s)
-
case operation
when :insert
klass.model.insert(self.attributes)
when :delete
- klass.db[klass.table_name].filter(self.attributes.slice(*primary_key).symbolize_keys).delete
+ klass.filter(self.attributes.slice(*primary_key).symbolize_keys).delete
when :update
- klass.db[klass.table_name].filter(self.attributes.slice(*primary_key).symbolize_keys)
- .update(self.attributes.symbolize_keys)
+ klass.filter(self.attributes.slice(*primary_key).symbolize_keys)
+ .update(self.attributes.symbolize_keys)
end
end
View
15 lib/tariff_importer/importers/taric_importer/strategies/strategies.rb
@@ -129,6 +129,21 @@ class QuotaReopeningEvent < BaseStrategy
class QuotaUnsuspensionEvent < BaseStrategy
end
class GoodsNomenclature < BaseStrategy
+ # NOTE Taric update on GoodsNomenclature may result in associated national measures
+ # becoming invalid as a result of ME8 conformance validation.
+ # Therefore we do a soft delete by setting invalidated columns. No further
+ # validations will be performed on such measures. They won't be provided
+ # via API either.
+ process(:update) {
+ goods_nomenclature = klass.filter(self.attributes.slice(*primary_key).symbolize_keys).first
+ goods_nomenclature.update(self.attributes.except(*primary_key).symbolize_keys)
+ goods_nomenclature.measures_dataset.national.non_invalidated.each do |measure|
+ unless measure.valid?
+ measure.update invalidated_by: transaction_id,
+ invalidated_at: Time.now
+ end
+ end
+ }
end
class GoodsNomenclatureIndent < BaseStrategy
end
View
2 lib/tariff_synchronizer.rb
@@ -108,6 +108,8 @@ def apply
Sequel::Model.db.transaction do
begin
pending_update.apply
+
+ ::ChiefTransformer.instance.invoke(:update) if pending_update.update_type == "TariffSynchronizer::ChiefUpdate"
rescue TaricImporter::ImportException,
ChiefImporter::ImportException,
TariffImporter::NotFound => exception
View
2 lib/tariff_synchronizer/pending_update.rb
@@ -3,7 +3,7 @@ class PendingUpdate
attr_reader :update,
:file_name
- delegate :apply, :issue_date, :update_priority, to: :update
+ delegate :apply, :issue_date, :update_type, :update_priority, to: :update
def initialize(update)
@file_name = update.filename
View
2 spec/factories/measure_factory.rb
@@ -13,7 +13,7 @@
validity_end_date { nil }
trait :national do
- national { true }
+ sequence(:measure_sid) { |n| -1 * n }
end
trait :with_goods_nomenclature do
View
73 spec/integration/chief_transformer/custom_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+require 'goods_nomenclature'
+require 'chief_transformer'
+require 'tariff_importer'
+
+describe 'CHIEF: Custom scenarions' do
+ before(:all) { preload_standing_data }
+ after(:all) { clear_standing_data }
+
+ # Based on real data
+ describe 'Scenario: TARIC update invalidates CHIEF measures' do
+ let!(:measure_type) { create :measure_type, measure_type_id: 'CVD' }
+ let!(:geographical_area) { create :geographical_area, :erga_omnes }
+ let!(:goods_nomenclature) { create :goods_nomenclature, :declarable,
+ :with_indent,
+ goods_nomenclature_sid: 70180,
+ validity_start_date: DateTime.parse("1998-07-14 00:00:00 -0700"),
+ validity_end_date: nil }
+ let!(:goods_nomenclature_indent) { create :goods_nomenclature_indent, number_indents: 10,
+ validity_start_date: DateTime.parse("1998-07-14 00:00:00 -0700"),
+ goods_nomenclature_sid: goods_nomenclature.goods_nomenclature_sid,
+ goods_nomenclature_item_id: goods_nomenclature.goods_nomenclature_item_id }
+ let(:national_measure) { create :measure, :national, :with_base_regulation,
+ measure_type: measure_type.measure_type_id,
+ geographical_area_id: geographical_area.geographical_area_id,
+ geographical_area_sid: geographical_area.geographical_area_sid,
+ goods_nomenclature_sid: goods_nomenclature.goods_nomenclature_sid,
+ goods_nomenclature_item_id: goods_nomenclature.goods_nomenclature_item_id,
+ tariff_measure_number: goods_nomenclature.goods_nomenclature_item_id,
+ validity_start_date: DateTime.parse("2012-03-01 00:00:00 +0200") }
+
+ specify 'national measure is valid before update' do
+ national_measure.valid?.should be_true
+ end
+
+ context 'Taric update occurs' do
+ let(:transaction_id) { 13565498 }
+
+ # Update goods nomenclature effectively leaving national measure invalid!
+ # As goods_nomenclature now does not span the validity period of national_measure (ME8)
+ def perform_transaction()
+ transaction_xml = Nokogiri::XML.parse(%Q{
+ <oub:record>
+ <oub:transaction.id>#{transaction_id}</oub:transaction.id>
+ <oub:record.code>400</oub:record.code>
+ <oub:subrecord.code>00</oub:subrecord.code>
+ <oub:record.sequence.number>199</oub:record.sequence.number>
+ <oub:update.type>1</oub:update.type>
+ <oub:goods.nomenclature>
+ <oub:goods.nomenclature.sid>70180</oub:goods.nomenclature.sid>
+ <oub:goods.nomenclature.item.id>1604141620</oub:goods.nomenclature.item.id>
+ <oub:producline.suffix>10</oub:producline.suffix>
+ <oub:validity.start.date>1998-07-14</oub:validity.start.date>
+ <oub:validity.end.date>2011-12-31</oub:validity.end.date>
+ <oub:statistical.indicator>0</oub:statistical.indicator>
+ </oub:goods.nomenclature>
+ </oub:record>
+ })
+ transaction_xml.remove_namespaces!
+
+ TaricImporter::Strategies::GoodsNomenclature.new(transaction_xml).process!
+ end
+
+ specify 'sets national measures invalidate_by to Taric transaction number' do
+ national_measure
+
+ perform_transaction
+
+ national_measure.reload.invalidated_by.should eq transaction_id
+ end
+ end
+ end
+end
View
26 spec/models/measure_spec.rb
@@ -372,30 +372,26 @@
# ME1 The combination of measure type + geographical area +
# goods nomenclature item id + additional code type + additional code +
# order number + reduction indicator + start date must be unique
- # TODO
- # it { should validate_uniqueness.of([:measure_type, :geographical_area_sid,
- # :goods_nomenclature_sid,
- # :additional_code_type,
- # :additional_code, :ordernumber,
- # :reduction_indicator,
- # :validity_start_date]) }
+ it { should validate_uniqueness.of([:measure_type, :geographical_area_sid,
+ :goods_nomenclature_sid,
+ :additional_code_type,
+ :additional_code, :ordernumber,
+ :reduction_indicator,
+ :validity_start_date]) }
# ME3 ME115 ME8 ME5 ME18 ME114 ME15 The validity period of the <associated record>
# must span the validity period of the measure
- # TODO
- # it { should validate_validity_date_span.of(:geographical_area, :type,
- # :goods_nomenclature,
- # :additional_code) }
+ it { should validate_validity_date_span.of(:geographical_area, :type,
+ :goods_nomenclature,
+ :additional_code) }
# ME25 If the measures end date is specified (implicitly or explicitly)
# then the start date of the measure must be less than
# or equal to the end date
- # TODO
- # it { should validate_validity_dates }
+ it { should validate_validity_dates }
# ME7 The goods nomenclature code must be a product code; that is,
# it may not be an intermediate line
# ME88 The level of the goods code, if present, cannot exceed the
# explosion level of the measure type.
- # TODO
- # it { should validate_associated(:goods_nomenclature).and_ensure(:qualified_goods_nomenclature?) }
+ it { should validate_associated(:goods_nomenclature).and_ensure(:qualified_goods_nomenclature?) }
# ME10 The order number must be specified if the "order number flag"
# (specified in the measure type record) has the value "mandatory".
# If the flag is set to "not permitted" then the field cannot be entered.
View
36 spec/unit/chief_transformer/logger_spec.rb
@@ -38,17 +38,26 @@
end
context 'transformation with errors' do
+ let!(:tame) { create :tame, :unprocessed }
+ let!(:measure) { create :measure }
+
before {
- ChiefTransformer::Processor.expects(:new)
- .raises(ChiefTransformer::TransformException)
+ Chief::Tame.any_instance.expects(:mark_as_processed!)
+ .raises(Sequel::ValidationFailed.new(measure))
rescuing { ChiefTransformer.instance.invoke }
}
it 'logs an error event' do
- @logger.logged(:error).size.should eq 1
+ @logger.logged(:error).size.should be >= 2
@logger.logged(:error).last.should =~ /transformer failed/i
end
+
+ it 'sends an error email' do
+ ActionMailer::Base.deliveries.should_not be_empty
+ email = ActionMailer::Base.deliveries.last
+ email.encoded.should =~ /invalid CHIEF operation/
+ end
end
end
@@ -64,25 +73,4 @@
end
end
end
-
- describe '#exception logging' do
- let!(:tame) { create :tame }
-
- before {
- tame.expects(:mark_as_processed!).raises(StandardError)
-
- rescuing { ChiefTransformer::Processor.new([tame]).process }
- }
-
- it 'logs an error event' do
- @logger.logged(:error).size.should eq 1
- @logger.logged(:error).last.should =~ /Could not transform/i
- end
-
- it 'sends an error email to the administrator' do
- ActionMailer::Base.deliveries.should_not be_empty
- email = ActionMailer::Base.deliveries.last
- email.encoded.should =~ /failed to transform/
- end
- end
end
View
12 spec/unit/tariff_importer/importers/taric_importer/strategies/base_strategy_spec.rb
@@ -67,10 +67,8 @@ class ExplicitAbrogationRegulation
subject { TaricImporter::Strategies::ExplicitAbrogationRegulation.new(update_xml) }
it 'calls Sequel record update by default' do
- db_stub, filter_stub, update_stub = stub(), stub(), stub()
- ExplicitAbrogationRegulation.expects(:db).returns(db_stub)
- db_stub.expects(:[]).returns(filter_stub)
- filter_stub.expects(:filter).returns(update_stub)
+ update_stub = stub()
+ ExplicitAbrogationRegulation.expects(:filter).returns(update_stub)
update_stub.expects(:update).returns(true)
subject.process!
@@ -86,10 +84,8 @@ class ExplicitAbrogationRegulation
subject { TaricImporter::Strategies::ExplicitAbrogationRegulation.new(delete_xml) }
it 'calls Sequel record deletion by default' do
- db_stub, filter_stub, destroy_stub = stub(), stub(), stub()
- ExplicitAbrogationRegulation.expects(:db).returns(db_stub)
- db_stub.expects(:[]).returns(filter_stub)
- filter_stub.expects(:filter).returns(destroy_stub)
+ destroy_stub = stub()
+ ExplicitAbrogationRegulation.expects(:filter).returns(destroy_stub)
destroy_stub.expects(:delete).returns(true)
subject.process!
View
15 spec/unit/tariff_importer/importers/taric_importer_spec.rb
@@ -59,12 +59,9 @@
}
it 'processes updates' do
- # update_record.xml is inserting to ExplicitAbrogationRegulation
-
- db_stub, filter_stub, update_stub = stub(), stub(), stub()
- ExplicitAbrogationRegulation.expects(:db).returns(db_stub)
- db_stub.expects(:[]).returns(filter_stub)
- filter_stub.expects(:filter).with({:explicit_abrogation_regulation_id=>"D1202470", :explicit_abrogation_regulation_role=>"7"}).returns(update_stub)
+ # update_record.xml is updating to ExplicitAbrogationRegulation
+ update_stub = stub()
+ ExplicitAbrogationRegulation.expects(:filter).returns(update_stub)
update_stub.expects(:update).with(expected_attributes).returns(true)
@importer = TaricImporter.new(update_record)
@@ -78,10 +75,8 @@
it 'processes deletions' do
# update_record.xml is inserting to ExplicitAbrogationRegulation
- db_stub, filter_stub, destroy_stub = stub(), stub(), stub()
- ExplicitAbrogationRegulation.expects(:db).returns(db_stub)
- db_stub.expects(:[]).returns(filter_stub)
- filter_stub.expects(:filter).with({:explicit_abrogation_regulation_id=>"D1202470", :explicit_abrogation_regulation_role=>"7"}).returns(destroy_stub)
+ destroy_stub = stub()
+ ExplicitAbrogationRegulation.expects(:filter).with({:explicit_abrogation_regulation_id=>"D1202470", :explicit_abrogation_regulation_role=>"7"}).returns(destroy_stub)
destroy_stub.expects(:delete).returns(true)
@importer = TaricImporter.new(delete_record)
Something went wrong with that request. Please try again.