Sha256: 1be5e14900b01da7c1b7a943612a044339aabf6f9e794f46f93e348e0380efd5

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 KB

Contents

describe "attributes" do
  it "should define reader per attribute" do
    Shape.new.should.respond_to :contents
  end
  
  it "should define writer per attribute" do
    Shape.new.should.respond_to :contents=
  end
  
  it "should duplicate array in setter" do
    contents = ['hello']
    shape = Shape.new
    shape.contents = contents
    shape.contents.object_id.should != contents.object_id
  end
  
  it "should duplicate hash in setter" do
    contents = { :foo => 'bar' }
    shape = Shape.new
    shape.contents = contents
    shape.contents.should.not.be.identical_to contents
  end
  
  it "should behave regularly for other values in setter" do
    shape = Shape.new
    shape.contents = "hello"
    shape.contents.should == "hello"
  end
  
  it "should store attribute names in accessor" do
    Shape.attributes.should.include :contents
  end
  
  it "should inherit attribute names from parent class" do
    Rectangle.attributes.should.include :contents
    Rectangle.attributes.should.include :size
  end
  
  it "should get hash of all attributes from instance" do
    shape = Shape.new
    shape.contents = "hello"
    shape.attributes[:contents].should == "hello"
  end
  
  describe "update_attributes" do
    it "should set attr_accessors" do
      time = Time.now
      shape = Shape.new
      shape.update_attributes(:created_at => time)
      shape.created_at.should == time
    end
    
    it "should set attributes" do
      shape = Shape.new
      shape.update_attributes(:position => "10,10")
      shape.position.should == "10,10"
    end
    
    it "should not crash when updating an unknown attribute" do
      shape = Shape.new
      lambda { shape.update_attributes(:foo => 'bar') }.should.not.raise
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
motion-resource-0.1.4 spec/motion-resource/attributes_spec.rb
motion-resource-0.1.3 spec/motion-resource/attributes_spec.rb
motion-resource-0.1.2 spec/motion-resource/attributes_spec.rb
motion-resource-0.1.1 spec/motion-resource/attributes_spec.rb
motion-resource-0.1.0 spec/motion-resource/attributes_spec.rb
motion-resource-0.0.2 spec/motion-resource/attributes_spec.rb
motion-resource-0.0.1 spec/motion-resource/attributes_spec.rb