spec/toy/persistence_spec.rb in toystore-0.6.6 vs spec/toy/persistence_spec.rb in toystore-0.7.0

- old
+ new

@@ -34,68 +34,31 @@ klass.store end.should raise_error(StandardError, 'No store has been set') end end - describe ".cache" do - it "sets if arguments and reads if not" do - klass.cache(:memory, {}) - klass.cache.should == Adapter[:memory].new({}) - end - - it "raises argument error if name provided but not client" do - lambda do - klass.cache(:memory) - end.should raise_error(ArgumentError, 'Client is required') - end - - it "raises argument error if no name or client provided and has not been set" do - lambda do - klass.cache - end.should raise_error(StandardError, 'No cache has been set') - end - end - describe ".has_store?" do - it "returns true if cache set" do + it "returns true if store set" do klass.store(:memory, {}) klass.has_store?.should be_true end - it "returns false if cache not set" do + it "returns false if store not set" do klass.has_store?.should be_false end end - describe ".has_cache?" do - it "returns true if cache set" do - klass.cache(:memory, {}) - klass.has_cache?.should be_true - end - - it "returns false if cache not set" do - klass.has_cache?.should be_false - end - end - - describe ".store_key" do - it "returns id" do - doc = User.new - User.store_key(doc.id).should == doc.id - end - end - describe ".create" do before do User.attribute :name, String User.attribute :age, Integer @doc = User.create(:name => 'John', :age => 50) end let(:doc) { @doc } it "creates key in database with attributes" do - User.store.read(doc.store_key).should == { + User.store.read(doc.id).should == { 'name' => 'John', 'age' => 50, } end @@ -154,17 +117,10 @@ it "delegates to class" do User.new.store.should equal(User.store) end end - describe "#store_key" do - it "returns id" do - doc = User.new - doc.store_key.should == doc.id - end - end - describe "#new_record?" do it "returns true if new" do User.new.should be_new_record end @@ -205,35 +161,35 @@ it "saves to key" do User.key?(@doc.id) end it "does not persist virtual attributes" do - @doc.store.read(@doc.store_key).should_not include('accepted_terms') + @doc.store.read(@doc.id).should_not include('accepted_terms') end end context "with existing record" do before do @doc = User.create(:name => 'John', :age => 28) - @key = @doc.store_key - @value = User.store.read(@doc.store_key) + @key = @doc.id + @value = User.store.read(@doc.id) @doc.name = 'Bill' @doc.accepted_terms = false @doc.save end let(:doc) { @doc } it "stores in same key" do - doc.store_key.should == @key + doc.id.should == @key end it "updates value in store" do - User.store.read(doc.store_key).should_not == @value + User.store.read(doc.id).should_not == @value end it "does not persist virtual attributes" do - @doc.store.read(@doc.store_key).should_not include('accepted_terms') + @doc.store.read(@doc.id).should_not include('accepted_terms') end it "updates the attributes in the instance" do doc.name.should == 'Bill' end @@ -278,26 +234,8 @@ it "should be true if deleted" do doc = User.create doc.delete doc.should be_destroyed - end - end - - describe "with cache store" do - before do - User.attribute(:name, String) - @cache = User.cache(:memory, {}) - @memory = User.store(:memory, {}) - @user = User.create(:name => 'John') - end - - let(:cache) { @cache } - let(:memory) { @memory } - let(:user) { @user } - - it "writes to cache and store" do - cache[user.store_key].should == {'name' => 'John'} - memory[user.store_key].should == {'name' => 'John'} end end end \ No newline at end of file