Sha256: 9b70e39d749e1b29606f32d845c8b45cfc541b725d15b550ecf1d193271c6384

Contents?: true

Size: 1.54 KB

Versions: 34

Compression:

Stored size: 1.54 KB

Contents

describe "Prime::Model 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

34 entries across 34 versions & 1 rubygems

Version Path
motion-prime-0.9.8 spec/unit/models/associations_spec.rb
motion-prime-0.9.7 spec/unit/models/associations_spec.rb
motion-prime-0.9.6 spec/unit/models/associations_spec.rb
motion-prime-0.9.5 spec/unit/models/associations_spec.rb
motion-prime-0.9.4 spec/unit/models/associations_spec.rb
motion-prime-0.9.3 spec/unit/models/associations_spec.rb
motion-prime-0.9.2 spec/unit/models/associations_spec.rb
motion-prime-0.9.1 spec/unit/models/associations_spec.rb
motion-prime-0.9.0 spec/unit/models/associations_spec.rb
motion-prime-0.8.12 spec/models/associations_spec.rb
motion-prime-0.8.11 spec/models/associations_spec.rb
motion-prime-0.8.10 spec/models/associations_spec.rb
motion-prime-0.8.9 spec/models/associations_spec.rb
motion-prime-0.8.8 spec/models/associations_spec.rb
motion-prime-0.8.7 spec/models/associations_spec.rb
motion-prime-0.8.6 spec/models/associations_spec.rb
motion-prime-0.8.5 spec/models/associations_spec.rb
motion-prime-0.8.4 spec/models/associations_spec.rb
motion-prime-0.8.3 spec/models/associations_spec.rb
motion-prime-0.8.2 spec/models/associations_spec.rb