Commit 4bc53974 by Alex Chaffee

fix bugs against Rails 2.3.14

parent 637499db
......@@ -317,7 +317,10 @@ module AnnotateModels
# Retrieve loaded model class by path to the file where it's supposed to be defined.
def get_loaded_model(model_path)
ObjectSpace.each_object.
select { |c| c.is_a?(Class) && c.ancestors.include?(ActiveRecord::Base) }.
select { |c|
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
c.ancestors.include?(ActiveRecord::Base)
}.
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
end
......@@ -357,6 +360,8 @@ module AnnotateModels
rescue Exception => e
# todo: check if all backtrace lines are in "gems" -- if so, it's an annotate bug, so print the whole stack trace.
puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})"
# todo: save this backtrace somewhere nice
# puts "\t" + e.backtrace.join("\n\t")
end
end
if annotated.empty?
......
source :rubygems
gem "rails", "~>2.3.14"
gem "rails", "~>2.3"
gem "sqlite3"
......@@ -26,5 +26,5 @@ PLATFORMS
ruby
DEPENDENCIES
rails (~> 2.3.14)
rails (~> 2.3)
sqlite3
source :rubygems
gem 'rails', "~>3.2.2"
gem 'rails', "~>3.2"
gem "sqlite3"
......@@ -83,5 +83,5 @@ PLATFORMS
ruby
DEPENDENCIES
rails (~> 3.2.2)
rails (~> 3.2)
sqlite3
......@@ -35,6 +35,7 @@ describe "annotate inside Rails" do
rails_version = rails_version.split(" ").last
rails_version.should =~ /(\d+)(\.\d+)*/
rails_version.should =~ /^#{base_version}/
puts "\nUsing Rails #{rails_version}"
`#{new_cmd} todo`
Dir.chdir("#{temp_dir}/todo") do
......@@ -42,20 +43,27 @@ describe "annotate inside Rails" do
`../rake db:migrate`.should =~ /CreateTasks: migrated/
File.read("app/models/task.rb").should == "class Task < ActiveRecord::Base\nend\n"
`#{annotate_bin}`.chomp.should == "Annotated (1): Task"
File.read("app/models/task.rb").should == <<-RUBY
expected_model = <<-RUBY
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# content :string(255)
# created_at :datetime not null
# id :integer not null, primary key
# updated_at :datetime not null
#
class Task < ActiveRecord::Base
end
RUBY
if base_version == "2.3"
# for some reason timestamps are not required in Rails 2.3.14
expected_model.gsub!("datetime not null", "datetime")
end
File.read("app/models/task.rb").should == expected_model
end
end
end
......
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