Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
92c00d75
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92c00d75
编写于
7月 21, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AMo conversion helper
上级
6944b391
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
53 addition
and
55 deletion
+53
-55
actionpack/test/activerecord/render_partial_with_record_identification_test.rb
...erecord/render_partial_with_record_identification_test.rb
+2
-1
actionpack/test/controller/record_identifier_test.rb
actionpack/test/controller/record_identifier_test.rb
+2
-1
actionpack/test/controller/redirect_test.rb
actionpack/test/controller/redirect_test.rb
+2
-1
actionpack/test/lib/controller/fake_models.rb
actionpack/test/lib/controller/fake_models.rb
+4
-2
actionpack/test/template/active_record_helper_test.rb
actionpack/test/template/active_record_helper_test.rb
+6
-3
actionpack/test/template/atom_feed_helper_test.rb
actionpack/test/template/atom_feed_helper_test.rb
+2
-1
actionpack/test/template/form_helper_test.rb
actionpack/test/template/form_helper_test.rb
+10
-5
actionpack/test/template/prototype_helper_test.rb
actionpack/test/template/prototype_helper_test.rb
+8
-4
actionpack/test/template/record_tag_helper_test.rb
actionpack/test/template/record_tag_helper_test.rb
+2
-1
actionpack/test/template/test_test.rb
actionpack/test/template/test_test.rb
+1
-1
actionpack/test/template/url_helper_test.rb
actionpack/test/template/url_helper_test.rb
+4
-2
activemodel/lib/active_model.rb
activemodel/lib/active_model.rb
+1
-1
activemodel/lib/active_model/api_compliant.rb
activemodel/lib/active_model/api_compliant.rb
+0
-25
activemodel/lib/active_model/conversion.rb
activemodel/lib/active_model/conversion.rb
+8
-0
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+1
-7
未找到文件。
actionpack/test/activerecord/render_partial_with_record_identification_test.rb
浏览文件 @
92c00d75
...
@@ -126,7 +126,8 @@ def render_with_record_collection
...
@@ -126,7 +126,8 @@ def render_with_record_collection
end
end
class
Game
<
Struct
.
new
(
:name
,
:id
)
class
Game
<
Struct
.
new
(
:name
,
:id
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
def
to_param
def
to_param
id
.
to_s
id
.
to_s
end
end
...
...
actionpack/test/controller/record_identifier_test.rb
浏览文件 @
92c00d75
require
'abstract_unit'
require
'abstract_unit'
class
Comment
class
Comment
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
def
save
;
@id
=
1
end
def
save
;
@id
=
1
end
...
...
actionpack/test/controller/redirect_test.rb
浏览文件 @
92c00d75
...
@@ -4,7 +4,8 @@ class WorkshopsController < ActionController::Base
...
@@ -4,7 +4,8 @@ class WorkshopsController < ActionController::Base
end
end
class
Workshop
class
Workshop
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_accessor
:id
,
:new_record
attr_accessor
:id
,
:new_record
def
initialize
(
id
,
new_record
)
def
initialize
(
id
,
new_record
)
...
...
actionpack/test/lib/controller/fake_models.rb
浏览文件 @
92c00d75
require
"active_model"
require
"active_model"
class
Customer
<
Struct
.
new
(
:name
,
:id
)
class
Customer
<
Struct
.
new
(
:name
,
:id
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
def
to_param
def
to_param
id
.
to_s
id
.
to_s
...
@@ -16,7 +17,8 @@ class GoodCustomer < Customer
...
@@ -16,7 +17,8 @@ class GoodCustomer < Customer
module
Quiz
module
Quiz
class
Question
<
Struct
.
new
(
:name
,
:id
)
class
Question
<
Struct
.
new
(
:name
,
:id
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
def
to_param
def
to_param
id
.
to_s
id
.
to_s
...
...
actionpack/test/template/active_record_helper_test.rb
浏览文件 @
92c00d75
...
@@ -5,15 +5,18 @@ class ActiveRecordHelperTest < ActionView::TestCase
...
@@ -5,15 +5,18 @@ class ActiveRecordHelperTest < ActionView::TestCase
silence_warnings
do
silence_warnings
do
class
Post
<
Struct
.
new
(
:title
,
:author_name
,
:body
,
:secret
,
:written_on
)
class
Post
<
Struct
.
new
(
:title
,
:author_name
,
:body
,
:secret
,
:written_on
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
end
end
class
User
<
Struct
.
new
(
:email
)
class
User
<
Struct
.
new
(
:email
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
end
end
class
Column
<
Struct
.
new
(
:type
,
:name
,
:human_name
)
class
Column
<
Struct
.
new
(
:type
,
:name
,
:human_name
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
end
end
end
end
...
...
actionpack/test/template/atom_feed_helper_test.rb
浏览文件 @
92c00d75
require
'abstract_unit'
require
'abstract_unit'
class
Scroll
<
Struct
.
new
(
:id
,
:to_param
,
:title
,
:body
,
:updated_at
,
:created_at
)
class
Scroll
<
Struct
.
new
(
:id
,
:to_param
,
:title
,
:body
,
:updated_at
,
:created_at
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
def
new_record?
def
new_record?
true
true
...
...
actionpack/test/template/form_helper_test.rb
浏览文件 @
92c00d75
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
silence_warnings
do
silence_warnings
do
class
Post
<
Struct
.
new
(
:title
,
:author_name
,
:body
,
:secret
,
:written_on
,
:cost
)
class
Post
<
Struct
.
new
(
:title
,
:author_name
,
:body
,
:secret
,
:written_on
,
:cost
)
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
alias_method
:secret?
,
:secret
alias_method
:secret?
,
:secret
...
@@ -25,7 +26,8 @@ def tags_attributes=(attributes); end
...
@@ -25,7 +26,8 @@ def tags_attributes=(attributes); end
end
end
class
Comment
class
Comment
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
attr_reader
:post_id
attr_reader
:post_id
...
@@ -43,7 +45,8 @@ def relevances_attributes=(attributes); end
...
@@ -43,7 +45,8 @@ def relevances_attributes=(attributes); end
end
end
class
Tag
class
Tag
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
attr_reader
:post_id
attr_reader
:post_id
...
@@ -61,7 +64,8 @@ def relevances_attributes=(attributes); end
...
@@ -61,7 +64,8 @@ def relevances_attributes=(attributes); end
end
end
class
CommentRelevance
class
CommentRelevance
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
attr_reader
:comment_id
attr_reader
:comment_id
...
@@ -75,7 +79,8 @@ def value
...
@@ -75,7 +79,8 @@ def value
end
end
class
TagRelevance
class
TagRelevance
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
attr_reader
:tag_id
attr_reader
:tag_id
...
...
actionpack/test/template/prototype_helper_test.rb
浏览文件 @
92c00d75
require
'abstract_unit'
require
'abstract_unit'
require
'active_model'
require
'active_model'
Bunny
=
Struct
.
new
(
:Bunny
,
:id
)
class
Bunny
<
Struct
.
new
(
:Bunny
,
:id
)
Bunny
.
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
end
class
Author
class
Author
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
def
save
;
@id
=
1
end
def
save
;
@id
=
1
end
...
@@ -16,7 +19,8 @@ def name
...
@@ -16,7 +19,8 @@ def name
end
end
class
Article
class
Article
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_reader
:id
attr_reader
:id
attr_reader
:author_id
attr_reader
:author_id
def
save
;
@id
=
1
;
@author_id
=
1
end
def
save
;
@id
=
1
;
@author_id
=
1
end
...
...
actionpack/test/template/record_tag_helper_test.rb
浏览文件 @
92c00d75
require
'abstract_unit'
require
'abstract_unit'
class
Post
class
Post
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
def
id
def
id
45
45
end
end
...
...
actionpack/test/template/test_test.rb
浏览文件 @
92c00d75
...
@@ -41,7 +41,7 @@ def test_homepage_url
...
@@ -41,7 +41,7 @@ def test_homepage_url
def
test_link_to_person
def
test_link_to_person
person
=
mock
(
:name
=>
"David"
)
person
=
mock
(
:name
=>
"David"
)
person
.
class
.
extend
ActiveModel
::
APICompliant
person
.
class
.
extend
ActiveModel
::
Naming
expects
(
:mocha_mock_path
).
with
(
person
).
returns
(
"/people/1"
)
expects
(
:mocha_mock_path
).
with
(
person
).
returns
(
"/people/1"
)
assert_equal
'<a href="/people/1">David</a>'
,
link_to_person
(
person
)
assert_equal
'<a href="/people/1">David</a>'
,
link_to_person
(
person
)
end
end
...
...
actionpack/test/template/url_helper_test.rb
浏览文件 @
92c00d75
...
@@ -494,7 +494,8 @@ def with_restful_routing
...
@@ -494,7 +494,8 @@ def with_restful_routing
end
end
class
Workshop
class
Workshop
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_accessor
:id
,
:new_record
attr_accessor
:id
,
:new_record
def
initialize
(
id
,
new_record
)
def
initialize
(
id
,
new_record
)
...
@@ -511,7 +512,8 @@ def to_s
...
@@ -511,7 +512,8 @@ def to_s
end
end
class
Session
class
Session
extend
ActiveModel
::
APICompliant
extend
ActiveModel
::
Naming
include
ActiveModel
::
Conversion
attr_accessor
:id
,
:workshop_id
,
:new_record
attr_accessor
:id
,
:workshop_id
,
:new_record
def
initialize
(
id
,
new_record
)
def
initialize
(
id
,
new_record
)
...
...
activemodel/lib/active_model.rb
浏览文件 @
92c00d75
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
require
'active_support'
require
'active_support'
module
ActiveModel
module
ActiveModel
autoload
:
APICompliant
,
'active_model/api_compliant
'
autoload
:
Conversion
,
'active_model/conversion
'
autoload
:DeprecatedErrorMethods
,
'active_model/deprecated_error_methods'
autoload
:DeprecatedErrorMethods
,
'active_model/deprecated_error_methods'
autoload
:Errors
,
'active_model/errors'
autoload
:Errors
,
'active_model/errors'
autoload
:Name
,
'active_model/naming'
autoload
:Name
,
'active_model/naming'
...
...
activemodel/lib/active_model/api_compliant.rb
已删除
100644 → 0
浏览文件 @
6944b391
module
ActiveModel
module
APICompliant
include
Naming
def
self
.
extended
(
klass
)
klass
.
class_eval
do
include
Validations
include
InstanceMethods
end
end
module
InstanceMethods
def
to_model
if
respond_to?
(
:new_record?
)
self
.
class
.
class_eval
{
def
to_model
()
self
end
}
to_model
else
raise
"In order to be ActiveModel API compliant, you need to define "
\
"a new_record? method, which should return true if it has not "
\
"yet been persisted."
end
end
end
end
end
\ No newline at end of file
activemodel/lib/active_model/conversion.rb
0 → 100644
浏览文件 @
92c00d75
module
ActiveModel
# Include ActiveModel::Conversion if your object "acts like an ActiveModel model".
module
Conversion
def
to_model
self
end
end
end
activerecord/lib/active_record/base.rb
浏览文件 @
92c00d75
...
@@ -2511,13 +2511,6 @@ def to_param
...
@@ -2511,13 +2511,6 @@ def to_param
(
id
=
self
.
id
)
?
id
.
to_s
:
nil
# Be sure to stringify the id for routes
(
id
=
self
.
id
)
?
id
.
to_s
:
nil
# Be sure to stringify the id for routes
end
end
# Returns the ActiveRecord object when asked for its
# ActiveModel-compliant representation, because ActiveRecord is
# ActiveModel-compliant.
def
to_model
self
end
# Returns a cache key that can be used to identify this record.
# Returns a cache key that can be used to identify this record.
#
#
# ==== Examples
# ==== Examples
...
@@ -3186,6 +3179,7 @@ def clone_attribute_value(reader_method, attribute_name)
...
@@ -3186,6 +3179,7 @@ def clone_attribute_value(reader_method, attribute_name)
include
Dirty
include
Dirty
include
Callbacks
,
ActiveModel
::
Observing
,
Timestamp
include
Callbacks
,
ActiveModel
::
Observing
,
Timestamp
include
Associations
,
AssociationPreload
,
NamedScope
include
Associations
,
AssociationPreload
,
NamedScope
include
ActiveModel
::
Conversion
# AutosaveAssociation needs to be included before Transactions, because we want
# AutosaveAssociation needs to be included before Transactions, because we want
# #save_with_autosave_associations to be wrapped inside a transaction.
# #save_with_autosave_associations to be wrapped inside a transaction.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录