Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
820b6f3d
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,体验更适合开发者的 AI 搜索 >>
提交
820b6f3d
编写于
5月 07, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #442 from jasonnoble/namespace_fixtures
Namespace Fixtures in ActiveRecord
上级
0ef978d1
e5c18ff2
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
323 addition
and
318 deletion
+323
-318
activerecord/lib/active_record/fixtures.rb
activerecord/lib/active_record/fixtures.rb
+290
-285
activerecord/lib/active_record/railties/databases.rake
activerecord/lib/active_record/railties/databases.rake
+3
-3
activerecord/test/cases/adapters/mysql/reserved_word_test.rb
activerecord/test/cases/adapters/mysql/reserved_word_test.rb
+1
-1
activerecord/test/cases/adapters/mysql2/reserved_word_test.rb
...verecord/test/cases/adapters/mysql2/reserved_word_test.rb
+1
-1
activerecord/test/cases/fixtures_test.rb
activerecord/test/cases/fixtures_test.rb
+21
-21
activerecord/test/cases/helper.rb
activerecord/test/cases/helper.rb
+1
-1
activerecord/test/fixtures/mateys.yml
activerecord/test/fixtures/mateys.yml
+2
-2
activerecord/test/fixtures/parrots_pirates.yml
activerecord/test/fixtures/parrots_pirates.yml
+4
-4
未找到文件。
activerecord/lib/active_record/fixtures.rb
浏览文件 @
820b6f3d
此差异已折叠。
点击以展开。
activerecord/lib/active_record/railties/databases.rake
浏览文件 @
820b6f3d
...
...
@@ -305,7 +305,7 @@ db_namespace = namespace :db do
fixtures_dir
=
File
.
join
[
base_dir
,
ENV
[
'FIXTURES_DIR'
]].
compact
(
ENV
[
'FIXTURES'
]
?
ENV
[
'FIXTURES'
].
split
(
/,/
)
:
Dir
[
"
#{
fixtures_dir
}
/**/*.{yml,csv}"
].
map
{
|
f
|
f
[(
fixtures_dir
.
size
+
1
)
..-
5
]
}).
each
do
|
fixture_file
|
Fixtures
.
create_fixtures
(
fixtures_dir
,
fixture_file
)
ActiveRecord
::
Fixtures
.
create_fixtures
(
fixtures_dir
,
fixture_file
)
end
end
...
...
@@ -316,13 +316,13 @@ db_namespace = namespace :db do
label
,
id
=
ENV
[
'LABEL'
],
ENV
[
'ID'
]
raise
'LABEL or ID required'
if
label
.
blank?
&&
id
.
blank?
puts
%Q(The fixture ID for "
#{
label
}
" is
#{
Fixtures
.
identify
(
label
)
}
.)
if
label
puts
%Q(The fixture ID for "
#{
label
}
" is
#{
ActiveRecord
::
Fixtures
.
identify
(
label
)
}
.)
if
label
base_dir
=
ENV
[
'FIXTURES_PATH'
]
?
File
.
join
(
Rails
.
root
,
ENV
[
'FIXTURES_PATH'
])
:
File
.
join
(
Rails
.
root
,
'test'
,
'fixtures'
)
Dir
[
"
#{
base_dir
}
/**/*.yml"
].
each
do
|
file
|
if
data
=
YAML
::
load
(
ERB
.
new
(
IO
.
read
(
file
)).
result
)
data
.
keys
.
each
do
|
key
|
key_id
=
Fixtures
.
identify
(
key
)
key_id
=
ActiveRecord
::
Fixtures
.
identify
(
key
)
if
key
==
label
||
key_id
==
id
.
to_i
puts
"
#{
file
}
:
#{
key
}
(
#{
key_id
}
)"
...
...
activerecord/test/cases/adapters/mysql/reserved_word_test.rb
浏览文件 @
820b6f3d
...
...
@@ -138,7 +138,7 @@ def test_associations_work_with_reserved_words
private
# custom fixture loader, uses Fixtures#create_fixtures and appends base_path to the current file's path
def
create_test_fixtures
(
*
fixture_names
)
Fixtures
.
create_fixtures
(
FIXTURES_ROOT
+
"/reserved_words"
,
fixture_names
)
ActiveRecord
::
Fixtures
.
create_fixtures
(
FIXTURES_ROOT
+
"/reserved_words"
,
fixture_names
)
end
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
...
...
activerecord/test/cases/adapters/mysql2/reserved_word_test.rb
浏览文件 @
820b6f3d
...
...
@@ -138,7 +138,7 @@ def test_associations_work_with_reserved_words
private
# custom fixture loader, uses Fixtures#create_fixtures and appends base_path to the current file's path
def
create_test_fixtures
(
*
fixture_names
)
Fixtures
.
create_fixtures
(
FIXTURES_ROOT
+
"/reserved_words"
,
fixture_names
)
ActiveRecord
::
Fixtures
.
create_fixtures
(
FIXTURES_ROOT
+
"/reserved_words"
,
fixture_names
)
end
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
...
...
activerecord/test/cases/fixtures_test.rb
浏览文件 @
820b6f3d
...
...
@@ -36,7 +36,7 @@ def test_clean_fixtures
FIXTURES
.
each
do
|
name
|
fixtures
=
nil
assert_nothing_raised
{
fixtures
=
create_fixtures
(
name
).
first
}
assert_kind_of
(
Fixtures
,
fixtures
)
assert_kind_of
(
ActiveRecord
::
Fixtures
,
fixtures
)
fixtures
.
each
{
|
_name
,
fixture
|
fixture
.
each
{
|
key
,
value
|
assert_match
(
MATCH_ATTRIBUTE_NAME
,
key
)
...
...
@@ -46,7 +46,7 @@ def test_clean_fixtures
end
def
test_create_fixtures
Fixtures
.
create_fixtures
(
FIXTURES_ROOT
,
"parrots"
)
ActiveRecord
::
Fixtures
.
create_fixtures
(
FIXTURES_ROOT
,
"parrots"
)
assert
Parrot
.
find_by_name
(
'Curious George'
),
'George is in the database'
end
...
...
@@ -54,7 +54,7 @@ def test_multiple_clean_fixtures
fixtures_array
=
nil
assert_nothing_raised
{
fixtures_array
=
create_fixtures
(
*
FIXTURES
)
}
assert_kind_of
(
Array
,
fixtures_array
)
fixtures_array
.
each
{
|
fixtures
|
assert_kind_of
(
Fixtures
,
fixtures
)
}
fixtures_array
.
each
{
|
fixtures
|
assert_kind_of
(
ActiveRecord
::
Fixtures
,
fixtures
)
}
end
def
test_attributes
...
...
@@ -75,7 +75,7 @@ def test_inserts
if
ActiveRecord
::
Base
.
connection
.
supports_migrations?
def
test_inserts_with_pre_and_suffix
# Reset cache to make finds on the new table work
Fixtures
.
reset_cache
ActiveRecord
::
Fixtures
.
reset_cache
ActiveRecord
::
Base
.
connection
.
create_table
:prefix_topics_suffix
do
|
t
|
t
.
column
:title
,
:string
...
...
@@ -150,11 +150,11 @@ def test_erb_in_fixtures
end
def
test_empty_yaml_fixture
assert_not_nil
Fixtures
.
new
(
Account
.
connection
,
"accounts"
,
'Account'
,
FIXTURES_ROOT
+
"/naked/yml/accounts"
)
assert_not_nil
ActiveRecord
::
Fixtures
.
new
(
Account
.
connection
,
"accounts"
,
'Account'
,
FIXTURES_ROOT
+
"/naked/yml/accounts"
)
end
def
test_empty_yaml_fixture_with_a_comment_in_it
assert_not_nil
Fixtures
.
new
(
Account
.
connection
,
"companies"
,
'Company'
,
FIXTURES_ROOT
+
"/naked/yml/companies"
)
assert_not_nil
ActiveRecord
::
Fixtures
.
new
(
Account
.
connection
,
"companies"
,
'Company'
,
FIXTURES_ROOT
+
"/naked/yml/companies"
)
end
def
test_nonexistent_fixture_file
...
...
@@ -164,23 +164,23 @@ def test_nonexistent_fixture_file
assert
Dir
[
nonexistent_fixture_path
+
"*"
].
empty?
assert_raise
(
FixturesFileNotFound
)
do
Fixtures
.
new
(
Account
.
connection
,
"companies"
,
'Company'
,
nonexistent_fixture_path
)
ActiveRecord
::
Fixtures
.
new
(
Account
.
connection
,
"companies"
,
'Company'
,
nonexistent_fixture_path
)
end
end
def
test_dirty_dirty_yaml_file
assert_raise
(
Fixture
::
FormatError
)
do
Fixtures
.
new
(
Account
.
connection
,
"courses"
,
'Course'
,
FIXTURES_ROOT
+
"/naked/yml/courses"
)
assert_raise
(
ActiveRecord
::
Fixture
::
FormatError
)
do
ActiveRecord
::
Fixtures
.
new
(
Account
.
connection
,
"courses"
,
'Course'
,
FIXTURES_ROOT
+
"/naked/yml/courses"
)
end
end
def
test_empty_csv_fixtures
assert_not_nil
Fixtures
.
new
(
Account
.
connection
,
"accounts"
,
'Account'
,
FIXTURES_ROOT
+
"/naked/csv/accounts"
)
assert_not_nil
ActiveRecord
::
Fixtures
.
new
(
Account
.
connection
,
"accounts"
,
'Account'
,
FIXTURES_ROOT
+
"/naked/csv/accounts"
)
end
def
test_omap_fixtures
assert_nothing_raised
do
fixtures
=
Fixtures
.
new
(
Account
.
connection
,
'categories'
,
'Category'
,
FIXTURES_ROOT
+
"/categories_ordered"
)
fixtures
=
ActiveRecord
::
Fixtures
.
new
(
Account
.
connection
,
'categories'
,
'Category'
,
FIXTURES_ROOT
+
"/categories_ordered"
)
i
=
0
fixtures
.
each
do
|
name
,
fixture
|
...
...
@@ -220,7 +220,7 @@ class FixturesResetPkSequenceTest < ActiveRecord::TestCase
def
setup
@instances
=
[
Account
.
new
(
:credit_limit
=>
50
),
Company
.
new
(
:name
=>
'RoR Consulting'
)]
Fixtures
.
reset_cache
# make sure tables get reinitialized
ActiveRecord
::
Fixtures
.
reset_cache
# make sure tables get reinitialized
end
def
test_resets_to_min_pk_with_specified_pk_and_sequence
...
...
@@ -524,13 +524,13 @@ class FasterFixturesTest < ActiveRecord::TestCase
def
load_extra_fixture
(
name
)
fixture
=
create_fixtures
(
name
).
first
assert
fixture
.
is_a?
(
Fixtures
)
assert
fixture
.
is_a?
(
ActiveRecord
::
Fixtures
)
@loaded_fixtures
[
fixture
.
table_name
]
=
fixture
end
def
test_cache
assert
Fixtures
.
fixture_is_cached?
(
ActiveRecord
::
Base
.
connection
,
'categories'
)
assert
Fixtures
.
fixture_is_cached?
(
ActiveRecord
::
Base
.
connection
,
'authors'
)
assert
ActiveRecord
::
Fixtures
.
fixture_is_cached?
(
ActiveRecord
::
Base
.
connection
,
'categories'
)
assert
ActiveRecord
::
Fixtures
.
fixture_is_cached?
(
ActiveRecord
::
Base
.
connection
,
'authors'
)
assert_no_queries
do
create_fixtures
(
'categories'
)
...
...
@@ -538,7 +538,7 @@ def test_cache
end
load_extra_fixture
(
'posts'
)
assert
Fixtures
.
fixture_is_cached?
(
ActiveRecord
::
Base
.
connection
,
'posts'
)
assert
ActiveRecord
::
Fixtures
.
fixture_is_cached?
(
ActiveRecord
::
Base
.
connection
,
'posts'
)
self
.
class
.
setup_fixture_accessors
(
'posts'
)
assert_equal
'Welcome to the weblog'
,
posts
(
:welcome
).
title
end
...
...
@@ -548,17 +548,17 @@ class FoxyFixturesTest < ActiveRecord::TestCase
fixtures
:parrots
,
:parrots_pirates
,
:pirates
,
:treasures
,
:mateys
,
:ships
,
:computers
,
:developers
,
:"admin/accounts"
,
:"admin/users"
def
test_identifies_strings
assert_equal
(
Fixtures
.
identify
(
"foo"
),
Fixtures
.
identify
(
"foo"
))
assert_not_equal
(
Fixtures
.
identify
(
"foo"
),
Fixtures
.
identify
(
"FOO"
))
assert_equal
(
ActiveRecord
::
Fixtures
.
identify
(
"foo"
),
ActiveRecord
::
Fixtures
.
identify
(
"foo"
))
assert_not_equal
(
ActiveRecord
::
Fixtures
.
identify
(
"foo"
),
ActiveRecord
::
Fixtures
.
identify
(
"FOO"
))
end
def
test_identifies_symbols
assert_equal
(
Fixtures
.
identify
(
:foo
),
Fixtures
.
identify
(
:foo
))
assert_equal
(
ActiveRecord
::
Fixtures
.
identify
(
:foo
),
ActiveRecord
::
Fixtures
.
identify
(
:foo
))
end
def
test_identifies_consistently
assert_equal
207281424
,
Fixtures
.
identify
(
:ruby
)
assert_equal
1066363776
,
Fixtures
.
identify
(
:sapphire_2
)
assert_equal
207281424
,
ActiveRecord
::
Fixtures
.
identify
(
:ruby
)
assert_equal
1066363776
,
ActiveRecord
::
Fixtures
.
identify
(
:sapphire_2
)
end
TIMESTAMP_COLUMNS
=
%w(created_at created_on updated_at updated_on)
...
...
activerecord/test/cases/helper.rb
浏览文件 @
820b6f3d
...
...
@@ -104,7 +104,7 @@ class ActiveSupport::TestCase
self
.
use_transactional_fixtures
=
true
def
create_fixtures
(
*
table_names
,
&
block
)
Fixtures
.
create_fixtures
(
ActiveSupport
::
TestCase
.
fixture_path
,
table_names
,
fixture_class_names
,
&
block
)
ActiveRecord
::
Fixtures
.
create_fixtures
(
ActiveSupport
::
TestCase
.
fixture_path
,
table_names
,
fixture_class_names
,
&
block
)
end
end
...
...
activerecord/test/fixtures/mateys.yml
浏览文件 @
820b6f3d
blackbeard_to_redbeard
:
pirate_id
:
<%= Fixtures.identify(:blackbeard) %>
target_id
:
<%= Fixtures.identify(:redbeard) %>
pirate_id
:
<%=
ActiveRecord::
Fixtures.identify(:blackbeard) %>
target_id
:
<%=
ActiveRecord::
Fixtures.identify(:redbeard) %>
weight
:
10
activerecord/test/fixtures/parrots_pirates.yml
浏览文件 @
820b6f3d
george_blackbeard
:
parrot_id
:
<%= Fixtures.identify(:george) %>
pirate_id
:
<%= Fixtures.identify(:blackbeard) %>
parrot_id
:
<%=
ActiveRecord::
Fixtures.identify(:george) %>
pirate_id
:
<%=
ActiveRecord::
Fixtures.identify(:blackbeard) %>
louis_blackbeard
:
parrot_id
:
<%= Fixtures.identify(:louis) %>
pirate_id
:
<%= Fixtures.identify(:blackbeard) %>
parrot_id
:
<%=
ActiveRecord::
Fixtures.identify(:louis) %>
pirate_id
:
<%=
ActiveRecord::
Fixtures.identify(:blackbeard) %>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录