Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure uuid returns self if already a uuid.

  • Loading branch information...
commit 2d5b932667ee8ac1374405882d755b568ff65972 1 parent 0e3b466
@jnunemaker authored
Showing with 16 additions and 4 deletions.
  1. +2 −0  lib/toy/extensions/uuid.rb
  2. +14 −4 spec/toy/extensions/uuid_spec.rb
View
2  lib/toy/extensions/uuid.rb
@@ -2,10 +2,12 @@ module Toy
module Extensions
module UUID
def to_store(value, *)
+ return value if value.is_a?(SimpleUUID::UUID)
SimpleUUID::UUID.new(value)
end
def from_store(value, *)
+ return value if value.is_a?(SimpleUUID::UUID)
SimpleUUID::UUID.new(value)
end
end
View
18 spec/toy/extensions/uuid_spec.rb
@@ -1,18 +1,28 @@
require 'helper'
describe "SimpleUUID::UUID.to_store" do
- it "should convert value to uuid" do
+ it "returns value if value is already uuid" do
uuid = SimpleUUID::UUID.new
- [uuid, uuid.to_guid, uuid.to_s, uuid.to_i].each do |value|
+ SimpleUUID::UUID.to_store(uuid).should be(uuid)
+ end
+
+ it "converts value to uuid if not already uuid" do
+ uuid = SimpleUUID::UUID.new
+ [uuid.to_guid, uuid.to_s, uuid.to_i].each do |value|
SimpleUUID::UUID.from_store(value).should eq(uuid)
end
end
end
describe "SimpleUUID::UUID.from_store" do
- it "should convert value to uuid" do
+ it "returns value if value is already uuid" do
+ uuid = SimpleUUID::UUID.new
+ SimpleUUID::UUID.from_store(uuid).should be(uuid)
+ end
+
+ it "converts value to uuid if not already uuid" do
uuid = SimpleUUID::UUID.new
- [uuid, uuid.to_guid, uuid.to_s, uuid.to_i].each do |value|
+ [uuid.to_guid, uuid.to_s, uuid.to_i].each do |value|
SimpleUUID::UUID.from_store(value).should eq(uuid)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.