Sha256: 34ff5831a3b34709690a31f34e29dc2ddb3ab04c5caa884d8d4de027c03f73b9

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

module LoadConst
  def const_missing(name)
    name = "#{self.name}::#{name}"
    eval("#{name} = Class.new; #{name}.send(:include, CouchPotato::Persistence); #{name}.extend(LoadConst)")
  end
end

class Autoloader
  extend LoadConst
end

class WithUnloadedEmbedded
  include CouchPotato::Persistence
  extend LoadConst
  
  property :embedded
  
  view :all, :type => :custom, :map => 'function(doc) {emit(doc._id, null)}', :include_docs => true
end


describe CouchPotato::Database, 'rails specific behavior' do
  
  before(:each) do
    recreate_db
  end
  
  context 'load a document' do
    it "should load models whose constants are currently uninitialized (like with rails in development mode)" do
      CouchPotato.couchrest_database.save_doc(JSON.create_id => 'Autoloader::Uninitialized', '_id' => '1')
      expect(CouchPotato.database.load('1').class.name).to eq('Autoloader::Uninitialized')
    end
    
    it "should load nested models" do
      CouchPotato.couchrest_database.save_doc(JSON.create_id => 'Autoloader::Nested::Nested2', '_id' => '1')
      expect(CouchPotato.database.load('1').class.name).to eq('Autoloader::Nested::Nested2')
    end
  end  
  
  context 'load documents using a view' do
    it "should load models from a view whose constants are currently uninitialized" do
      doc = {JSON.create_id => 'WithUnloadedEmbedded', '_id' => '1', 'embedded' => {JSON.create_id => 'WithUnloadedEmbedded::Uninitialized'}}
      CouchPotato.couchrest_database.save_doc(doc)
      expect(CouchPotato.database.view(WithUnloadedEmbedded.all).first.embedded.class.name).to eq('WithUnloadedEmbedded::Uninitialized')
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
couch_potato-1.17.0 spec/rails_spec.rb
couch_potato-1.16.0 spec/rails_spec.rb
couch_potato-1.15.0 spec/rails_spec.rb
couch_potato-1.14.0 spec/rails_spec.rb
couch_potato-1.13.0 spec/rails_spec.rb
couch_potato-1.12.1 spec/rails_spec.rb
couch_potato-1.12.0 spec/rails_spec.rb
couch_potato-1.11.0 spec/rails_spec.rb
couch_potato-1.10.1 spec/rails_spec.rb
couch_potato-1.10.0 spec/rails_spec.rb
couch_potato-1.9.0 spec/rails_spec.rb
couch_potato-1.7.1 spec/rails_spec.rb
couch_potato-1.7.0 spec/rails_spec.rb
couch_potato-1.6.5 spec/rails_spec.rb
couch_potato-1.6.4 spec/rails_spec.rb
couch_potato-1.6.3 spec/rails_spec.rb