Sha256: 5129e2b1ba50d1ed421313c6c939e543c2dff5f14d93d3ea66fce516fc2de5dd

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 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

    it "allows to reload bag" do
      todo = Todo.create(:title => "Today Tasks")
      todo.items = [TodoItem.new(:text => "Hi")]
      todo.items.save
      todo.items << [TodoItem.new(:text => "Foo"), TodoItem.new(:text => "Bar")]
      todo.items.count.should == 3
      todo.items(true).count.should == 1
    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

11 entries across 11 versions & 1 rubygems

Version Path
motion-prime-1.0.7 spec/unit/models/associations_spec.rb
motion-prime-1.0.6 spec/unit/models/associations_spec.rb
motion-prime-1.0.5 spec/unit/models/associations_spec.rb
motion-prime-1.0.4 spec/unit/models/associations_spec.rb
motion-prime-1.0.3 spec/unit/models/associations_spec.rb
motion-prime-1.0.2 spec/unit/models/associations_spec.rb
motion-prime-1.0.1 spec/unit/models/associations_spec.rb
motion-prime-1.0.0 spec/unit/models/associations_spec.rb
motion-prime-0.9.9.2 spec/unit/models/associations_spec.rb
motion-prime-0.9.9.1 spec/unit/models/associations_spec.rb
motion-prime-0.9.9 spec/unit/models/associations_spec.rb