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
8d47241e
Commit
8d47241e
authored
Jun 20, 2010
by
fistfvck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add specs
parent
10f896ee
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
35 deletions
+36
-35
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+36
-35
No files found.
spec/annotate/annotate_models_spec.rb
View file @
8d47241e
...
...
@@ -3,29 +3,11 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
require
'annotate/annotate_models'
require
'active_support'
require
'fakefs/spec_helpers'
require
'tmpdir'
describe
AnnotateModels
do
include
FakeFS
::
SpecHelpers
before
(
:all
)
do
require
"tmpdir"
@dir
=
Dir
.
tmpdir
+
"/
#{
Time
.
now
.
to_i
}
"
+
"/annotate_models"
FileUtils
.
mkdir_p
(
@dir
)
AnnotateModels
.
model_dir
=
@dir
end
module
::
ActiveRecord
class
Base
end
end
def
create
(
file
,
body
=
"hi"
)
File
.
open
(
@dir
+
'/'
+
file
,
"w"
)
do
|
f
|
f
.
puts
(
body
)
end
@dir
+
'/'
+
file
end
def
mock_class
(
table_name
,
primary_key
,
columns
)
options
=
{
:connection
=>
mock
(
"Conn"
,
:indexes
=>
[]),
...
...
@@ -79,7 +61,19 @@ EOS
describe
"#get_model_class"
do
def
create
(
file
,
body
=
"hi"
)
path
=
@dir
+
'/'
+
file
File
.
open
(
path
,
"w"
)
do
|
f
|
f
.
puts
(
body
)
end
path
end
before
:all
do
@dir
=
File
.
join
Dir
.
tmpdir
,
"annotate_models"
FileUtils
.
mkdir_p
(
@dir
)
AnnotateModels
.
model_dir
=
@dir
create
(
'foo.rb'
,
<<-
EOS
)
class Foo < ActiveRecord::Base
end
...
...
@@ -175,35 +169,42 @@ end
describe
"annotating a file"
do
before
do
@file_name
=
"user.rb"
@file_content
=
"class User < ActiveRecord::Base; end"
@file_content
=
<<-
EOS
class User < ActiveRecord::Base
end
EOS
File
.
open
(
@file_name
,
"wb"
)
{
|
f
|
f
.
write
@file_content
}
@klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:name
,
:string
,
:limit
=>
50
)
])
end
def
write_file
File
.
open
(
"user.rb"
,
"w"
)
do
|
f
|
f
<<
@file_content
end
@schema_info
=
AnnotateModels
.
get_schema_info
(
@klass
,
"== Schema Info"
)
end
it
"should annotate the file before the model if position == 'before'"
do
write_file
schema_info
=
AnnotateModels
.
get_schema_info
(
@klass
,
"Schema Info"
)
AnnotateModels
.
annotate_one_file
(
@file_name
,
@schema_info
,
:position
=>
"before"
)
File
.
read
(
@file_name
).
should
==
"
#{
@schema_info
}#{
@file_content
}
"
end
AnnotateModels
.
annotate_one_file
(
"user.rb"
,
schema_info
,
:position
=>
"before"
)
it
"should annotate before if given :position => :before"
do
AnnotateModels
.
annotate_one_file
(
@file_name
,
@schema_info
,
:position
=>
:before
)
File
.
read
(
@file_name
).
should
==
"
#{
@schema_info
}#{
@file_content
}
"
end
File
.
read
(
"user.rb"
).
should
==
"
#{
schema_info
}#{
@file_content
}
\n
"
it
"should annotate before if given :position => :after"
do
AnnotateModels
.
annotate_one_file
(
@file_name
,
@schema_info
,
:position
=>
:after
)
File
.
read
(
@file_name
).
should
==
"
#{
@file_content
}
\n
#{
@schema_info
}
"
end
it
"should annotate before if given :position => :before"
do
write_file
schema_info
=
AnnotateModels
.
get_schema_info
(
@klass
,
"Schema Info"
)
it
"should update annotate position"
do
AnnotateModels
.
annotate_one_file
(
@file_name
,
@schema_info
,
:position
=>
:before
)
another_schema_info
=
AnnotateModels
.
get_schema_info
(
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),]),
"== Schema Info"
)
AnnotateModels
.
annotate_one_file
(
@file_name
,
schema_info
,
:position
=>
:before
)
AnnotateModels
.
annotate_one_file
(
@file_name
,
another_schema_info
,
:position
=>
:after
)
File
.
read
(
"user.rb"
).
should
==
"
#{
schema_info
}#{
@file_content
}
\n
"
File
.
read
(
@file_name
).
should
==
"
#{
@file_content
}
\n
#{
another_schema_info
}
"
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