doubledrones-annotate 2.4.0.1 → 2.4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -127,7 +127,7 @@ module AnnotateModels
127
127
  false
128
128
  else
129
129
  # Remove old schema info
130
- old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
130
+ old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*/, '')
131
131
 
132
132
  # Write it back
133
133
  new_content = options[:position] == 'before' ? (info_block + old_content) : (old_content + info_block)
@@ -79,4 +79,56 @@ EOS
79
79
  end
80
80
  end
81
81
 
82
+ describe "annotating one file already annotated but schema was changed" do
83
+ def create(file, body="hi")
84
+ File.open(@dir + '/' + file, "w") do |f|
85
+ f.puts(body)
86
+ end
87
+ end
88
+
89
+ before :all do
90
+ require "tmpdir"
91
+ @dir = Dir.tmpdir + "/#{Time.now.to_i}" + "/annotate_models"
92
+ FileUtils.mkdir_p(@dir)
93
+ AnnotateModels.model_dir = @dir
94
+ create('foo.rb', <<-EOS)
95
+ class Foo < ActiveRecord::Base
96
+ end
97
+ # == Schema Information
98
+ #
99
+ # Table name: users
100
+ #
101
+ # id :integer primary key
102
+ # name :string
103
+ #
104
+ EOS
105
+ end
106
+
107
+ it 'should replace old annotation' do
108
+ info_block = <<-EOS
109
+ # == Schema Information
110
+ #
111
+ # Table name: users
112
+ #
113
+ # id :integer primary key
114
+ # name :string
115
+ # new :string
116
+ #
117
+ EOS
118
+ AnnotateModels.annotate_one_file(@dir + '/foo.rb', info_block).should be_true
119
+ File.read(@dir + '/foo.rb').should == <<-EOS
120
+ class Foo < ActiveRecord::Base
121
+ end
122
+ # == Schema Information
123
+ #
124
+ # Table name: users
125
+ #
126
+ # id :integer primary key
127
+ # name :string
128
+ # new :string
129
+ #
130
+ EOS
131
+ end
132
+ end
133
+
82
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doubledrones-annotate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 77
4
+ hash: 75
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 4
9
9
  - 0
10
- - 1
11
- version: 2.4.0.1
10
+ - 2
11
+ version: 2.4.0.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Cuong Tran