Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Measure change feeds does not return proactively added measures

In other words: if I'm querying for commodity changes on 31st of Jan,
I should not be seeing Measures that were added on 24th of Jan but have
validity start date of 1st of Feb. Showing these causes issues with
associations like measure type, because we expect measure type of such
measure to be valid at query date (31st of Jan) and if they were
introduced at the same time that is not the case (also has validity
start date of 1st of Feb).
  • Loading branch information...
commit 4993a0429e8b1c27639114c763d4756cfb5096fe 1 parent e960dc7
@saulius saulius authored
View
8 app/models/commodity.rb
@@ -143,13 +143,17 @@ def changes(depth = 1)
:operation,
Sequel.as(depth, :depth)
).where(pk_hash)
- .union(Measure.changes_for(depth + 1, Sequel.qualify(:measures_oplog, :goods_nomenclature_item_id) => goods_nomenclature_item_id))
+ .union(
+ Measure.changes_for(
+ depth + 1,
+ Sequel.qualify(:measures_oplog, :goods_nomenclature_item_id) => goods_nomenclature_item_id)
+ )
.from_self
.where(Sequel.~(operation_date: nil))
.tap! { |criteria|
# if Commodity did not come from initial seed, filter by its
# create/update date
- criteria.where{ |o| o.>=(:operation_date, operation_date) } unless operation_date.blank?
+ criteria.where { |o| o.>=(:operation_date, operation_date) } unless operation_date.blank?
}
.limit(TradeTariffBackend.change_count)
.order(Sequel.function(:isnull, :operation_date), Sequel.desc(:operation_date), Sequel.desc(:depth))
View
1  app/models/measure.rb
@@ -347,6 +347,7 @@ def self.changes_for(depth = 1, conditions = {})
:operation,
Sequel.as(depth, :depth)
).where(conditions)
+ .where { |o| o.<=(:validity_start_date, point_in_time) }
.limit(TradeTariffBackend.change_count)
.order(Sequel.function(:isnull, :operation_date), Sequel.desc(:operation_date))
end
View
2  app/views/api/v1/changes/changes.json.rabl
@@ -1,6 +1,6 @@
collection @changes
-attributes :oid, :model_name, :operation_date, :operation
+attributes :oid, :model_name, :operation, :operation_date
node(:record) { |change|
partial "api/v1/#{change.to_partial_path}", object: change.record
View
23 spec/models/measure_spec.rb
@@ -936,4 +936,27 @@
end
end
end
+
+ describe '.changes_for' do
+ context 'measure validity start date lower than requested date' do
+ let!(:measure) { create :measure, validity_start_date: Date.new(2014,2,1) }
+
+ it 'incudes measure' do
+ TimeMachine.at(Date.new(2014,1,30)) do
+ expect(Measure.changes_for).to be_empty
+ end
+ end
+ end
+
+ context 'measure validity start date higher than requested date' do
+ let!(:measure) { create :measure, validity_start_date: Date.new(2014,2,1) }
+
+ it 'does not include measure' do
+ TimeMachine.at(Date.new(2014,2,1)) do
+ expect(Measure.changes_for).not_to be_empty
+ expect(Measure.changes_for.first.oid).to eq measure.source.oid
+ end
+ end
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.