Sha256: bbec714e3544f37ae8e0114c4b0abbe088a8750315f40ac20a8bbc0822a511a1

Contents?: true

Size: 1.36 KB

Versions: 41

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

module MongoModel
  specs_for(Document, EmbeddedDocument) do
    define_class(:TestDocument, described_class) do
      property :foo, String
    end
    
    subject { TestDocument.new(:foo => 'value of foo', :bar => 'value of bar') }
    
    describe "#read_attribute" do
      context "valid property" do
        it "should return the attribute value" do
          subject.read_attribute(:foo).should == 'value of foo'
        end
        
        it "should define a reader method" do
          subject.foo.should == 'value of foo'
        end
      end
      
      context "no property" do
        it "should return the attribute value" do
          subject.read_attribute(:bar).should == 'value of bar'
        end
        
        it "should not define a reader method" do
          lambda { subject.bar }.should raise_error(NoMethodError)
        end
      end
    end
    
    describe "#[]" do
      it "should read the given attribute" do
        subject.should_receive(:read_attribute).with(:foo).and_return('value of foo')
        subject[:foo].should == 'value of foo'
      end
    end
  end
  
  specs_for(Document) do
    define_class(:TestDocument, Document)
    
    subject { TestDocument.new }
    
    describe "#id" do
      it "should return id from attributes" do
        subject.id.should == subject.attributes[:id]
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
mongomodel-0.4.6 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.4.5 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.4.4 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.4.3 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.4.2 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.4.1 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.4.0 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.6 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.5 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.4 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.3 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.2 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.1 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.3.0 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.2.20 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.2.19 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.2.18 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.2.17 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.2.16 spec/mongomodel/concerns/attribute_methods/read_spec.rb
mongomodel-0.2.15 spec/mongomodel/concerns/attribute_methods/read_spec.rb