Sha256: cd6aa8b06abed9e5cefe3f7cc2d751193d57132441e78cfb2aad27a80ada0da2

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe "Node Queries" do
  
  subject { Person }
  
  describe "fetching a node" do
    
    it { should respond_to(:find_by_id) }
    
    it "should find a node based on its id" do
      person = Person.create(:name => 'Agent Smith', :human => false)
      person.persisted?.should be_true
      
      record = Person.find_by_id(person.id)
      record.should be_a(Person)
      record.id.should == person.id
    end
    
    it "should not instatiate the node if it is of the wrong type" do
      ship = Ship.create(:name => 'Brahama', :crew_size => 1)
      Person.find_by_id(ship.id).should be_nil
    end
    
    it "should return nil when the node is not found" do
      Person.find_by_id(-1).should be_nil
    end
    
    it "should raise an exception when banged finder is used an no record found" do
      lambda { Person.find_by_id!(-1) }.should raise_error(Architect4r::RecordNotFound)
    end
    
    it "should not raise an exception when banged finder is used an a record is found" do
      person = Person.create(:name => 'The Architect', :human => false)
      lambda { Person.find_by_id!(person.id) }.should_not raise_error(Architect4r::RecordNotFound)
    end
    
  end
  
  describe "counting records" do
    
    it "should count the number of records" do
      Person.create(:name => 'Neo', :human => true)
      Person.create(:name => 'Trinity', :human => true)
      Person.count.should >= 2
    end
    
  end
  
  describe "custom cypher queries" do
    
    it "should only return the first two records" do
      Person.create(:name => 'Neo', :human => true)
      Person.create(:name => 'Trinity', :human => true)
      Person.create(:name => 'Morpheus', :human => true)
      results = Person.find_by_cypher("start s=node(:person_root) match s<-[:model_type]-d return d limit 2", 'd')
      results.size.should == 2
      results.first.should be_a(Person)
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
architect4r-0.3.4.2 spec/model/queries_spec.rb
architect4r-0.3.4.1 spec/model/queries_spec.rb
architect4r-0.3.4 spec/model/queries_spec.rb