Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
53e2e8ef
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,发现更多精彩内容 >>
提交
53e2e8ef
编写于
8月 23, 2008
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into i18n
上级
23fb26a0
c471f13d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
90 addition
and
42 deletion
+90
-42
actionpack/test/template/url_helper_test.rb
actionpack/test/template/url_helper_test.rb
+1
-0
activerecord/lib/active_record/associations/association_proxy.rb
...ecord/lib/active_record/associations/association_proxy.rb
+1
-1
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
..._record/connection_adapters/abstract/schema_statements.rb
+2
-6
activerecord/test/cases/column_definition_test.rb
activerecord/test/cases/column_definition_test.rb
+4
-4
activesupport/lib/active_support/inflector.rb
activesupport/lib/active_support/inflector.rb
+45
-24
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
+2
-2
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
...b/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
+5
-5
activesupport/test/inflector_test.rb
activesupport/test/inflector_test.rb
+7
-0
railties/lib/rails_generator/generated_attribute.rb
railties/lib/rails_generator/generated_attribute.rb
+4
-0
railties/lib/rails_generator/generators/components/model/templates/model.rb
..._generator/generators/components/model/templates/model.rb
+3
-0
railties/test/generators/rails_model_generator_test.rb
railties/test/generators/rails_model_generator_test.rb
+16
-0
未找到文件。
actionpack/test/template/url_helper_test.rb
浏览文件 @
53e2e8ef
# encoding: utf-8
require
'abstract_unit'
RequestMock
=
Struct
.
new
(
"Request"
,
:request_uri
,
:protocol
,
:host_with_port
,
:env
)
...
...
activerecord/lib/active_record/associations/association_proxy.rb
浏览文件 @
53e2e8ef
...
...
@@ -213,7 +213,7 @@ def raise_on_type_mismatch(record)
# Array#flatten has problems with recursive arrays. Going one level deeper solves the majority of the problems.
def
flatten_deeper
(
array
)
array
.
collect
{
|
element
|
element
.
respond_to?
(
:flatten
)
?
element
.
flatten
:
element
}.
flatten
array
.
collect
{
|
element
|
(
element
.
respond_to?
(
:flatten
)
&&
!
element
.
is_a?
(
Hash
)
)
?
element
.
flatten
:
element
}.
flatten
end
def
owner_quoted_id
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
浏览文件 @
53e2e8ef
...
...
@@ -384,12 +384,8 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
def
add_column_options!
(
sql
,
options
)
#:nodoc:
sql
<<
" DEFAULT
#{
quote
(
options
[
:default
],
options
[
:column
])
}
"
if
options_include_default?
(
options
)
# must explicitly check for :null to allow change_column to work on migrations
if
options
.
has_key?
:null
if
options
[
:null
]
==
false
sql
<<
" NOT NULL"
else
sql
<<
" NULL"
end
if
options
[
:null
]
==
false
sql
<<
" NOT NULL"
end
end
...
...
activerecord/test/cases/column_definition_test.rb
浏览文件 @
53e2e8ef
...
...
@@ -9,13 +9,13 @@ def @adapter.native_database_types
end
# Avoid column definitions in create table statements like:
# `title` varchar(255) DEFAULT NULL
NULL
# `title` varchar(255) DEFAULT NULL
def
test_should_not_include_default_clause_when_default_is_null
column
=
ActiveRecord
::
ConnectionAdapters
::
Column
.
new
(
"title"
,
nil
,
"varchar(20)"
)
column_def
=
ActiveRecord
::
ConnectionAdapters
::
ColumnDefinition
.
new
(
@adapter
,
column
.
name
,
"string"
,
column
.
limit
,
column
.
precision
,
column
.
scale
,
column
.
default
,
column
.
null
)
assert_equal
"title varchar(20)
NULL
"
,
column_def
.
to_sql
assert_equal
"title varchar(20)"
,
column_def
.
to_sql
end
def
test_should_include_default_clause_when_default_is_present
...
...
@@ -23,7 +23,7 @@ def test_should_include_default_clause_when_default_is_present
column_def
=
ActiveRecord
::
ConnectionAdapters
::
ColumnDefinition
.
new
(
@adapter
,
column
.
name
,
"string"
,
column
.
limit
,
column
.
precision
,
column
.
scale
,
column
.
default
,
column
.
null
)
assert_equal
%Q{title varchar(20) DEFAULT 'Hello'
NULL
}
,
column_def
.
to_sql
assert_equal
%Q{title varchar(20) DEFAULT 'Hello'}
,
column_def
.
to_sql
end
def
test_should_specify_not_null_if_null_option_is_false
...
...
@@ -33,4 +33,4 @@ def test_should_specify_not_null_if_null_option_is_false
column
.
limit
,
column
.
precision
,
column
.
scale
,
column
.
default
,
column
.
null
)
assert_equal
%Q{title varchar(20) DEFAULT 'Hello' NOT NULL}
,
column_def
.
to_sql
end
end
\ No newline at end of file
end
activesupport/lib/active_support/inflector.rb
浏览文件 @
53e2e8ef
...
...
@@ -39,12 +39,16 @@ def initialize
# Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
# The replacement should always be a string that may include references to the matched data from the rule.
def
plural
(
rule
,
replacement
)
@uncountables
.
delete
(
rule
)
if
rule
.
is_a?
(
String
)
@uncountables
.
delete
(
replacement
)
@plurals
.
insert
(
0
,
[
rule
,
replacement
])
end
# Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
# The replacement should always be a string that may include references to the matched data from the rule.
def
singular
(
rule
,
replacement
)
@uncountables
.
delete
(
rule
)
if
rule
.
is_a?
(
String
)
@uncountables
.
delete
(
replacement
)
@singulars
.
insert
(
0
,
[
rule
,
replacement
])
end
...
...
@@ -55,6 +59,8 @@ def singular(rule, replacement)
# irregular 'octopus', 'octopi'
# irregular 'person', 'people'
def
irregular
(
singular
,
plural
)
@uncountables
.
delete
(
singular
)
@uncountables
.
delete
(
plural
)
if
singular
[
0
,
1
].
upcase
==
plural
[
0
,
1
].
upcase
plural
(
Regexp
.
new
(
"(
#{
singular
[
0
,
1
]
}
)
#{
singular
[
1
..-
1
]
}
$"
,
"i"
),
'\1'
+
plural
[
1
..-
1
])
singular
(
Regexp
.
new
(
"(
#{
plural
[
0
,
1
]
}
)
#{
plural
[
1
..-
1
]
}
$"
,
"i"
),
'\1'
+
singular
[
1
..-
1
])
...
...
@@ -273,32 +279,47 @@ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
underscore
(
demodulize
(
class_name
))
+
(
separate_class_name_and_id_with_underscore
?
"_id"
:
"id"
)
end
# Tries to find a constant with the name specified in the argument string:
#
# "Module".constantize # => Module
# "Test::Unit".constantize # => Test::Unit
#
# The name is assumed to be the one of a top-level constant, no matter whether
# it starts with "::" or not. No lexical context is taken into account:
#
# C = 'outside'
# module M
# C = 'inside'
# C # => 'inside'
# "C".constantize # => 'outside', same as ::C
# end
#
# NameError is raised when the name is not in CamelCase or the constant is
# unknown.
def
constantize
(
camel_cased_word
)
names
=
camel_cased_word
.
split
(
'::'
)
names
.
shift
if
names
.
empty?
||
names
.
first
.
empty?
# Ruby 1.9 introduces an inherit argument for Module#const_get and
# #const_defined? and changes their default behavior.
if
Module
.
method
(
:const_get
).
arity
==
1
# Tries to find a constant with the name specified in the argument string:
#
# "Module".constantize # => Module
# "Test::Unit".constantize # => Test::Unit
#
# The name is assumed to be the one of a top-level constant, no matter whether
# it starts with "::" or not. No lexical context is taken into account:
#
# C = 'outside'
# module M
# C = 'inside'
# C # => 'inside'
# "C".constantize # => 'outside', same as ::C
# end
#
# NameError is raised when the name is not in CamelCase or the constant is
# unknown.
def
constantize
(
camel_cased_word
)
names
=
camel_cased_word
.
split
(
'::'
)
names
.
shift
if
names
.
empty?
||
names
.
first
.
empty?
constant
=
Object
names
.
each
do
|
name
|
constant
=
constant
.
const_defined?
(
name
)
?
constant
.
const_get
(
name
)
:
constant
.
const_missing
(
name
)
end
constant
end
else
def
constantize
(
camel_cased_word
)
#:nodoc:
names
=
camel_cased_word
.
split
(
'::'
)
names
.
shift
if
names
.
empty?
||
names
.
first
.
empty?
constant
=
Object
names
.
each
do
|
name
|
constant
=
constant
.
const_defined?
(
name
)
?
constant
.
const_get
(
name
)
:
constant
.
const_missing
(
name
)
constant
=
Object
names
.
each
do
|
name
|
constant
=
constant
.
const_get
(
name
,
false
)
||
constant
.
const_missing
(
name
)
end
constant
end
constant
end
# Turns a number into an ordinal string used to denote the position in an
...
...
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
浏览文件 @
53e2e8ef
...
...
@@ -183,8 +183,8 @@ def default_exception_handler(exception, locale, key, options)
# keys are Symbols.
def
normalize_translation_keys
(
locale
,
key
,
scope
)
keys
=
[
locale
]
+
Array
(
scope
)
+
[
key
]
keys
=
keys
.
map
{
|
k
ey
|
key
.
to_s
.
split
(
/\./
)
}
keys
.
flatten
.
map
{
|
k
ey
|
key
.
to_sym
}
keys
=
keys
.
map
{
|
k
|
k
.
to_s
.
split
(
/\./
)
}
keys
.
flatten
.
map
{
|
k
|
k
.
to_sym
}
end
end
end
...
...
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
浏览文件 @
53e2e8ef
...
...
@@ -27,7 +27,7 @@ def store_translations(locale, data)
def
translate
(
locale
,
key
,
options
=
{})
raise
InvalidLocale
.
new
(
locale
)
if
locale
.
nil?
return
key
.
map
{
|
k
ey
|
translate
locale
,
key
,
options
}
if
key
.
is_a?
Array
return
key
.
map
{
|
k
|
translate
locale
,
k
,
options
}
if
key
.
is_a?
Array
reserved
=
:scope
,
:default
count
,
scope
,
default
=
options
.
values_at
(
:count
,
*
reserved
)
...
...
@@ -74,7 +74,7 @@ def translations
def
lookup
(
locale
,
key
,
scope
=
[])
return
unless
key
keys
=
I18n
.
send
:normalize_translation_keys
,
locale
,
key
,
scope
keys
.
inject
(
translations
){
|
result
,
k
ey
|
result
[
key
.
to_sym
]
or
return
nil
}
keys
.
inject
(
translations
){
|
result
,
k
|
result
[
k
.
to_sym
]
or
return
nil
}
end
# Evaluates a default translation.
...
...
@@ -147,9 +147,9 @@ def load_file(filename)
type
=
File
.
extname
(
filename
).
tr
(
'.'
,
''
).
downcase
raise
UnknownFileType
.
new
(
type
,
filename
)
unless
respond_to?
:"load_
#{
type
}
"
data
=
send
:"load_
#{
type
}
"
,
filename
# TODO raise a meaningful exception if this does not yield a Hash
data
.
each
do
|
locale
,
d
ata
|
merge_translations
locale
,
d
ata
end
data
.
each
do
|
locale
,
d
|
merge_translations
locale
,
d
end
end
# Loads a plain Ruby translations file. eval'ing the file must yield
...
...
activesupport/test/inflector_test.rb
浏览文件 @
53e2e8ef
...
...
@@ -34,6 +34,13 @@ def test_pluralize_empty_string
end
end
def
test_overwrite_previous_inflectors
assert_equal
(
"series"
,
ActiveSupport
::
Inflector
.
singularize
(
"series"
))
ActiveSupport
::
Inflector
.
inflections
.
singular
"series"
,
"serie"
assert_equal
(
"serie"
,
ActiveSupport
::
Inflector
.
singularize
(
"series"
))
ActiveSupport
::
Inflector
.
inflections
.
uncountable
"series"
# Return to normal
end
MixtureToTitleCase
.
each
do
|
before
,
titleized
|
define_method
"test_titleize_
#{
before
}
"
do
assert_equal
(
titleized
,
ActiveSupport
::
Inflector
.
titleize
(
before
))
...
...
railties/lib/rails_generator/generated_attribute.rb
浏览文件 @
53e2e8ef
...
...
@@ -37,6 +37,10 @@ def default
""
end
end
def
reference?
[
:references
,
:belongs_to
].
include?
(
self
.
type
)
end
end
end
end
railties/lib/rails_generator/generators/components/model/templates/model.rb
浏览文件 @
53e2e8ef
class
<
%= class_name %> < ActiveRecord::Base
<% attributes.select(&:reference?).each do |attribute| -%>
belongs_to :<%=
attribute
.
name
%>
<% end -%>
end
railties/test/generators/rails_model_generator_test.rb
浏览文件 @
53e2e8ef
...
...
@@ -29,4 +29,20 @@ def test_model_with_attributes_generates_resources_with_attributes
assert_generated_column
t
,
:created_at
,
:timestamp
end
end
def
test_model_with_reference_attributes_generates_belongs_to_associations
run_generator
(
'model'
,
%w(Product name:string supplier:references)
)
assert_generated_model_for
:product
do
|
body
|
assert
body
=~
/^\s+belongs_to :supplier/
,
"
#{
body
.
inspect
}
should contain 'belongs_to :supplier'"
end
end
def
test_model_with_belongs_to_attributes_generates_belongs_to_associations
run_generator
(
'model'
,
%w(Product name:string supplier:belongs_to)
)
assert_generated_model_for
:product
do
|
body
|
assert
body
=~
/^\s+belongs_to :supplier/
,
"
#{
body
.
inspect
}
should contain 'belongs_to :supplier'"
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录