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