Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
68672122
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,发现更多精彩内容 >>
提交
68672122
编写于
12月 07, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3889 from kielkowicz/master
Annotating haml and slim file
上级
0df2ef3e
c6e6ce43
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
135 addition
and
69 deletion
+135
-69
railties/lib/rails/source_annotation_extractor.rb
railties/lib/rails/source_annotation_extractor.rb
+5
-1
railties/test/application/rake/migrations_test.rb
railties/test/application/rake/migrations_test.rb
+85
-0
railties/test/application/rake/notes_test.rb
railties/test/application/rake/notes_test.rb
+45
-0
railties/test/application/rake_test.rb
railties/test/application/rake_test.rb
+0
-68
未找到文件。
railties/lib/rails/source_annotation_extractor.rb
浏览文件 @
68672122
...
@@ -55,7 +55,7 @@ def find(dirs=%w(app config lib script test))
...
@@ -55,7 +55,7 @@ def find(dirs=%w(app config lib script test))
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
# with their annotations. Only files with annotations are included, and only
# with their annotations. Only files with annotations are included, and only
# those with extension +.builder+, +.rb+,
and +.erb
+
# those with extension +.builder+, +.rb+,
+.erb+, +.haml+ and +.slim
+
# are taken into account.
# are taken into account.
def
find_in
(
dir
)
def
find_in
(
dir
)
results
=
{}
results
=
{}
...
@@ -69,6 +69,10 @@ def find_in(dir)
...
@@ -69,6 +69,10 @@ def find_in(dir)
results
.
update
(
extract_annotations_from
(
item
,
/#\s*(
#{
tag
}
):?\s*(.*)$/
))
results
.
update
(
extract_annotations_from
(
item
,
/#\s*(
#{
tag
}
):?\s*(.*)$/
))
elsif
item
=~
/\.erb$/
elsif
item
=~
/\.erb$/
results
.
update
(
extract_annotations_from
(
item
,
/<%\s*#\s*(
#{
tag
}
):?\s*(.*?)\s*%>/
))
results
.
update
(
extract_annotations_from
(
item
,
/<%\s*#\s*(
#{
tag
}
):?\s*(.*?)\s*%>/
))
elsif
item
=~
/\.haml$/
results
.
update
(
extract_annotations_from
(
item
,
/-\s*#\s*(
#{
tag
}
):?\s*(.*)$/
))
elsif
item
=~
/\.slim$/
results
.
update
(
extract_annotations_from
(
item
,
/\/\s*\s*(
#{
tag
}
):?\s*(.*)$/
))
end
end
end
end
...
...
railties/test/application/rake/migrations_test.rb
0 → 100644
浏览文件 @
68672122
require
"isolation/abstract_unit"
module
ApplicationTests
module
RakeTests
class
RakeMigrationsTest
<
Test
::
Unit
::
TestCase
def
setup
build_app
boot_rails
FileUtils
.
rm_rf
(
"
#{
app_path
}
/config/environments"
)
end
def
teardown
teardown_app
end
test
'model and migration generator with change syntax'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
output
=
Dir
.
chdir
(
app_path
){
`rake db:migrate`
}
assert_match
(
/create_table\(:users\)/
,
output
)
assert_match
(
/CreateUsers: migrated/
,
output
)
assert_match
(
/add_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AddEmailToUsers: migrated/
,
output
)
output
=
Dir
.
chdir
(
app_path
){
`rake db:rollback STEP=2`
}
assert_match
(
/drop_table\("users"\)/
,
output
)
assert_match
(
/CreateUsers: reverted/
,
output
)
assert_match
(
/remove_column\("users", :email\)/
,
output
)
assert_match
(
/AddEmailToUsers: reverted/
,
output
)
end
test
'migration status when schema migrations table is not present'
do
output
=
Dir
.
chdir
(
app_path
){
`rake db:migrate:status`
}
assert_equal
"Schema migrations table does not exist yet.
\n
"
,
output
end
test
'test migration status'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=1`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
end
test
'test migration status after rollback and redo'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=2`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/down\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:redo`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
end
end
end
railties/test/application/rake/notes_test.rb
0 → 100644
浏览文件 @
68672122
require
"isolation/abstract_unit"
module
ApplicationTests
module
RakeTests
class
RakeNotesTest
<
Test
::
Unit
::
TestCase
def
setup
build_app
require
"rails/all"
end
def
teardown
teardown_app
end
test
'notes'
do
app_file
"app/views/home/index.html.erb"
,
"<% # TODO: note in erb %>"
app_file
"app/views/home/index.html.haml"
,
"-# TODO: note in haml"
app_file
"app/views/home/index.html.slim"
,
"/ TODO: note in slim"
boot_rails
require
'rake'
require
'rdoc/task'
require
'rake/testtask'
Rails
.
application
.
load_tasks
Dir
.
chdir
(
app_path
)
do
output
=
`bundle exec rake notes`
assert_match
/note in erb/
,
output
assert_match
/note in haml/
,
output
assert_match
/note in slim/
,
output
end
end
private
def
boot_rails
super
require
"
#{
app_path
}
/config/environment"
end
end
end
end
railties/test/application/rake_test.rb
浏览文件 @
68672122
...
@@ -108,74 +108,6 @@ def test_logger_is_flushed_when_exiting_production_rake_tasks
...
@@ -108,74 +108,6 @@ def test_logger_is_flushed_when_exiting_production_rake_tasks
assert_match
"Sample log message"
,
output
assert_match
"Sample log message"
,
output
end
end
def
test_model_and_migration_generator_with_change_syntax
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
output
=
Dir
.
chdir
(
app_path
){
`rake db:migrate`
}
assert_match
(
/create_table\(:users\)/
,
output
)
assert_match
(
/CreateUsers: migrated/
,
output
)
assert_match
(
/add_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AddEmailToUsers: migrated/
,
output
)
output
=
Dir
.
chdir
(
app_path
){
`rake db:rollback STEP=2`
}
assert_match
(
/drop_table\("users"\)/
,
output
)
assert_match
(
/CreateUsers: reverted/
,
output
)
assert_match
(
/remove_column\("users", :email\)/
,
output
)
assert_match
(
/AddEmailToUsers: reverted/
,
output
)
end
def
test_migration_status_when_schema_migrations_table_is_not_present
output
=
Dir
.
chdir
(
app_path
){
`rake db:migrate:status`
}
assert_equal
"Schema migrations table does not exist yet.
\n
"
,
output
end
def
test_migration_status
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=1`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
end
def
test_migration_status_after_rollback_and_redo
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=2`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/down\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:redo`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
def
test_loading_specific_fixtures
def
test_loading_specific_fixtures
Dir
.
chdir
(
app_path
)
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate model user username:string password:string`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录