/
uuid_spec.rb
28 lines (22 loc) · 894 Bytes
/
uuid_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require File.expand_path('spec_helper.rb', File.dirname(__FILE__))
include CassandraCQL
describe "UUID" do
it "should respond_to to_guid" do
UUID.new.respond_to?(:to_guid)
end
it "should respond_to to_time" do
UUID.new.respond_to?(:to_time)
end
it "should instantiate from raw bytes" do
UUID.new("\252}\303\374\3137\021\340\237\214\251}\315\351 ]")
end
it "should instantiate from a Time object" do
ts = Time.new
# Nanosecond precision is available on some platforms but not in UUIDv1 so they may not match, just be v.close
# Note that the time returned from two UUIDs using these two timestamps will still be the same
(UUID.new(ts).to_time - ts).should < 0.000001
end
it "should turn have a to_time class method that takes bytes" do
UUID.to_time("\252}\303\374\3137\021\340\237\214\251}\315\351 ]").should be_kind_of(Time)
end
end