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
11 years ago
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
...
@@ -31,8 +31,8 @@ module AnnotateModels
FABRICATORS_SPEC_DIR
=
File
.
join
(
"spec"
,
"fabricators"
)
FABRICATORS_SPEC_DIR
=
File
.
join
(
"spec"
,
"fabricators"
)
TEST_PATTERNS
=
[
TEST_PATTERNS
=
[
[
UNIT_TEST_DIR
,
"%MODEL_NAME%_test.rb"
]
,
File
.
join
(
UNIT_TEST_DIR
,
"%MODEL_NAME%_test.rb"
)
,
[
SPEC_MODEL_DIR
,
"%MODEL_NAME%_spec.rb"
]
,
File
.
join
(
SPEC_MODEL_DIR
,
"%MODEL_NAME%_spec.rb"
)
,
]
]
FIXTURE_PATTERNS
=
[
FIXTURE_PATTERNS
=
[
...
@@ -301,8 +301,7 @@ module AnnotateModels
...
@@ -301,8 +301,7 @@ module AnnotateModels
unless
options
[
:exclude_tests
]
unless
options
[
:exclude_tests
]
did_annotate
=
TEST_PATTERNS
.
did_annotate
=
TEST_PATTERNS
.
map
{
|
pat
|
[
pat
[
0
],
resolve_filename
(
pat
[
1
],
model_name
,
table_name
)]
}.
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
map
{
|
pat
|
find_test_file
(
*
pat
)
}.
map
{
|
file
|
annotate_one_file
(
file
,
info
,
:position_in_test
,
options_with_position
(
options
,
:position_in_test
))
}.
map
{
|
file
|
annotate_one_file
(
file
,
info
,
:position_in_test
,
options_with_position
(
options
,
:position_in_test
))
}.
detect
{
|
result
|
result
}
||
did_annotate
detect
{
|
result
|
result
}
||
did_annotate
end
end
...
@@ -441,16 +440,7 @@ module AnnotateModels
...
@@ -441,16 +440,7 @@ module AnnotateModels
model_file_name
=
File
.
join
(
model_dir
,
file
)
model_file_name
=
File
.
join
(
model_dir
,
file
)
deannotated_klass
=
true
if
(
remove_annotation_of_file
(
model_file_name
))
deannotated_klass
=
true
if
(
remove_annotation_of_file
(
model_file_name
))
TEST_PATTERNS
.
(
TEST_PATTERNS
+
FIXTURE_PATTERNS
+
FACTORY_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
).
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
each
do
|
file
|
each
do
|
file
|
if
File
.
exist?
(
file
)
if
File
.
exist?
(
file
)
...
@@ -468,10 +458,6 @@ module AnnotateModels
...
@@ -468,10 +458,6 @@ module AnnotateModels
puts
"Removed annotations from:
#{
deannotated
.
join
(
', '
)
}
"
puts
"Removed annotations from:
#{
deannotated
.
join
(
', '
)
}
"
end
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
)
def
resolve_filename
(
filename_template
,
model_name
,
table_name
)
return
filename_template
.
return
filename_template
.
gsub
(
'%MODEL_NAME%'
,
model_name
).
gsub
(
'%MODEL_NAME%'
,
model_name
).
...
...
This diff is collapsed.
Click to expand it.
spec/annotate/annotate_models_spec.rb
View file @
7cbdba6a
...
@@ -6,14 +6,14 @@ require 'annotate/active_record_patch'
...
@@ -6,14 +6,14 @@ require 'annotate/active_record_patch'
describe
AnnotateModels
do
describe
AnnotateModels
do
def
mock_class
(
table_name
,
primary_key
,
columns
)
def
mock_class
(
table_name
,
primary_key
,
columns
)
options
=
{
options
=
{
:connection
=>
mock
(
"Conn"
,
:indexes
=>
[]),
:connection
=>
double
(
"Conn"
,
:indexes
=>
[]),
:table_name
=>
table_name
,
:table_name
=>
table_name
,
:primary_key
=>
primary_key
,
:primary_key
=>
primary_key
,
:column_names
=>
columns
.
map
{
|
col
|
col
.
name
.
to_s
},
:column_names
=>
columns
.
map
{
|
col
|
col
.
name
.
to_s
},
:columns
=>
columns
:columns
=>
columns
}
}
mock
(
"An ActiveRecord class"
,
options
)
double
(
"An ActiveRecord class"
,
options
)
end
end
def
mock_column
(
name
,
type
,
options
=
{})
def
mock_column
(
name
,
type
,
options
=
{})
...
@@ -27,7 +27,7 @@ describe AnnotateModels do
...
@@ -27,7 +27,7 @@ describe AnnotateModels do
stubs
.
merge!
(
options
)
stubs
.
merge!
(
options
)
stubs
.
merge!
(
:name
=>
name
,
:type
=>
type
)
stubs
.
merge!
(
:name
=>
name
,
:type
=>
type
)
mock
(
"Column"
,
stubs
)
double
(
"Column"
,
stubs
)
end
end
it
{
AnnotateModels
.
quote
(
nil
).
should
eql
(
"NULL"
)
}
it
{
AnnotateModels
.
quote
(
nil
).
should
eql
(
"NULL"
)
}
...
...
This diff is collapsed.
Click to expand it.
spec/annotate/annotate_routes_spec.rb
View file @
7cbdba6a
...
@@ -4,7 +4,7 @@ require 'annotate/annotate_routes'
...
@@ -4,7 +4,7 @@ require 'annotate/annotate_routes'
describe
AnnotateRoutes
do
describe
AnnotateRoutes
do
def
mock_file
(
stubs
=
{})
def
mock_file
(
stubs
=
{})
@mock_file
||=
mock
(
File
,
stubs
)
@mock_file
||=
double
(
File
,
stubs
)
end
end
it
"should check if routes.rb exists"
do
it
"should check if routes.rb exists"
do
...
...
This diff is collapsed.
Click to expand it.
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