Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #142 from alphagov/64645912-hide-proactively-intro…

…duced-measures

Measure change feeds does not return proactively added measures
  • Loading branch information...
commit 59e968cd2561e60ac4415d5ded1e44bfb64e2196 2 parents e960dc7 + 4993a04
@matthewford matthewford 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.