Commit fba0ca0a by Jon Frisby

Implement namespaced models test.

parent 3689d9db
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
non-standard capitalization. non-standard capitalization.
Note that this still requires that the inflector be configured to understand Note that this still requires that the inflector be configured to understand
the special case. the special case.
* Shore up test cases a bit.
* Merge against many of the older branches on Github whose functionality is * Merge against many of the older branches on Github whose functionality is
already reflected to reduce confusion about what is and is not implemented already reflected to reduce confusion about what is and is not implemented
here. here.
......
...@@ -295,7 +295,7 @@ end ...@@ -295,7 +295,7 @@ end
describe "annotating a file" do describe "annotating a file" do
before do before do
@model_dir = Dir.mktmpdir('annotate_models') @model_dir = Dir.mktmpdir('annotate_models')
write_model "user.rb", <<-EOS (@model_file_name, @file_content) = write_model "user.rb", <<-EOS
class User < ActiveRecord::Base class User < ActiveRecord::Base
end end
EOS EOS
...@@ -308,9 +308,10 @@ end ...@@ -308,9 +308,10 @@ end
end end
def write_model file_name, file_content def write_model file_name, file_content
@model_file_name = File.join(@model_dir, file_name) fname = File.join(@model_dir, file_name)
@file_content = file_content FileUtils.mkdir_p(File.dirname(fname))
File.open(@model_file_name, "wb") { |f| f.write @file_content } File.open(fname, "wb") { |f| f.write file_content }
return fname, file_content
end end
def annotate_one_file options = {} def annotate_one_file options = {}
...@@ -344,7 +345,20 @@ end ...@@ -344,7 +345,20 @@ end
File.read(@model_file_name).should == "#{@file_content}\n#{another_schema_info}" File.read(@model_file_name).should == "#{@file_content}\n#{another_schema_info}"
end end
it "works with namepaced models (i.e. models inside modules/subdirectories" it "works with namespaced models (i.e. models inside modules/subdirectories)" do
(model_file_name, file_content) = write_model "foo/user.rb", <<-EOS
class Foo::User < ActiveRecord::Base
end
EOS
klass = mock_class(:'foo_users', :id, [
mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50)
])
schema_info = AnnotateModels.get_schema_info(klass, "== Schema Info")
AnnotateModels.annotate_one_file(model_file_name, schema_info, :position => :before)
File.read(model_file_name).should == "#{schema_info}#{file_content}"
end
describe "if a file can't be annotated" do describe "if a file can't be annotated" do
before do before do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment