<commit_before># -*- encoding : utf-8 -*-
require File.expand_path(File.join(File.dirname(__FILE__),"../helper"))

describe Splash::Namespace do
  
  it "should derefence correctly" do
    
    class Something
      
      include Splash::Document
      
      attribute "name"
      
    end
    
    
    a = Something.new('name'=>'A').store!
    ['b','c','d','e','f'].each do |c|
      
      Something.new('name'=>c).store!
      
    end
    z = Something.new('name'=>'Z').store!
    
    
    
    
    Something.namespace.dereference(BSON::DBRef.new(Something.collection.name , a._id)).should == a
    
    
    Something.namespace.dereference(BSON::DBRef.new(Something.collection.name , z._id)).should == z
    
  end
  
  
  it "should get the correct class, right from the start" do
    
    class Brxlwupf
      
      include Splash::HasCollection
      
    end
    
    Brxlwupf.namespace.class_for('brxlwupf').should == Brxlwupf
    
    
    
  end
  
  describe "naming" do
    
    it "should convert class to collection names" do
      
      ns = Splash::Namespace.default
      
      ns.class_to_collection_name("Consultant").should == "consultant"
      
      ns.class_to_collection_name("FinanceEnquiry").should == "finance_enquiry"
      
      ns.class_to_collection_name("Notification::Request").should == "notification.request"
      
      
    end
    
    
  end<commit_msg>Added a spec for namespace#dereference<commit_after># -*- encoding : utf-8 -*-
require File.expand_path(File.join(File.dirname(__FILE__),"../helper"))

describe Splash::Namespace do
  
  it "should derefence correctly" do
    
    class Something
      
      include Splash::Document
      
      attribute "name"
      
    end
    
    
    a = Something.new('name'=>'A').store!
    ['b','c','d','e','f'].each do |c|
      
      Something.new('name'=>c).store!
      
    end
    z = Something.new('name'=>'Z').store!
    
    
    
    
    Something.namespace.dereference(BSON::DBRef.new(Something.collection.name , a._id)).should == a
    
    
    Something.namespace.dereference(BSON::DBRef.new(Something.collection.name , z._id)).should == z
    
  end
  
  
  it "should get the correct class, right from the start" do
    
    class Brxlwupf
      
      include Splash::HasCollection
      
    end
    
    Brxlwupf.namespace.class_for('brxlwupf').should == Brxlwupf
    
  end
  
  it "should dereference correctly, even when the class has not yet accessed the collection" do
    
    
    c = Splash::Namespace.default.collection('brxlwopf')
    id = c.insert({
      'name' =>'Hallowed'
    })
    
    class Brxlwopf
      
      include Splash::Document
      
      attribute "name"
      
    end
    
    found = Splash::Namespace.default.dereference(BSON::DBRef.new('brxlwopf',id))
    found.should be_a(Brxlwopf)
    found.name.should == 'Hallowed'
    
  end
  
  describe "naming" do
    
    it "should convert class to collection names" do
      
      ns = Splash::Namespace.default
      
      ns.class_to_collection_name("Consultant").should == "consultant"
      
      ns.class_to_collection_name("FinanceEnquiry").should == "finance_enquiry"
      
      ns.class_to_collection_name("Notification::Request").should == "notification.request"
      
      
    end
    
    
  end
{'fraction_non_alphanumeric': 0.12081952395299789, 'fraction_numerical': 0.0006025911419102139, 'mean_word_length': 2.2453567937438903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798531', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1056, 'n_words': 190}