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
7cbdba6a
Commit
7cbdba6a
authored
Feb 23, 2014
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #166 from jonoterc/namespacefix
fix overwriting of namespaced model test annotations with non-namespaced model annotations
parents
4e4a5a42
8aa6948e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
22 deletions
+8
-22
annotate_models.rb
lib/annotate/annotate_models.rb
+4
-18
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+3
-3
annotate_routes_spec.rb
spec/annotate/annotate_routes_spec.rb
+1
-1
No files found.
lib/annotate/annotate_models.rb
View file @
7cbdba6a
...
...
@@ -31,8 +31,8 @@ module AnnotateModels
FABRICATORS_SPEC_DIR
=
File
.
join
(
"spec"
,
"fabricators"
)
TEST_PATTERNS
=
[
[
UNIT_TEST_DIR
,
"%MODEL_NAME%_test.rb"
]
,
[
SPEC_MODEL_DIR
,
"%MODEL_NAME%_spec.rb"
]
,
File
.
join
(
UNIT_TEST_DIR
,
"%MODEL_NAME%_test.rb"
)
,
File
.
join
(
SPEC_MODEL_DIR
,
"%MODEL_NAME%_spec.rb"
)
,
]
FIXTURE_PATTERNS
=
[
...
...
@@ -301,8 +301,7 @@ module AnnotateModels
unless
options
[
:exclude_tests
]
did_annotate
=
TEST_PATTERNS
.
map
{
|
pat
|
[
pat
[
0
],
resolve_filename
(
pat
[
1
],
model_name
,
table_name
)]
}.
map
{
|
pat
|
find_test_file
(
*
pat
)
}.
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
map
{
|
file
|
annotate_one_file
(
file
,
info
,
:position_in_test
,
options_with_position
(
options
,
:position_in_test
))
}.
detect
{
|
result
|
result
}
||
did_annotate
end
...
...
@@ -441,16 +440,7 @@ module AnnotateModels
model_file_name
=
File
.
join
(
model_dir
,
file
)
deannotated_klass
=
true
if
(
remove_annotation_of_file
(
model_file_name
))
TEST_PATTERNS
.
map
{
|
pat
|
[
pat
[
0
],
resolve_filename
(
pat
[
1
],
model_name
,
table_name
)]}.
map
{
|
pat
|
find_test_file
(
*
pat
)
}.
each
do
|
file
|
if
(
File
.
exist?
(
file
))
remove_annotation_of_file
(
file
)
deannotated_klass
=
true
end
end
(
FIXTURE_PATTERNS
+
FACTORY_PATTERNS
).
(
TEST_PATTERNS
+
FIXTURE_PATTERNS
+
FACTORY_PATTERNS
).
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
each
do
|
file
|
if
File
.
exist?
(
file
)
...
...
@@ -468,10 +458,6 @@ module AnnotateModels
puts
"Removed annotations from:
#{
deannotated
.
join
(
', '
)
}
"
end
def
find_test_file
(
dir
,
file_name
)
Dir
.
glob
(
File
.
join
(
dir
,
"**"
,
file_name
)).
first
||
File
.
join
(
dir
,
file_name
)
end
def
resolve_filename
(
filename_template
,
model_name
,
table_name
)
return
filename_template
.
gsub
(
'%MODEL_NAME%'
,
model_name
).
...
...
spec/annotate/annotate_models_spec.rb
View file @
7cbdba6a
...
...
@@ -6,14 +6,14 @@ require 'annotate/active_record_patch'
describe
AnnotateModels
do
def
mock_class
(
table_name
,
primary_key
,
columns
)
options
=
{
:connection
=>
mock
(
"Conn"
,
:indexes
=>
[]),
:connection
=>
double
(
"Conn"
,
:indexes
=>
[]),
:table_name
=>
table_name
,
:primary_key
=>
primary_key
,
:column_names
=>
columns
.
map
{
|
col
|
col
.
name
.
to_s
},
:columns
=>
columns
}
mock
(
"An ActiveRecord class"
,
options
)
double
(
"An ActiveRecord class"
,
options
)
end
def
mock_column
(
name
,
type
,
options
=
{})
...
...
@@ -27,7 +27,7 @@ describe AnnotateModels do
stubs
.
merge!
(
options
)
stubs
.
merge!
(
:name
=>
name
,
:type
=>
type
)
mock
(
"Column"
,
stubs
)
double
(
"Column"
,
stubs
)
end
it
{
AnnotateModels
.
quote
(
nil
).
should
eql
(
"NULL"
)
}
...
...
spec/annotate/annotate_routes_spec.rb
View file @
7cbdba6a
...
...
@@ -4,7 +4,7 @@ require 'annotate/annotate_routes'
describe
AnnotateRoutes
do
def
mock_file
(
stubs
=
{})
@mock_file
||=
mock
(
File
,
stubs
)
@mock_file
||=
double
(
File
,
stubs
)
end
it
"should check if routes.rb exists"
do
...
...
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