|
94 | 94 | end |
95 | 95 |
|
96 | 96 | it 'uses created_at if it exists and has no null values' do |
97 | | - Candidate.create!(id: 1, email_address: 'first@example.com') |
98 | | - Candidate.create!(id: 2, email_address: 'second@example.com') |
| 97 | + Candidate.create!(id: 1, email_address: 'first@example.com', created_at: 2.days.ago, updated_at: 2.days.ago) |
| 98 | + Candidate.create!(id: 2, email_address: 'second@example.com', created_at: 1.day.ago, updated_at: 1.day.ago) |
99 | 99 |
|
100 | | - table_ids = Candidate.order(:created_at).pluck(:id) |
| 100 | + table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(:created_at).pluck(:id) |
101 | 101 | checksum = Digest::MD5.hexdigest(table_ids.join) |
102 | 102 |
|
103 | 103 | described_class.call(entity_name: candidate_entity, entity_type: entity_type, entity_tag: nil) |
|
139 | 139 | end |
140 | 140 |
|
141 | 141 | it 'defaults to created_at when updated_at is null but created_at exists' do |
142 | | - Candidate.create!(id: 1, email_address: 'first@example.com', updated_at: nil, created_at: 2.hours.ago) |
143 | | - Candidate.create!(id: 2, email_address: 'second@example.com', updated_at: nil, created_at: 1.hour.ago) |
144 | | - Candidate.create!(id: 3, email_address: 'third@example.com', updated_at: nil, created_at: 3.hours.ago) |
| 142 | + cutoff = Time.zone.parse(checksum_calculated_at) |
| 143 | + |
| 144 | + Candidate.create!(id: 1, email_address: 'first@example.com', updated_at: nil, created_at: cutoff - 3.hours) |
| 145 | + Candidate.create!(id: 2, email_address: 'second@example.com', updated_at: nil, created_at: cutoff - 2.hours) |
| 146 | + Candidate.create!(id: 3, email_address: 'third@example.com', updated_at: nil, created_at: cutoff - 1.hour) |
145 | 147 |
|
146 | 148 | # Ensure updated_at is not nil |
147 | | - Candidate.update_all(updated_at: Time.now) |
| 149 | + Candidate.update_all(updated_at: cutoff - 30.minutes) |
148 | 150 |
|
149 | | - table_ids = Candidate.order(:created_at).pluck(:id) |
| 151 | + table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(:created_at).pluck(:id) |
150 | 152 | checksum = Digest::MD5.hexdigest(table_ids.join) |
151 | 153 |
|
152 | 154 | described_class.call(entity_name: candidate_entity, entity_type: entity_type, entity_tag: nil) |
|
166 | 168 | order_column = 'CREATED_AT' |
167 | 169 | [123, 124, 125].map { |id| Application.create(id: id) } |
168 | 170 | application_entities = DfE::Analytics.entities_for_analytics.select { |entity| entity.to_s.include?('application') } |
169 | | - table_ids = Application.where('created_at < ?', checksum_calculated_at).order(created_at: :asc).pluck(:id) |
| 171 | + table_ids = Application.where('created_at < ?', checksum_calculated_at).order(:created_at).pluck(:id) |
170 | 172 | checksum = Digest::MD5.hexdigest(table_ids.join) |
171 | 173 |
|
172 | 174 | application_entities.each do |application| |
|
186 | 188 | it 'sends an entity table check event' do |
187 | 189 | [130, 131, 132].map { |id| Candidate.create(id: id) } |
188 | 190 | candidate_entities = DfE::Analytics.entities_for_analytics.select { |entity| entity.to_s.include?('candidate') } |
189 | | - table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(created_at: :asc).pluck(:id) |
| 191 | + table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(:created_at).pluck(:id) |
190 | 192 | checksum = Digest::MD5.hexdigest(table_ids.join) |
191 | 193 |
|
192 | 194 | candidate_entities.each do |candidate| |
|
211 | 213 |
|
212 | 214 | Candidate.update_all(created_at: DateTime.parse(checksum_calculated_at) - 1.hour) |
213 | 215 |
|
214 | | - table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(:updated_at).pluck(:id) |
| 216 | + table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(:created_at).pluck(:id) |
215 | 217 | checksum = Digest::MD5.hexdigest(table_ids.join) |
216 | 218 |
|
217 | 219 | described_class.call(entity_name: candidate_entity, entity_type: entity_type, entity_tag: nil) |
|
228 | 230 | end |
229 | 231 |
|
230 | 232 | it 'returns zero rows and checksum if table is empty' do |
231 | | - table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(created_at: :asc).pluck(:id) |
| 233 | + table_ids = Candidate.where('created_at < ?', checksum_calculated_at).order(:created_at).pluck(:id) |
232 | 234 | checksum = Digest::MD5.hexdigest(table_ids.join) |
233 | 235 | described_class.call(entity_name: candidate_entity, entity_type: entity_type, entity_tag: nil) |
234 | 236 |
|
|
0 commit comments