Fix issue during update models

parent febb1fe4
......@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{doubledrones-annotate}
s.version = "2.4.0.1"
s.version = "2.4.0.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Marcin Michałowski", "Marcin Nowicki"]
......
......@@ -127,7 +127,7 @@ module AnnotateModels
false
else
# Remove old schema info
old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*/, '')
# Write it back
new_content = options[:position] == 'before' ? (info_block + old_content) : (old_content + info_block)
......
......@@ -79,4 +79,56 @@ EOS
end
end
describe "annotating one file already annotated but schema was changed" do
def create(file, body="hi")
File.open(@dir + '/' + file, "w") do |f|
f.puts(body)
end
end
before :all do
require "tmpdir"
@dir = Dir.tmpdir + "/#{Time.now.to_i}" + "/annotate_models"
FileUtils.mkdir_p(@dir)
AnnotateModels.model_dir = @dir
create('foo.rb', <<-EOS)
class Foo < ActiveRecord::Base
end
# == Schema Information
#
# Table name: users
#
# id :integer primary key
# name :string
#
EOS
end
it 'should replace old annotation' do
info_block = <<-EOS
# == Schema Information
#
# Table name: users
#
# id :integer primary key
# name :string
# new :string
#
EOS
AnnotateModels.annotate_one_file(@dir + '/foo.rb', info_block).should be_true
File.read(@dir + '/foo.rb').should == <<-EOS
class Foo < ActiveRecord::Base
end
# == Schema Information
#
# Table name: users
#
# id :integer primary key
# name :string
# new :string
#
EOS
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