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
a4be28ad
Commit
a4be28ad
authored
Nov 09, 2019
by
Alexander Belozerov
Committed by
Cuong Tran
Nov 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix #624] Correct default values for columns when ActiveRecord::Enum is used (#677)
parent
1df2153f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+1
-1
annotate_models_spec.rb
spec/lib/annotate/annotate_models_spec.rb
+23
-0
No files found.
lib/annotate/annotate_models.rb
View file @
a4be28ad
...
...
@@ -211,7 +211,7 @@ module AnnotateModels
end
def
schema_default
(
klass
,
column
)
quote
(
klass
.
column
_defaults
[
column
.
name
]
)
quote
(
klass
.
column
s
.
find
{
|
x
|
x
.
name
.
to_s
==
column
.
name
.
to_s
}.
try
(
:default
)
)
end
def
retrieve_indexes_from_table
(
klass
)
...
...
spec/lib/annotate/annotate_models_spec.rb
View file @
a4be28ad
...
...
@@ -225,6 +225,29 @@ EOS
EOS
end
it
'sets correct default value for integer column when ActiveRecord::Enum is used'
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:status
,
:integer
,
default:
0
)
])
# column_defaults may be overritten when ActiveRecord::Enum is used, e.g:
# class User < ActiveRecord::Base
# enum status: [ :disabled, :enabled ]
# end
allow
(
klass
).
to
receive
(
:column_defaults
).
and_return
(
'id'
=>
nil
,
'status'
=>
'disabled'
)
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
'Schema Info'
)).
to
eql
(
<<-
EOS
)
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# status :integer default(0), not null
#
EOS
end
it
'should get foreign key info'
do
klass
=
mock_class
(
:users
,
:id
,
...
...
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