lapis-common 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lapis/uuid.rb +1 -1
- data/lib/lapis/version.rb +1 -1
- data/spec/factories/uuid_factory.rb +3 -3
- data/spec/lapis/uuid_spec.rb +23 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1679496db3f2c1ebd08176c885f972d39a2bf299
|
4
|
+
data.tar.gz: db84544ca727992e10b80116b8add44c21d37555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f6b9359296e663cf3e06927ce623325ba27653f07a0e1b825fd7e90ed953952f19de1c7c0c41431c148b54409fafcbb9e2f4f36ca03533f43b54152aa285972
|
7
|
+
data.tar.gz: b4cf97edc59983d333c1545a51bca30b0003139535b9388a6ca0ff312c0b110af094b07a57586c2c406ffde7fe85563db20166d6455ad56a8a8e55ef1aab82cd
|
data/lib/lapis/uuid.rb
CHANGED
@@ -52,7 +52,7 @@ module Lapis
|
|
52
52
|
if uuid_str.is_a? String
|
53
53
|
# Check the formatting.
|
54
54
|
# Note that the validity of the UUID isn't checked.
|
55
|
-
|
55
|
+
!!/^\A[0-9a-f]{8}(-?)[0-9a-f]{4}\1[0-9a-f]{4}\1[0-9a-f]{4}\1[0-9a-f]{12}\z$/i.match(uuid_str)
|
56
56
|
else
|
57
57
|
# A string wasn't passed in.
|
58
58
|
fail ArgumentError
|
data/lib/lapis/version.rb
CHANGED
@@ -14,10 +14,10 @@ FactoryGirl.define do
|
|
14
14
|
|
15
15
|
factory :uuid_value, class: String do
|
16
16
|
transient do
|
17
|
-
association :uuid_str, :strategy => :build
|
17
|
+
association :source, :factory => :uuid_str, :strategy => :build
|
18
18
|
end
|
19
19
|
|
20
|
-
initialize_with {
|
20
|
+
initialize_with { source.delete('-').scan(/../).map(&:hex).pack('C*') }
|
21
21
|
end
|
22
22
|
|
23
23
|
factory :uuid, class: Lapis::Uuid do
|
@@ -35,7 +35,7 @@ FactoryGirl.define do
|
|
35
35
|
if source.length == 16
|
36
36
|
Lapis::Uuid.new(source)
|
37
37
|
else
|
38
|
-
Lapis::Uuid.new(build(:uuid_value, :
|
38
|
+
Lapis::Uuid.new(build(:uuid_value, :source => source))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/spec/lapis/uuid_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
|
|
2
2
|
|
3
3
|
RSpec::Matchers.define :be_a_valid_uuid_string do
|
4
4
|
match do |actual|
|
5
|
-
|
5
|
+
!!/^\A[0-9a-f]{8}(-?)[0-9a-f]{4}\1[1-5][0-9a-f]{3}\1[89ab][0-9a-f]{3}\1[0-9a-f]{12}\z$/i.match(actual)
|
6
6
|
end
|
7
7
|
|
8
8
|
description do
|
@@ -32,7 +32,7 @@ RSpec.describe Lapis::Uuid do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe '#
|
35
|
+
describe '#initialize' do
|
36
36
|
context 'with a valid value' do
|
37
37
|
let(:uuid_value) { build(:uuid_value) }
|
38
38
|
subject(:uuid) { Lapis::Uuid.new(uuid_value) }
|
@@ -55,11 +55,10 @@ RSpec.describe Lapis::Uuid do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
describe '.generate' do
|
59
59
|
subject(:uuid) { Lapis::Uuid.generate }
|
60
60
|
|
61
61
|
describe 'the value' do
|
62
|
-
let(:other) { build(:uuid) }
|
63
62
|
subject { uuid.value }
|
64
63
|
|
65
64
|
# The UUID standards don't allow generated UUID to be all zeroes.
|
@@ -69,6 +68,7 @@ RSpec.describe Lapis::Uuid do
|
|
69
68
|
|
70
69
|
# The chances of two randomly generated UUIDs being identical is virtually impossible.
|
71
70
|
it 'is random' do
|
71
|
+
other = build(:uuid)
|
72
72
|
is_expected.to_not eq other
|
73
73
|
end
|
74
74
|
end
|
@@ -83,12 +83,15 @@ RSpec.describe Lapis::Uuid do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
describe '.parse' do
|
86
|
-
let(:uuid_str) { build(:uuid_str) }
|
87
86
|
subject { Lapis::Uuid.parse(uuid_str) }
|
88
87
|
|
89
|
-
context 'with a valid
|
90
|
-
|
91
|
-
|
88
|
+
context 'with a valid argument' do
|
89
|
+
context 'with dashes' do
|
90
|
+
let(:uuid_str) { build(:uuid_str) }
|
91
|
+
|
92
|
+
it 'parses correctly' do
|
93
|
+
is_expected.to eq uuid_str
|
94
|
+
end
|
92
95
|
end
|
93
96
|
|
94
97
|
context 'without dashes' do
|
@@ -115,6 +118,14 @@ RSpec.describe Lapis::Uuid do
|
|
115
118
|
expect { subject }.to raise_error(ArgumentError)
|
116
119
|
end
|
117
120
|
end
|
121
|
+
|
122
|
+
context 'with newlines' do
|
123
|
+
let(:uuid_str) { "\n" + build(:uuid_str) + "\n" }
|
124
|
+
|
125
|
+
it 'returns nil' do
|
126
|
+
is_expected.to be_nil
|
127
|
+
end
|
128
|
+
end
|
118
129
|
end
|
119
130
|
|
120
131
|
describe '#value' do
|
@@ -129,12 +140,8 @@ RSpec.describe Lapis::Uuid do
|
|
129
140
|
is_expected.to be_frozen
|
130
141
|
end
|
131
142
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
it 'is 16 bytes' do
|
136
|
-
is_expected.to be 16
|
137
|
-
end
|
143
|
+
it 'is 16 bytes' do
|
144
|
+
expect(value.length).to be 16
|
138
145
|
end
|
139
146
|
end
|
140
147
|
|
@@ -306,7 +313,7 @@ RSpec.describe Lapis::Uuid do
|
|
306
313
|
|
307
314
|
context 'with a lesser value' do
|
308
315
|
let(:first) { build(:uuid, :source => greater) }
|
309
|
-
let(:second) { build(:uuid_value, :
|
316
|
+
let(:second) { build(:uuid_value, :source => lesser) }
|
310
317
|
|
311
318
|
it 'is 1' do
|
312
319
|
is_expected.to eq 1
|
@@ -315,7 +322,7 @@ RSpec.describe Lapis::Uuid do
|
|
315
322
|
|
316
323
|
context 'with a greater value' do
|
317
324
|
let(:first) { build(:uuid, :source => lesser) }
|
318
|
-
let(:second) { build(:uuid_value, :
|
325
|
+
let(:second) { build(:uuid_value, :source => greater) }
|
319
326
|
|
320
327
|
it 'is -1' do
|
321
328
|
is_expected.to eq(-1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lapis-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|