Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
83dd6e1e
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,发现更多精彩内容 >>
提交
83dd6e1e
编写于
2月 11, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
favor composition over inheritence. use AS::OrderedHash rather than omap
上级
b17d8d72
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
20 deletion
+25
-20
activerecord/lib/active_record/fixtures.rb
activerecord/lib/active_record/fixtures.rb
+24
-19
activerecord/test/cases/fixtures_test.rb
activerecord/test/cases/fixtures_test.rb
+1
-1
未找到文件。
activerecord/lib/active_record/fixtures.rb
浏览文件 @
83dd6e1e
...
...
@@ -12,15 +12,7 @@
require
'active_support/core_ext/array/wrap'
require
'active_support/core_ext/object/blank'
require
'active_support/core_ext/logger'
if
RUBY_VERSION
<
'1.9'
module
YAML
#:nodoc:
class
Omap
#:nodoc:
def
keys
;
map
{
|
k
,
v
|
k
}
end
def
values
;
map
{
|
k
,
v
|
v
}
end
end
end
end
require
'active_support/ordered_hash'
if
defined?
ActiveRecord
class
FixtureClassNotFound
<
ActiveRecord
::
ActiveRecordError
#:nodoc:
...
...
@@ -452,7 +444,7 @@ class FixturesFileNotFound < StandardError; end
#
# Any fixture labeled "DEFAULTS" is safely ignored.
class
Fixtures
<
(
RUBY_VERSION
<
'1.9'
?
YAML
::
Omap
:
Hash
)
class
Fixtures
MAX_ID
=
2
**
30
-
1
DEFAULT_FILTER_RE
=
/\.ya?ml$/
...
...
@@ -552,9 +544,10 @@ def self.identify(label)
Zlib
.
crc32
(
label
.
to_s
)
%
MAX_ID
end
attr_reader
:table_name
,
:name
attr_reader
:table_name
,
:name
,
:fixtures
def
initialize
(
connection
,
table_name
,
class_name
,
fixture_path
,
file_filter
=
DEFAULT_FILTER_RE
)
@fixtures
=
ActiveSupport
::
OrderedHash
.
new
@connection
,
@table_name
,
@fixture_path
,
@file_filter
=
connection
,
table_name
,
fixture_path
,
file_filter
@name
=
table_name
# preserve fixture base name
@class_name
=
class_name
||
...
...
@@ -565,6 +558,22 @@ def initialize(connection, table_name, class_name, fixture_path, file_filter = D
read_fixture_files
end
def
[]
(
x
)
fixtures
[
x
]
end
def
[]=
(
k
,
v
)
fixtures
[
k
]
=
v
end
def
each
(
&
block
)
fixtures
.
each
(
&
block
)
end
def
size
fixtures
.
size
end
def
delete_existing_fixtures
@connection
.
delete
"DELETE FROM
#{
@connection
.
quote_table_name
(
table_name
)
}
"
,
'Fixture Delete'
end
...
...
@@ -574,18 +583,14 @@ def insert_fixtures
now
=
now
.
to_s
(
:db
)
# allow a standard key to be used for doing defaults in YAML
if
is_a?
(
Hash
)
delete
(
'DEFAULTS'
)
else
delete
(
assoc
(
'DEFAULTS'
))
end
fixtures
.
delete
(
'DEFAULTS'
)
# track any join tables we need to insert later
habtm_fixtures
=
Hash
.
new
do
|
h
,
habtm
|
h
[
habtm
]
=
HabtmFixtures
.
new
(
@connection
,
habtm
.
options
[
:join_table
],
nil
,
nil
)
end
each
do
|
label
,
fixture
|
fixtures
.
each
do
|
label
,
fixture
|
row
=
fixture
.
to_hash
if
model_class
&&
model_class
<
ActiveRecord
::
Base
...
...
@@ -725,7 +730,7 @@ def read_yaml_fixture_files
raise
Fixture
::
FormatError
,
"Bad data for
#{
@class_name
}
fixture named
#{
name
}
(nil)"
end
self
[
name
]
=
Fixture
.
new
(
data
,
model_class
,
@connection
)
fixtures
[
name
]
=
Fixture
.
new
(
data
,
model_class
,
@connection
)
end
end
end
...
...
@@ -738,7 +743,7 @@ def read_csv_fixture_files
reader
.
each
do
|
row
|
data
=
{}
row
.
each_with_index
{
|
cell
,
j
|
data
[
header
[
j
].
to_s
.
strip
]
=
cell
.
to_s
.
strip
}
self
[
"
#{
@class_name
.
to_s
.
underscore
}
_
#{
i
+=
1
}
"
]
=
Fixture
.
new
(
data
,
model_class
,
@connection
)
fixtures
[
"
#{
@class_name
.
to_s
.
underscore
}
_
#{
i
+=
1
}
"
]
=
Fixture
.
new
(
data
,
model_class
,
@connection
)
end
end
...
...
activerecord/test/cases/fixtures_test.rb
浏览文件 @
83dd6e1e
...
...
@@ -245,7 +245,7 @@ def test_resets_to_min_pk_with_default_pk_and_sequence
def
test_create_fixtures_resets_sequences_when_not_cached
@instances
.
each
do
|
instance
|
max_id
=
create_fixtures
(
instance
.
class
.
table_name
).
inject
(
0
)
do
|
_max_id
,
(
_
,
fixture
)
|
max_id
=
create_fixtures
(
instance
.
class
.
table_name
).
fixtures
.
inject
(
0
)
do
|
_max_id
,
(
_
,
fixture
)
|
fixture_id
=
fixture
[
'id'
].
to_i
fixture_id
>
_max_id
?
fixture_id
:
_max_id
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录