Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
annotate
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
annotate
Commits
a153002b
Commit
a153002b
authored
Jun 20, 2010
by
fistfvck
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'origin/master' into restart
parents
6ac41da4
ace84ab4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
2 deletions
+60
-2
annotate_models.rb
lib/annotate/annotate_models.rb
+2
-2
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+58
-0
No files found.
lib/annotate/annotate_models.rb
View file @
a153002b
...
...
@@ -137,7 +137,7 @@ module AnnotateModels
false
else
# Remove old schema info
old_content
.
sub!
(
/^#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
old_content
.
sub!
(
/^
\n?
#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
# Write it back
new_content
=
options
[
:position
].
to_s
==
'after'
?
(
old_content
+
"
\n
"
+
info_block
)
:
(
info_block
+
old_content
)
...
...
@@ -152,7 +152,7 @@ module AnnotateModels
if
File
.
exist?
(
file_name
)
content
=
File
.
read
(
file_name
)
content
.
sub!
(
/^#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
content
.
sub!
(
/^
\n?
#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
content
}
end
...
...
spec/annotate/annotate_models_spec.rb
View file @
a153002b
...
...
@@ -149,4 +149,62 @@ EOF
end
end
describe
"#remove_annotation_of_file"
do
def
create
(
file
,
body
=
"hi"
)
File
.
open
(
@dir
+
'/'
+
file
,
"w"
)
do
|
f
|
f
.
puts
(
body
)
end
end
def
content
(
file
)
File
.
read
(
@dir
+
'/'
+
file
)
end
before
:all
do
require
"tmpdir"
@dir
=
Dir
.
tmpdir
+
"/
#{
Time
.
now
.
to_i
}
"
+
"/annotate_models"
FileUtils
.
mkdir_p
(
@dir
)
create
(
"before.rb"
,
<<-
EOS
)
# == Schema Information
#
# Table name: foo
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#
class Foo < ActiveRecord::Base
end
EOS
create
(
"after.rb"
,
<<-
EOS
)
class Foo < ActiveRecord::Base
end
# == Schema Information
#
# Table name: foo
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#
EOS
end
it
"should remove before annotate"
do
AnnotateModels
.
remove_annotation_of_file
(
@dir
+
'/'
+
"before.rb"
)
content
(
"before.rb"
).
should
==
<<-
EOS
class Foo < ActiveRecord::Base
end
EOS
end
it
"should remove after annotate"
do
AnnotateModels
.
remove_annotation_of_file
(
@dir
+
'/'
+
"after.rb"
)
content
(
"after.rb"
).
should
==
<<-
EOS
class Foo < ActiveRecord::Base
end
EOS
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment