Skip to content

Commit 4bc5397

Browse files
committed
fix bugs against Rails 2.3.14
1 parent 637499d commit 4bc5397

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

lib/annotate/annotate_models.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ def get_model_class(file)
317317
# Retrieve loaded model class by path to the file where it's supposed to be defined.
318318
def get_loaded_model(model_path)
319319
ObjectSpace.each_object.
320-
select { |c| c.is_a?(Class) && c.ancestors.include?(ActiveRecord::Base) }.
320+
select { |c|
321+
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
322+
c.ancestors.include?(ActiveRecord::Base)
323+
}.
321324
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
322325
end
323326

@@ -357,6 +360,8 @@ def do_annotations(options={})
357360
rescue Exception => e
358361
# todo: check if all backtrace lines are in "gems" -- if so, it's an annotate bug, so print the whole stack trace.
359362
puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})"
363+
# todo: save this backtrace somewhere nice
364+
# puts "\t" + e.backtrace.join("\n\t")
360365
end
361366
end
362367
if annotated.empty?

spec/integration/rails-2.3.gems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source :rubygems
22

3-
gem "rails", "~>2.3.14"
3+
gem "rails", "~>2.3"
44
gem "sqlite3"

spec/integration/rails-2.3.gems.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ PLATFORMS
2626
ruby
2727

2828
DEPENDENCIES
29-
rails (~> 2.3.14)
29+
rails (~> 2.3)
3030
sqlite3

spec/integration/rails-3.2.gems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source :rubygems
22

3-
gem 'rails', "~>3.2.2"
3+
gem 'rails', "~>3.2"
44
gem "sqlite3"

spec/integration/rails-3.2.gems.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ PLATFORMS
8383
ruby
8484

8585
DEPENDENCIES
86-
rails (~> 3.2.2)
86+
rails (~> 3.2)
8787
sqlite3

spec/integration/rails_integration_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,38 @@
3535
rails_version = rails_version.split(" ").last
3636
rails_version.should =~ /(\d+)(\.\d+)*/
3737
rails_version.should =~ /^#{base_version}/
38+
puts "\nUsing Rails #{rails_version}"
3839

3940
`#{new_cmd} todo`
4041
Dir.chdir("#{temp_dir}/todo") do
4142
`#{generate_cmd} scaffold Task content:string`.should =~ %r{db/migrate/.*_create_tasks.rb}
4243
`../rake db:migrate`.should =~ /CreateTasks: migrated/
4344
File.read("app/models/task.rb").should == "class Task < ActiveRecord::Base\nend\n"
4445
`#{annotate_bin}`.chomp.should == "Annotated (1): Task"
45-
File.read("app/models/task.rb").should == <<-RUBY
46+
expected_model = <<-RUBY
4647
# == Schema Information
4748
#
4849
# Table name: tasks
4950
#
51+
# id :integer not null, primary key
5052
# content :string(255)
5153
# created_at :datetime not null
52-
# id :integer not null, primary key
5354
# updated_at :datetime not null
5455
#
5556
5657
class Task < ActiveRecord::Base
5758
end
5859
RUBY
60+
61+
if base_version == "2.3"
62+
# for some reason timestamps are not required in Rails 2.3.14
63+
expected_model.gsub!("datetime not null", "datetime")
64+
end
65+
File.read("app/models/task.rb").should == expected_model
66+
5967
end
6068
end
6169
end
6270
end
6371
end
64-
end
72+
end

0 commit comments

Comments
 (0)