Permalink
Browse files

Override native uuid to use guid for #to_key.

  • Loading branch information...
1 parent 3cb3dfe commit c02fa41e1e536baea5903cb130b1092825adeae1 @jnunemaker committed Nov 16, 2012
Showing with 20 additions and 0 deletions.
  1. +4 −0 lib/toy/identity/native_uuid_key_factory.rb
  2. +16 −0 spec/toy/object_spec.rb
View
4 lib/toy/identity/native_uuid_key_factory.rb
@@ -8,6 +8,10 @@ def key_type
def next_key(object)
SimpleUUID::UUID.new
end
+
+ def to_key(object)
+ [object.id.to_guid] if object.persisted?
+ end
end
end
end
View
16 spec/toy/object_spec.rb
@@ -35,6 +35,22 @@
it "returns nil if not persisted" do
User.new.to_key.should be_nil
end
+
+ context "with native uuid" do
+ before do
+ User.key :native_uuid
+ end
+
+ it "returns array with guid if persisted" do
+ user = User.new
+ user.stub(:persisted?).and_return(true)
+ user.to_key.should == [user.id.to_guid]
+ end
+
+ it "returns nil if not persisted" do
+ User.new.to_key.should be_nil
+ end
+ end
end
describe "#to_param" do

0 comments on commit c02fa41

Please sign in to comment.