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
5177edd4
Commit
5177edd4
authored
9 years ago
by
cuong.tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore default value for json type since that can break indentation, #320
parent
5c9674fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+4
-1
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+19
-0
No files found.
lib/annotate/annotate_models.rb
View file @
5177edd4
...
...
@@ -59,6 +59,9 @@ module AnnotateModels
# Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES
=
[
"integer"
,
"boolean"
]
# Don't show default value for these column types
NO_DEFAULT_COL_TYPES
=
[
"json"
,
"jsonb"
]
class
<<
self
def
model_dir
@model_dir
.
is_a?
(
Array
)
?
@model_dir
:
[
@model_dir
||
"app/models"
]
...
...
@@ -198,7 +201,7 @@ module AnnotateModels
col_type
=
(
col
.
type
||
col
.
sql_type
).
to_s
attrs
=
[]
attrs
<<
"default(
#{
schema_default
(
klass
,
col
)
}
)"
unless
col
.
default
.
nil?
||
col_type
==
"jsonb"
attrs
<<
"default(
#{
schema_default
(
klass
,
col
)
}
)"
unless
col
.
default
.
nil?
||
NO_DEFAULT_COL_TYPES
.
include?
(
col_type
)
attrs
<<
"not null"
unless
col
.
null
attrs
<<
"primary key"
if
klass
.
primary_key
&&
(
klass
.
primary_key
.
is_a?
(
Array
)
?
klass
.
primary_key
.
collect
{
|
c
|
c
.
to_sym
}.
include?
(
col
.
name
.
to_sym
)
:
col
.
name
.
to_sym
==
klass
.
primary_key
.
to_sym
)
...
...
This diff is collapsed.
Click to expand it.
spec/annotate/annotate_models_spec.rb
View file @
5177edd4
...
...
@@ -150,6 +150,25 @@ EOS
EOS
end
it
"should ignore default value of json columns "
do
klass
=
mock_class
(
:users
,
nil
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:profile
,
:json
,
:default
=>
'{}'
),
mock_column
(
:settings
,
:jsonb
,
:default
=>
'{}'
)
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
"Schema Info"
)).
to
eql
(
<<-
EOS
)
# Schema Info
#
# Table name: users
#
# id :integer not null
# profile :json not null
# settings :jsonb not null
#
EOS
end
it
"should get foreign key info"
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
...
...
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