@@ -295,7 +295,7 @@ class Foo < ActiveRecord::Base
295
295
describe "annotating a file" do
296
296
before do
297
297
@model_dir = Dir . mktmpdir ( 'annotate_models' )
298
- write_model "user.rb" , <<-EOS
298
+ ( @model_file_name , @file_content ) = write_model "user.rb" , <<-EOS
299
299
class User < ActiveRecord::Base
300
300
end
301
301
EOS
@@ -308,9 +308,10 @@ class User < ActiveRecord::Base
308
308
end
309
309
310
310
def write_model file_name , file_content
311
- @model_file_name = File . join ( @model_dir , file_name )
312
- @file_content = file_content
313
- File . open ( @model_file_name , "wb" ) { |f | f . write @file_content }
311
+ fname = File . join ( @model_dir , file_name )
312
+ FileUtils . mkdir_p ( File . dirname ( fname ) )
313
+ File . open ( fname , "wb" ) { |f | f . write file_content }
314
+ return fname , file_content
314
315
end
315
316
316
317
def annotate_one_file options = { }
@@ -344,7 +345,20 @@ def annotate_one_file options = {}
344
345
File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ another_schema_info } "
345
346
end
346
347
347
- it "works with namepaced models (i.e. models inside modules/subdirectories"
348
+ it "works with namespaced models (i.e. models inside modules/subdirectories)" do
349
+ ( model_file_name , file_content ) = write_model "foo/user.rb" , <<-EOS
350
+ class Foo::User < ActiveRecord::Base
351
+ end
352
+ EOS
353
+
354
+ klass = mock_class ( :'foo_users' , :id , [
355
+ mock_column ( :id , :integer ) ,
356
+ mock_column ( :name , :string , :limit => 50 )
357
+ ] )
358
+ schema_info = AnnotateModels . get_schema_info ( klass , "== Schema Info" )
359
+ AnnotateModels . annotate_one_file ( model_file_name , schema_info , :position => :before )
360
+ File . read ( model_file_name ) . should == "#{ schema_info } #{ file_content } "
361
+ end
348
362
349
363
describe "if a file can't be annotated" do
350
364
before do
0 commit comments