Commit 2f6dbdc0 by Alex Chaffee

issue 36 fix: warn about macros, to mitigate when we're included during a…

issue 36 fix: warn about macros, to mitigate when we're included during a production run, not just a rakefile run -- possibly at the expense of too much noise
parent 2aa3d087
...@@ -5,4 +5,5 @@ group :development do ...@@ -5,4 +5,5 @@ group :development do
gem "rdoc" gem "rdoc"
gem "mg" gem "mg"
gem 'activesupport', '>= 2.1.0' gem 'activesupport', '>= 2.1.0'
gem "wrong"
end end
== 2.5.0 2011-06-27 ? == 2.5.0 2011-06-27 ?
* issue 36 fix: warn about macros, to mitigate when we're included during a production run, not just a rakefile run -- possibly at the expense of too much noise
* 85f6e53 (HEAD, master) Merge branch 'master' of github.com:ctran/annotate_models * 85f6e53 (HEAD, master) Merge branch 'master' of github.com:ctran/annotate_models
|\ |\
......
...@@ -330,7 +330,10 @@ end ...@@ -330,7 +330,10 @@ end
module ::ActiveRecord module ::ActiveRecord
class Base class Base
def self.method_missing(name, *args) def self.method_missing(name, *args)
super
rescue NoMethodError => e
# ignore this, so unknown/unloaded macros won't cause parsing to fail # ignore this, so unknown/unloaded macros won't cause parsing to fail
warn "Annotate Models ignoring #{e.class}: #{e.message}"
end end
end end
end end
...@@ -46,6 +46,8 @@ EOS ...@@ -46,6 +46,8 @@ EOS
describe "#get_model_class" do describe "#get_model_class" do
module ::ActiveRecord module ::ActiveRecord
class Base class Base
def self.has_many name
end
end end
end end
...@@ -69,15 +71,32 @@ EOS ...@@ -69,15 +71,32 @@ EOS
acts_as_awesome :yah acts_as_awesome :yah
end end
EOS EOS
create('foo_with_known_macro.rb', <<-EOS)
class FooWithKnownMacro < ActiveRecord::Base
has_many :yah
end
EOS
end end
it "should work" do it "should work" do
klass = AnnotateModels.get_model_class("foo.rb") klass = AnnotateModels.get_model_class("foo.rb")
klass.name.should == "Foo" klass.name.should == "Foo"
end end
it "should not care about unknown macros" do it "should not care about unknown macros" do
capturing(:stderr) do
klass = AnnotateModels.get_model_class("foo_with_macro.rb") klass = AnnotateModels.get_model_class("foo_with_macro.rb")
klass.name.should == "FooWithMacro" klass.name.should == "FooWithMacro"
end.should include("undefined method `acts_as_awesome'")
end
it "should allow known macros" do
capturing(:stderr) do
klass = AnnotateModels.get_model_class("foo_with_known_macro.rb")
klass.name.should == "FooWithKnownMacro"
end.should == ""
end end
end end
end end
...@@ -6,5 +6,7 @@ rescue LoadError ...@@ -6,5 +6,7 @@ rescue LoadError
require 'rspec' require 'rspec'
end end
require "wrong/adapters/rspec"
$:.unshift(File.dirname(__FILE__) + '/../lib') $:.unshift(File.dirname(__FILE__) + '/../lib')
require 'annotate' require 'annotate'
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