Skip to content

Commit 248e665

Browse files
committed
Allow models with non standard capitalization
1 parent ddfba1f commit 248e665

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ def get_model_class(file)
239239
begin
240240
parts.inject(Object) {|klass, part| klass.const_get(part) }
241241
rescue LoadError, NameError
242-
Object.const_get(parts.last)
242+
begin
243+
Object.const_get(parts.last)
244+
rescue LoadError, NameError
245+
Object.const_get(Module.constants.detect{|c|parts.last.downcase == c.downcase})
246+
end
243247
end
244248
end
245249

spec/annotate/annotate_models_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class FooWithMacro < ActiveRecord::Base
6969
acts_as_awesome :yah
7070
end
7171
EOS
72+
create('foo_with_capitals.rb', <<-EOS)
73+
class FooWithCAPITALS < ActiveRecord::Base
74+
acts_as_awesome :yah
75+
end
76+
EOS
7277
end
7378
it "should work" do
7479
klass = AnnotateModels.get_model_class("foo.rb")
@@ -78,6 +83,10 @@ class FooWithMacro < ActiveRecord::Base
7883
klass = AnnotateModels.get_model_class("foo_with_macro.rb")
7984
klass.name.should == "FooWithMacro"
8085
end
86+
it "should find models with non standard capitalization" do
87+
klass = AnnotateModels.get_model_class("foo_with_capitals.rb")
88+
klass.name.should == "FooWithCAPITALS"
89+
end
8190
end
8291

8392
end

0 commit comments

Comments
 (0)