Sha256: faa1d8a1b6e50a980fc569b22b5767ed55575b7fb06229cdd6637c07dc6434fe

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

describe "base" do
  it "should define the id method" do
    Post.new.should.respond_to :id
  end
  
  it "should set new_record to true when calling new" do
    Post.new.should.be.new_record
  end
  
  it "should set attributes when given a hash in new" do
    post = Post.new(:text => 'hello')
    post.text.should == 'hello'
  end
  
  describe "instantiate" do
    it "should raise an exception if no ID is given" do
      lambda { Shape.instantiate({}) }.should.raise(ArgumentError)
    end
    
    it "should instantiate concrete type if given in json" do
      shape = Shape.instantiate(:id => 1, :type => 'Rectangle')
      shape.should.is_a Rectangle
    end
    
    it "should instantiate base type if concrete type does not exist" do
      shape = Shape.instantiate(:id => 2, :type => 'FuzzyCircle')
      shape.should.is_a Shape
    end
    
    it "should instantiate base type if no type given in json" do
      shape = Shape.instantiate(:id => 3)
      shape.should.is_a Shape
      shape.should.not.is_a Rectangle
    end
    
    it "should set new_record to false" do
      shape = Shape.instantiate(:id => 4)
      shape.should.not.be.new_record
    end
    
    it "should remember instance" do
      Shape.recall(5).should.be.nil
      shape = Shape.instantiate(:id => 5)
      Shape.recall(5).should.not.be.nil
    end
    
    it "should update existing instance" do
      shape1 = Shape.instantiate(:id => 6, :contents => 'nothing')
      shape2 = Shape.instantiate(:id => 6, :contents => 'something')
      shape1.should.be.identical_to shape2
      shape1.contents.should == 'something'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
motion-resource-0.1.2 spec/motion-resource/base_spec.rb
motion-resource-0.1.1 spec/motion-resource/base_spec.rb
motion-resource-0.0.1 spec/motion-resource/base_spec.rb