Commit f50b4cca by Scott Taylor

Allow :position => to be a symbol or string (as per the rake tasks)

parent eac9f453
......@@ -130,7 +130,9 @@ module AnnotateModels
old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
# Write it back
new_content = options[:position] == 'before' ? (info_block + old_content) : (old_content + "\n" + info_block)
new_content = options[:position].to_sym == :before ?
(info_block + old_content) :
(old_content + "\n" + info_block)
File.open(file_name, "wb") { |f| f.puts new_content }
true
......
......@@ -115,5 +115,24 @@ EOS
File.read("user.rb").should == "#{schema_info}#{file_content}\n"
end
it "should annotate before if given :position => :before" do
file_content = "class User < ActiveRecord::Base; end"
File.open("user.rb", "w") do |f|
f << file_content
end
klass = mock_class(: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("user.rb", schema_info, {:position => :before})
File.read("user.rb").should == "#{schema_info}#{file_content}\n"
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