summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2017-04-10 02:05:09 +0000
committerbrian m. carlson <sandals@crustytoothpaste.net>2017-04-10 02:05:09 +0000
commitb50dd2f2d75235124b157d8e870833afece301c8 (patch)
tree437deb5a94ffbcf3f1686ac133b4daee814b6cf7
parent60acae460444cba42a7c4ac92614c9173705868e (diff)
spec: add spec for consistent IDs
Add a spec to verify that we produce consistent IDs. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
-rw-r--r--spec/comic_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/comic_spec.rb b/spec/comic_spec.rb
index 759fdee..91d19ad 100644
--- a/spec/comic_spec.rb
+++ b/spec/comic_spec.rb
@@ -22,4 +22,28 @@ describe Comics::Comic do
expect(entry.date('%FT%T')).to eq expected
end
end
+
+ it 'produces consistent IDs for entries based on timestamp' do
+ entry_pairs = []
+ [
+ [Time.new(2017, 4, 4, 11, 0, 0, 0),
+ '0c093ce5524e932ce3d72bb67c848ed5afedf40cc929ed581d2d0cab381193c4'],
+ # If the time hasn't happened yet, then use the previous date.
+ [Time.new(2017, 4, 4, 13, 0, 0, 0),
+ 'f2a54d85608e91ca4cc029d9b90ebdda48531a749e9424a7d93f525877c0b06a'],
+ ].each do |(stamp, expected)|
+ allow(Time).to receive(:now) { stamp }
+ c = config.comic('dilbert')
+ entry = c.first
+ expect(entry.id).to match(
+ /\Atag:sandals@crustytoothpaste.net,2013:urn:sha256:id:([0-9a-f]{64})/
+ )
+ expect(entry.id).to end_with expected
+ entry_pairs << c.map { |e| [e.date, e.id] }
+ end
+ # Verify that the entries are consistent between the items generated on two
+ # different days. Ignore the oldest and most recent entries, since those
+ # will not overlap between the two days.
+ expect(entry_pairs[0][0..-2]).to eq entry_pairs[1][1..-1]
+ end
end