Skip to content

Commit

Permalink
fixed reloading nested classes
Browse files Browse the repository at this point in the history
  • Loading branch information
langalex committed Mar 30, 2010
1 parent 9a7de66 commit 4a78b38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rails/reload_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def load_document_with_class_reloading(id)
load_document_without_class_reloading id
rescue ArgumentError => e
if(name = e.message.scan(/(can't find const|undefined class\/module) ([\w\:]+)/).first[1])
eval name
eval name.gsub(/\:+$/, '')
retry
else
raise e
Expand Down
17 changes: 14 additions & 3 deletions spec/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + '/../rails/reload_classes'

class Autoloader
def self.const_missing(name)
eval("#{name} = Class.new; #{name}.send(:include, CouchPotato::Persistence)")
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


describe CouchPotato::Database, 'rails specific behavior' do

Expand All @@ -16,5 +21,11 @@ def self.const_missing(name)
CouchPotato.database.load('1').class.name.should == 'Autoloader::Uninitialized'
end

it "should load nested models" do
recreate_db
CouchPotato.couchrest_database.save_doc(JSON.create_id => 'Autoloader::Nested::Nested2', '_id' => '1')
CouchPotato.database.load('1').class.name.should == 'Autoloader::Nested::Nested2'
end

end

0 comments on commit 4a78b38

Please sign in to comment.