Sha256: 2a4dff4019069f2fc65845eb5905d3884e7fc587ebf67dea19724222abbc2fb0

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

describe "Associations" do
   before do
    MotionPrime::Store.connect
  end

  after do
    MotionPrime::Store.shared_store.clear
  end

  describe "#bag" do
    it "adds a attr reader to the class" do
      todo = Todo.create(:title => "Today Tasks")
      todo.items.is_a?(MotionPrime::Bag).should == true
      todo.items.size.should == 0
    end

    it "adds a attr 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?(MotionPrime::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 = MotionPrime::Bag.bag
      todo.items.is_a?(MotionPrime::Bag).should == true
      todo.items.size.should == 0
    end
  end

  describe "#save" do
    it "save a model also saves associated bags" 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?(MotionPrime::Bag).should == true
      todo.save

      todo = Todo.find(:title => "Today Tasks").first
      todo.should.not.be.nil
      todo.items.is_a?(MotionPrime::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

7 entries across 7 versions & 1 rubygems

Version Path
motion-prime-0.1.7 spec/models/association_spec.rb
motion-prime-0.1.6 spec/models/association_spec.rb
motion-prime-0.1.5 spec/models/association_spec.rb
motion-prime-0.1.4 spec/models/association_spec.rb
motion-prime-0.1.3 spec/models/association_spec.rb
motion-prime-0.1.2 spec/models/association_spec.rb
motion-prime-0.1.1 spec/models/association_spec.rb