Sha256: 86038f2c5b5de0e43c57cf1ac31ade8fc351e00589b2cbb163bc004c7503e089
Contents?: true
Size: 1.65 KB
Versions: 2
Compression:
Stored size: 1.65 KB
Contents
require 'helper' describe Toy::Identity do uses_constants('User', 'Piece') describe "setting the key" do it "should set key factory to UUIDKeyFactory" do User.key(:uuid).should be_instance_of(Toy::Identity::UUIDKeyFactory) end it "should use ObjectIdKeyFactory if :object_id" do User.key(:object_id).should be_instance_of(Toy::Identity::ObjectIdKeyFactory) end it "should set key factory passed in factory" do factory = Toy::Identity::UUIDKeyFactory.new User.key(factory).should == factory end it "should use Toy.key_factory by default" do key_factory = Toy::Identity::UUIDKeyFactory.new Toy.key_factory = key_factory klass = Class.new { include Toy::Store } key_factory.should_receive(:next_key).and_return('some_key') klass.next_key Toy.key_factory = nil end end describe ".next_key" do it "should call the next key on the key factory" do factory = Toy::Identity::UUIDKeyFactory.new factory.should_receive(:next_key).and_return('some_key') User.key(factory) User.next_key.should == 'some_key' end it "should raise an exception for nil key" do factory = Toy::Identity::UUIDKeyFactory.new factory.should_receive(:next_key).and_return(nil) User.key(factory) lambda { User.next_key }.should raise_error end end describe "initializing the id" do it "should pass use pass the new object" do Piece.attribute(:name, String) Piece.attribute(:number, Integer) Piece.key(NameAndNumberKeyFactory.new) Piece.new(:name => 'Rook', :number => 1).id.should == 'Rook-1' end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
toystore-0.6.3 | spec/toy/identity_spec.rb |
toystore-0.6.2 | spec/toy/identity_spec.rb |