Skip to content

Commit fba0ca0

Browse files
committed
Implement namespaced models test.
1 parent 3689d9d commit fba0ca0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

CHANGELOG.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
non-standard capitalization.
5555
Note that this still requires that the inflector be configured to understand
5656
the special case.
57+
* Shore up test cases a bit.
5758
* Merge against many of the older branches on Github whose functionality is
5859
already reflected to reduce confusion about what is and is not implemented
5960
here.

spec/annotate/annotate_models_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class Foo < ActiveRecord::Base
295295
describe "annotating a file" do
296296
before do
297297
@model_dir = Dir.mktmpdir('annotate_models')
298-
write_model "user.rb", <<-EOS
298+
(@model_file_name, @file_content) = write_model "user.rb", <<-EOS
299299
class User < ActiveRecord::Base
300300
end
301301
EOS
@@ -308,9 +308,10 @@ class User < ActiveRecord::Base
308308
end
309309

310310
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
314315
end
315316

316317
def annotate_one_file options = {}
@@ -344,7 +345,20 @@ def annotate_one_file options = {}
344345
File.read(@model_file_name).should == "#{@file_content}\n#{another_schema_info}"
345346
end
346347

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
348362

349363
describe "if a file can't be annotated" do
350364
before do

0 commit comments

Comments
 (0)