Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d475de7e
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,发现更多精彩内容 >>
提交
d475de7e
编写于
9月 19, 2010
作者:
P
Piotr Sarnacki
提交者:
José Valim
9月 20, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add helper for loading seed data for engine and application
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
0523b55a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
2 deletion
+30
-2
activerecord/lib/active_record/railties/databases.rake
activerecord/lib/active_record/railties/databases.rake
+1
-2
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+9
-0
railties/lib/rails/engine/configuration.rb
railties/lib/rails/engine/configuration.rb
+1
-0
railties/test/railties/engine_test.rb
railties/test/railties/engine_test.rb
+19
-0
未找到文件。
activerecord/lib/active_record/railties/databases.rake
浏览文件 @
d475de7e
...
...
@@ -299,8 +299,7 @@ namespace :db do
desc
'Load the seed data from db/seeds.rb'
task
:seed
=>
'db:abort_if_pending_migrations'
do
seed_file
=
File
.
join
(
Rails
.
root
,
'db'
,
'seeds.rb'
)
load
(
seed_file
)
if
File
.
exist?
(
seed_file
)
Rails
.
application
.
load_seed
end
namespace
:fixtures
do
...
...
railties/lib/rails/engine.rb
浏览文件 @
d475de7e
...
...
@@ -380,6 +380,15 @@ def config
@config
||=
Engine
::
Configuration
.
new
(
find_root_with_flag
(
"lib"
))
end
# Load data from db/seeds.rb file. It can be used in to load engines'
# seeds, e.g.:
#
# Blog::Engine.load_seed
def
load_seed
seed_file
=
config
.
paths
.
db
.
seeds
.
to_a
.
first
load
(
seed_file
)
if
File
.
exist?
(
seed_file
)
end
# Add configured load paths to ruby load paths and remove duplicates.
initializer
:set_load_path
,
:before
=>
:bootstrap_hook
do
_all_load_paths
.
reverse_each
do
|
path
|
...
...
railties/lib/rails/engine/configuration.rb
浏览文件 @
d475de7e
...
...
@@ -37,6 +37,7 @@ def paths
paths
.
vendor
.
plugins
"vendor/plugins"
paths
.
db
"db"
paths
.
db
.
migrate
"db/migrate"
paths
.
db
.
seeds
"db/seeds.rb"
paths
end
end
...
...
railties/test/railties/engine_test.rb
浏览文件 @
d475de7e
...
...
@@ -624,5 +624,24 @@ class Engine < ::Rails::Engine
assert
!
File
.
exist?
(
File
.
join
(
app_path
,
'public/bukkits'
))
end
end
test
"loading seed data"
do
@plugin
.
write
"db/seeds.rb"
,
<<-
RUBY
Bukkits::Engine.config.bukkits_seeds_loaded = true
RUBY
app_file
"db/seeds.rb"
,
<<-
RUBY
Rails.application.config.app_seeds_loaded = true
RUBY
boot_rails
Rails
.
application
.
load_seed
assert
Rails
.
application
.
config
.
app_seeds_loaded
assert_raise
(
NoMethodError
)
do
Bukkits
::
Engine
.
config
.
bukkits_seeds_loaded
end
Bukkits
::
Engine
.
load_seed
assert
Bukkits
::
Engine
.
config
.
bukkits_seeds_loaded
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录