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
026cee5a
Commit
026cee5a
authored
Mar 08, 2015
by
cuong.tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #212 due to Rails 4.2 internal changes
parent
9c5837be
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
128 additions
and
7 deletions
+128
-7
annotate_models.rb
lib/annotate/annotate_models.rb
+7
-1
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+22
-1
event.rb
...ntegration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb
+10
-0
user.rb
spec/integration/rails_4.1.1/app/models/sub1/user.rb
+10
-0
task.rb
spec/integration/rails_4.1.1/app/models/task.rb
+12
-0
20140526224112_create_tasks.rb
...ion/rails_4.1.1/db/migrate/20140526224112_create_tasks.rb
+2
-1
schema.rb
spec/integration/rails_4.1.1/db/schema.rb
+2
-0
task_test.rb
spec/integration/rails_4.1.1/test/models/task_test.rb
+12
-0
event.rb
...ntegration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb
+10
-0
user.rb
spec/integration/rails_4.2.0/app/models/sub1/user.rb
+10
-0
task.rb
spec/integration/rails_4.2.0/app/models/task.rb
+12
-0
20140526224112_create_tasks.rb
...ion/rails_4.2.0/db/migrate/20140526224112_create_tasks.rb
+2
-1
schema.rb
spec/integration/rails_4.2.0/db/schema.rb
+5
-3
task_test.rb
spec/integration/rails_4.2.0/test/models/task_test.rb
+12
-0
No files found.
lib/annotate/annotate_models.rb
View file @
026cee5a
require
'bigdecimal'
module
AnnotateModels
# Annotate Models plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
...
...
@@ -94,6 +96,10 @@ module AnnotateModels
end
end
def
schema_default
(
klass
,
column
)
quote
(
klass
.
column_defaults
[
column
.
name
])
end
# Use the column information in an ActiveRecord class
# to create a comment block containing a line for
# each column. The line contains the column name,
...
...
@@ -130,7 +136,7 @@ module AnnotateModels
cols
=
classified_sort
(
cols
)
if
(
options
[
:classified_sort
])
cols
.
each
do
|
col
|
attrs
=
[]
attrs
<<
"default(
#{
quote
(
col
.
default
)
}
)"
unless
col
.
default
.
nil?
attrs
<<
"default(
#{
schema_default
(
klass
,
col
)
}
)"
unless
col
.
default
.
nil?
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
)
...
...
spec/annotate/annotate_models_spec.rb
View file @
026cee5a
...
...
@@ -10,7 +10,10 @@ describe AnnotateModels do
:table_name
=>
table_name
,
:primary_key
=>
primary_key
,
:column_names
=>
columns
.
map
{
|
col
|
col
.
name
.
to_s
},
:columns
=>
columns
:columns
=>
columns
,
:column_defaults
=>
Hash
[
columns
.
map
{
|
col
|
[
col
.
name
,
col
.
default
]
}]
}
double
(
"An ActiveRecord class"
,
options
)
...
...
@@ -106,6 +109,24 @@ EOS
EOS
end
it
"should get schema info for integer and boolean with default"
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:size
,
:integer
,
:default
=>
20
),
mock_column
(
:flag
,
:boolean
,
:default
=>
false
)
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
"Schema Info"
)).
to
eql
(
<<-
EOS
)
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# size :integer default(20), not null
# flag :boolean default(FALSE), not null
#
EOS
end
it
"should get schema info as RDoc"
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
...
...
spec/integration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb
View file @
026cee5a
# == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# content :string(255)
# created_at :datetime
# updated_at :datetime
#
module
Sub1::Sub2::Sub3
class
Event
<
ActiveRecord
::
Base
end
...
...
spec/integration/rails_4.1.1/app/models/sub1/user.rb
View file @
026cee5a
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# content :string(255)
# created_at :datetime
# updated_at :datetime
#
class
Sub1
::
User
<
ActiveRecord
::
Base
end
spec/integration/rails_4.1.1/app/models/task.rb
View file @
026cee5a
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# content :string(255)
# count :integer default(0)
# status :boolean default(FALSE)
# created_at :datetime
# updated_at :datetime
#
class
Task
<
ActiveRecord
::
Base
enum
status:
%w(normal active completed)
end
spec/integration/rails_4.1.1/db/migrate/20140526224112_create_tasks.rb
View file @
026cee5a
...
...
@@ -2,7 +2,8 @@ class CreateTasks < ActiveRecord::Migration
def
change
create_table
:tasks
do
|
t
|
t
.
string
:content
t
.
column
:status
,
:default
=>
0
t
.
integer
:count
,
:default
=>
0
t
.
boolean
:status
,
:default
=>
0
t
.
timestamps
end
end
...
...
spec/integration/rails_4.1.1/db/schema.rb
View file @
026cee5a
...
...
@@ -21,6 +21,8 @@ ActiveRecord::Schema.define(version: 20140705000010) do
create_table
"tasks"
,
force:
true
do
|
t
|
t
.
string
"content"
t
.
integer
"count"
,
default:
0
t
.
boolean
"status"
,
default:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
...
...
spec/integration/rails_4.1.1/test/models/task_test.rb
View file @
026cee5a
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# content :string(255)
# count :integer default(0)
# status :boolean default(FALSE)
# created_at :datetime
# updated_at :datetime
#
require
'test_helper'
class
TaskTest
<
ActiveSupport
::
TestCase
...
...
spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb
View file @
026cee5a
# == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# content :string
# created_at :datetime
# updated_at :datetime
#
module
Sub1::Sub2::Sub3
class
Event
<
ActiveRecord
::
Base
end
...
...
spec/integration/rails_4.2.0/app/models/sub1/user.rb
View file @
026cee5a
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# content :string
# created_at :datetime
# updated_at :datetime
#
class
Sub1
::
User
<
ActiveRecord
::
Base
end
spec/integration/rails_4.2.0/app/models/task.rb
View file @
026cee5a
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# content :string
# count :integer default(0)
# status :boolean default(FALSE)
# created_at :datetime
# updated_at :datetime
#
class
Task
<
ActiveRecord
::
Base
enum
status:
%w(normal active completed)
end
spec/integration/rails_4.2.0/db/migrate/20140526224112_create_tasks.rb
View file @
026cee5a
...
...
@@ -2,7 +2,8 @@ class CreateTasks < ActiveRecord::Migration
def
change
create_table
:tasks
do
|
t
|
t
.
string
:content
t
.
column
:status
,
:default
=>
0
t
.
integer
:count
,
default:
0
t
.
boolean
:status
,
default:
0
t
.
timestamps
end
end
...
...
spec/integration/rails_4.2.0/db/schema.rb
View file @
026cee5a
...
...
@@ -13,19 +13,21 @@
ActiveRecord
::
Schema
.
define
(
version:
20140705000010
)
do
create_table
"events"
,
force:
tru
e
do
|
t
|
create_table
"events"
,
force:
:cascad
e
do
|
t
|
t
.
string
"content"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
create_table
"tasks"
,
force:
tru
e
do
|
t
|
create_table
"tasks"
,
force:
:cascad
e
do
|
t
|
t
.
string
"content"
t
.
integer
"count"
,
default:
0
t
.
boolean
"status"
,
default:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
create_table
"users"
,
force:
tru
e
do
|
t
|
create_table
"users"
,
force:
:cascad
e
do
|
t
|
t
.
string
"content"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
...
...
spec/integration/rails_4.2.0/test/models/task_test.rb
View file @
026cee5a
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# content :string
# count :integer default(0)
# status :boolean default(FALSE)
# created_at :datetime
# updated_at :datetime
#
require
'test_helper'
class
TaskTest
<
ActiveSupport
::
TestCase
...
...
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