spec/annotate/annotate_models_spec.rb in doubledrones-annotate-2.4.0.1 vs spec/annotate/annotate_models_spec.rb in doubledrones-annotate-2.4.0.2

- old
+ new

@@ -77,6 +77,58 @@ klass = AnnotateModels.get_model_class("foo_with_macro.rb") klass.name.should == "FooWithMacro" 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