Sha256: 480bae143df5766ac7a3e2cdd58b4a3ca43d48e09bd9635d0722637da8f82f74

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

class Plant
  include CouchPotato::Persistence
  property :leaf_count
end

describe "attributes" do
  
  describe 'attributes=' do
    it "should assign the attributes" do
      plant = Plant.new 
      plant.attributes = {:leaf_count => 1}
      plant.leaf_count.should == 1
    end
  end

  describe "attributes" do
    it "should return the attributes" do
      plant = Plant.new(:leaf_count => 1)
      plant.attributes.should == {:leaf_count => 1, :created_at => nil, :updated_at => nil}
    end
  end
  
  # useful when loading models from custom views
  describe "accessing non-property attributes" do
    it "should allow me to access attributes that are in the couchdb document " do
      plant = Plant.json_create({"ruby_class" => "Plant", "color" => "red", "leaf_count" => 1})
      plant.color.should == 'red'
    end
    
    it "should raise a no method error when trying to read attributes that are not in the document" do
      plant = Plant.json_create({"ruby_class" => "Plant", "leaf_count" => 1})
      lambda do
        plant.length
      end.should raise_error(NoMethodError)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
langalex-couch_potato-0.2.9 spec/unit/attributes_spec.rb