Sha256: 39e25946d6d604f094476cde1f0b98c3031e92e576878f2f0b5ac225f65a60fb
Contents?: true
Size: 1.67 KB
Versions: 4
Compression:
Stored size: 1.67 KB
Contents
describe "Associations" do class Todo < NanoStore::Model attribute :title bag :items end class TodoItem < NanoStore::Model attribute :completed attribute :text end before do NanoStore.shared_store = NanoStore.store end after do NanoStore.shared_store = nil end describe "#bag" do it "adds a reader to the class" do todo = Todo.create(:title => "Today Tasks") todo.items.is_a?(NanoStore::Bag).should == true todo.items.size.should == 0 end it "adds a writer to the class that can take an array" do todo = Todo.create(:title => "Today Tasks") todo.items = [TodoItem.new(:text => "Hi"), TodoItem.new(:text => "Foo"), TodoItem.new(:text => "Bar")] todo.items.is_a?(NanoStore::Bag).should == true todo.items.size.should == 3 end it "adds a writer to the class that can take a Bag" do todo = Todo.create(:title => "Today Tasks") todo.items = NanoStore::Bag.bag todo.items.is_a?(NanoStore::Bag).should == true todo.items.size.should == 0 end end describe "#save" do it "save a model also save associated fields" do todo = Todo.create(:title => "Today Tasks") todo.items = [TodoItem.new(:text => "Hi"), TodoItem.new(:text => "Foo"), TodoItem.new(:text => "Bar")] todo.items.is_a?(NanoStore::Bag).should == true todo.save todo = Todo.find(:title => "Today Tasks").first todo.should.not.be.nil todo.items.is_a?(NanoStore::Bag).should == true todo.items.key.should == todo.items.key todo.items.size.should == 3 todo.items.to_a.each do |item| item.is_a?(TodoItem).should.be.true end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
nano-store-0.6.3 | spec/association_spec.rb |
nano-store-0.6.2 | spec/association_spec.rb |
nano-store-0.6.1 | spec/association_spec.rb |
nano-store-0.6.0 | spec/association_spec.rb |