Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
85ff67ce
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 搜索 >>
提交
85ff67ce
编写于
6月 27, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
git://github.com/rails/rails
上级
e375819b
085db5e1
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
400 addition
and
39 deletion
+400
-39
actionpack/lib/action_controller/base/filter_parameter_logging.rb
...ck/lib/action_controller/base/filter_parameter_logging.rb
+4
-0
actionpack/lib/action_view/helpers/form_tag_helper.rb
actionpack/lib/action_view/helpers/form_tag_helper.rb
+5
-0
actionpack/test/controller/filter_params_test.rb
actionpack/test/controller/filter_params_test.rb
+2
-1
actionpack/test/template/form_tag_helper_test.rb
actionpack/test/template/form_tag_helper_test.rb
+12
-0
railties/lib/initializer.rb
railties/lib/initializer.rb
+15
-35
railties/lib/rails/configuration.rb
railties/lib/rails/configuration.rb
+31
-2
railties/lib/rails/paths.rb
railties/lib/rails/paths.rb
+120
-0
railties/lib/railties_path.rb
railties/lib/railties_path.rb
+1
-1
railties/test/abstract_unit.rb
railties/test/abstract_unit.rb
+1
-0
railties/test/initializer/path_test.rb
railties/test/initializer/path_test.rb
+86
-0
railties/test/initializer/root/app/controllers/.keep
railties/test/initializer/root/app/controllers/.keep
+0
-0
railties/test/initializer/root/app/helpers/.keep
railties/test/initializer/root/app/helpers/.keep
+0
-0
railties/test/initializer/root/app/metal/.keep
railties/test/initializer/root/app/metal/.keep
+0
-0
railties/test/initializer/root/app/models/.keep
railties/test/initializer/root/app/models/.keep
+0
-0
railties/test/initializer/root/app/views/.keep
railties/test/initializer/root/app/views/.keep
+0
-0
railties/test/initializer/root/config/database.yml
railties/test/initializer/root/config/database.yml
+4
-0
railties/test/initializer/root/config/environments/.keep
railties/test/initializer/root/config/environments/.keep
+0
-0
railties/test/initializer/root/config/locales/.keep
railties/test/initializer/root/config/locales/.keep
+0
-0
railties/test/initializer/root/config/routes.rb
railties/test/initializer/root/config/routes.rb
+0
-0
railties/test/initializer/root/lib/.keep
railties/test/initializer/root/lib/.keep
+0
-0
railties/test/initializer/root/tmp/.keep
railties/test/initializer/root/tmp/.keep
+0
-0
railties/test/initializer/root/tmp/cache/.keep
railties/test/initializer/root/tmp/cache/.keep
+0
-0
railties/test/initializer/root/vendor/.keep
railties/test/initializer/root/vendor/.keep
+0
-0
railties/test/paths_test.rb
railties/test/paths_test.rb
+119
-0
未找到文件。
actionpack/lib/action_controller/base/filter_parameter_logging.rb
浏览文件 @
85ff67ce
...
...
@@ -43,6 +43,10 @@ def filter_parameter_logging(*filter_words, &block)
filtered_parameters
[
key
]
=
'[FILTERED]'
elsif
value
.
is_a?
(
Hash
)
filtered_parameters
[
key
]
=
filter_parameters
(
value
)
elsif
value
.
is_a?
(
Array
)
filtered_parameters
[
key
]
=
value
.
collect
do
|
item
|
filter_parameters
(
item
)
end
elsif
block_given?
key
=
key
.
dup
value
=
value
.
dup
if
value
...
...
actionpack/lib/action_view/helpers/form_tag_helper.rb
浏览文件 @
85ff67ce
...
...
@@ -231,6 +231,8 @@ def password_field_tag(name = "password", value = nil, options = {})
# * <tt>:rows</tt> - Specify the number of rows in the textarea
# * <tt>:cols</tt> - Specify the number of columns in the textarea
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
# * <tt>:escape</tt> - By default, the contents of the text input are HTML escaped.
# If you need unescaped contents, set this to false.
# * Any other key creates standard HTML attributes for the tag.
#
# ==== Examples
...
...
@@ -258,6 +260,9 @@ def text_area_tag(name, content = nil, options = {})
options
[
"cols"
],
options
[
"rows"
]
=
size
.
split
(
"x"
)
if
size
.
respond_to?
(
:split
)
end
escape
=
options
.
key?
(
"escape"
)
?
options
.
delete
(
"escape"
)
:
true
content
=
html_escape
(
content
)
if
escape
content_tag
:textarea
,
content
,
{
"name"
=>
name
,
"id"
=>
sanitize_to_id
(
name
)
}.
update
(
options
.
stringify_keys
)
end
...
...
actionpack/test/controller/filter_params_test.rb
浏览文件 @
85ff67ce
...
...
@@ -40,7 +40,8 @@ def test_filter_parameters
[{
'foo'
=>
'bar'
,
'bar'
=>
'foo'
},{
'foo'
=>
'[FILTERED]'
,
'bar'
=>
'foo'
},
%w'foo baz'
],
[{
'foo'
=>
'bar'
,
'baz'
=>
'foo'
},{
'foo'
=>
'[FILTERED]'
,
'baz'
=>
'[FILTERED]'
},
%w'foo baz'
],
[{
'bar'
=>
{
'foo'
=>
'bar'
,
'bar'
=>
'foo'
}},{
'bar'
=>
{
'foo'
=>
'[FILTERED]'
,
'bar'
=>
'foo'
}},
%w'fo'
],
[{
'foo'
=>
{
'foo'
=>
'bar'
,
'bar'
=>
'foo'
}},{
'foo'
=>
'[FILTERED]'
},
%w'f banana'
]]
[{
'foo'
=>
{
'foo'
=>
'bar'
,
'bar'
=>
'foo'
}},{
'foo'
=>
'[FILTERED]'
},
%w'f banana'
],
[{
'baz'
=>
[{
'foo'
=>
'baz'
}]},
{
'baz'
=>
[{
'foo'
=>
'[FILTERED]'
}]},
%w(foo)
]]
test_hashes
.
each
do
|
before_filter
,
after_filter
,
filter_words
|
FilterParamController
.
filter_parameter_logging
(
*
filter_words
)
...
...
actionpack/test/template/form_tag_helper_test.rb
浏览文件 @
85ff67ce
...
...
@@ -159,6 +159,18 @@ def test_text_area_tag_id_sanitized
assert_match
VALID_HTML_ID
,
input_elem
[
'id'
]
end
def
test_text_area_tag_escape_content
actual
=
text_area_tag
"body"
,
"<b>hello world</b>"
,
:size
=>
"20x40"
expected
=
%(<textarea cols="20" id="body" name="body" rows="40"><b>hello world</b></textarea>)
assert_dom_equal
expected
,
actual
end
def
test_text_area_tag_unescaped_content
actual
=
text_area_tag
"body"
,
"<b>hello world</b>"
,
:size
=>
"20x40"
,
:escape
=>
false
expected
=
%(<textarea cols="20" id="body" name="body" rows="40"><b>hello world</b></textarea>)
assert_dom_equal
expected
,
actual
end
def
test_text_field_tag
actual
=
text_field_tag
"title"
,
"Hello!"
expected
=
%(<input id="title" name="title" type="text" value="Hello!" />)
...
...
railties/lib/initializer.rb
浏览文件 @
85ff67ce
...
...
@@ -5,6 +5,7 @@
require
'rails/version'
require
'rails/gem_dependency'
require
'rails/rack'
require
'rails/paths'
require
'rails/core'
require
'rails/configuration'
...
...
@@ -112,24 +113,6 @@ def self.run(initializer = nil, config = nil)
require
'ruby_version_check'
end
Initializer
.
default
.
add
:set_root_path
do
raise
'RAILS_ROOT is not set'
unless
defined?
(
RAILS_ROOT
)
raise
'RAILS_ROOT is not a directory'
unless
File
.
directory?
(
RAILS_ROOT
)
configuration
.
root_path
=
# Pathname is incompatible with Windows, but Windows doesn't have
# real symlinks so File.expand_path is safe.
if
RUBY_PLATFORM
=~
/(:?mswin|mingw)/
File
.
expand_path
(
RAILS_ROOT
)
# Otherwise use Pathname#realpath which respects symlinks.
else
Pathname
.
new
(
RAILS_ROOT
).
realpath
.
to_s
end
RAILS_ROOT
.
replace
configuration
.
root_path
end
# If Rails is vendored and RubyGems is available, install stub GemSpecs
# for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
# Active Resource. This allows Gem plugins to depend on Rails even when
...
...
@@ -158,8 +141,9 @@ def self.run(initializer = nil, config = nil)
# Set the <tt>$LOAD_PATH</tt> based on the value of
# Configuration#load_paths. Duplicates are removed.
Initializer
.
default
.
add
:set_load_path
do
load_paths
=
configuration
.
load_paths
+
configuration
.
framework_paths
load_paths
.
reverse_each
{
|
dir
|
$LOAD_PATH
.
unshift
(
dir
)
if
File
.
directory?
(
dir
)
}
# TODO: Think about unifying this with the general Rails paths
configuration
.
framework_paths
.
reverse_each
{
|
dir
|
$LOAD_PATH
.
unshift
(
dir
)
if
File
.
directory?
(
dir
)
}
configuration
.
paths
.
add_to_load_path
$LOAD_PATH
.
uniq!
end
...
...
@@ -179,6 +163,10 @@ def self.run(initializer = nil, config = nil)
begin
require
'active_support'
require
'active_support/core_ext/kernel/reporting'
require
'active_support/core_ext/logger'
# TODO: This is here to make Sam Ruby's tests pass. Needs discussion.
require
'active_support/core_ext/numeric/bytes'
configuration
.
frameworks
.
each
{
|
framework
|
require
(
framework
.
to_s
)
}
rescue
LoadError
=>
e
# Re-raise as RuntimeError because Mongrel would swallow LoadError.
...
...
@@ -217,6 +205,8 @@ def self.run(initializer = nil, config = nil)
Initializer
.
default
.
add
:load_environment
do
silence_warnings
do
next
if
@environment_loaded
next
unless
File
.
file?
(
configuration
.
environment_path
)
@environment_loaded
=
true
config
=
configuration
...
...
@@ -307,6 +297,7 @@ def self.run(initializer = nil, config = nil)
end
end
# TODO: Why are we silencing warning here?
silence_warnings
{
Object
.
const_set
"RAILS_DEFAULT_LOGGER"
,
logger
}
end
...
...
@@ -326,6 +317,7 @@ def self.run(initializer = nil, config = nil)
# Sets the dependency loading mechanism based on the value of
# Configuration#cache_classes.
Initializer
.
default
.
add
:initialize_dependency_mechanism
do
# TODO: Remove files from the $" and always use require
ActiveSupport
::
Dependencies
.
mechanism
=
configuration
.
cache_classes
?
:require
:
:load
end
...
...
@@ -409,10 +401,6 @@ def self.run(initializer = nil, config = nil)
end
end
# Add the load paths used by support functions such as the info controller
Initializer
.
default
.
add
:add_support_load_paths
do
end
Initializer
.
default
.
add
:check_for_unbuilt_gems
do
unbuilt_gems
=
config
.
gems
.
select
{
|
gem
|
gem
.
frozen?
&&
!
gem
.
built?
}
if
unbuilt_gems
.
size
>
0
...
...
@@ -462,6 +450,7 @@ def self.run(initializer = nil, config = nil)
# # pick up any gems that plugins depend on
Initializer
.
default
.
add
:add_gem_load_paths
do
require
'rails/gem_dependency'
# TODO: This seems extraneous
Rails
::
GemDependency
.
add_frozen_gem_path
unless
config
.
gems
.
empty?
require
"rubygems"
...
...
@@ -529,6 +518,7 @@ def self.run(initializer = nil, config = nil)
end
end
# TODO: Make a DSL way to limit an initializer to a particular framework
# # Prepare dispatcher callbacks and run 'prepare' callbacks
Initializer
.
default
.
add
:prepare_dispatcher
do
...
...
@@ -557,20 +547,10 @@ def self.run(initializer = nil, config = nil)
end
end
# # Load view path cache
Initializer
.
default
.
add
:load_view_paths
do
if
configuration
.
frameworks
.
include?
(
:action_view
)
if
configuration
.
cache_classes
view_path
=
ActionView
::
FileSystemResolverWithFallback
.
new
(
configuration
.
view_path
)
ActionController
::
Base
.
view_paths
=
view_path
if
configuration
.
frameworks
.
include?
(
:action_controller
)
ActionMailer
::
Base
.
template_root
=
view_path
if
configuration
.
frameworks
.
include?
(
:action_mailer
)
end
end
end
# Eager load application classes
Initializer
.
default
.
add
:load_application_classes
do
next
if
$rails_rake_task
if
configuration
.
cache_classes
configuration
.
eager_load_paths
.
each
do
|
load_path
|
matcher
=
/\A
#{
Regexp
.
escape
(
load_path
)
}
(.*)\.rb\Z/
...
...
railties/lib/rails/configuration.rb
浏览文件 @
85ff67ce
...
...
@@ -10,7 +10,7 @@ class Configuration
:log_path
,
:log_level
,
:logger
,
:preload_frameworks
,
:database_configuration_file
,
:cache_store
,
:time_zone
,
:view_path
,
:metals
,
:controller_paths
,
:routes_configuration_file
,
:eager_load_paths
,
:dependency_loading
:eager_load_paths
,
:dependency_loading
,
:paths
def
initialize
set_root_path!
...
...
@@ -61,7 +61,36 @@ def set_root_path!
Pathname
.
new
(
RAILS_ROOT
).
realpath
.
to_s
end
RAILS_ROOT
.
replace
self
.
root_path
@paths
=
Rails
::
Application
::
Root
.
new
(
root_path
)
@paths
.
app
=
"app"
@paths
.
app
.
metals
=
"app/metal"
@paths
.
app
.
models
=
"app/models"
@paths
.
app
.
controllers
=
"app/controllers"
@paths
.
app
.
helpers
=
"app/helpers"
@paths
.
app
.
services
=
"app/services"
@paths
.
lib
=
"lib"
@paths
.
vendor
=
"vendor"
@paths
.
vendor
.
plugins
=
"vendor/plugins"
@paths
.
cache
=
"tmp/cache"
@paths
.
config
=
"config"
@paths
.
config
.
locales
=
"config/locales"
@paths
.
config
.
environments
=
"config/environments"
@paths
.
app
.
controllers
.
push
*
builtin_directories
@paths
.
app
.
load_path!
@paths
.
app
.
metals
.
load_path!
@paths
.
app
.
models
.
eager_load!
@paths
.
app
.
controllers
.
eager_load!
@paths
.
app
.
helpers
.
eager_load!
@paths
.
app
.
services
.
load_path!
@paths
.
app
.
metals
.
eager_load!
@paths
.
lib
.
load_path!
@paths
.
vendor
.
load_path!
@paths
.
config
.
environments
.
glob
=
"
#{
RAILS_ENV
}
.rb"
RAILS_ROOT
.
replace
root_path
end
# Enable threaded mode. Allows concurrent requests to controller actions and
...
...
railties/lib/rails/paths.rb
0 → 100644
浏览文件 @
85ff67ce
require
'set'
module
Rails
class
Application
module
PathParent
def
method_missing
(
id
,
*
args
)
name
=
id
.
to_s
if
name
=~
/^(.*)=$/
@children
[
$1
]
=
Path
.
new
(
args
.
first
,
@root
)
elsif
path
=
@children
[
name
]
path
else
super
end
end
end
class
Root
include
PathParent
attr_reader
:path
def
initialize
(
path
)
raise
unless
path
.
is_a?
(
String
)
@children
=
{}
# TODO: Move logic from set_root_path initializer
@path
=
File
.
expand_path
(
path
)
@root
=
self
@load_once
,
@eager_load
,
@all_paths
=
[],
[],
[]
end
def
load_once
@load_once
.
uniq!
@load_once
end
def
eager_load
@eager_load
.
uniq!
@eager_load
end
def
all_paths
@all_paths
.
uniq!
@all_paths
end
def
load_paths
all_paths
.
map
{
|
path
|
path
.
paths
}.
flatten
end
def
add_to_load_path
load_paths
.
reverse_each
do
|
path
|
$LOAD_PATH
.
unshift
(
path
)
if
File
.
directory?
(
path
)
end
end
end
class
Path
include
PathParent
attr_reader
:path
attr_accessor
:glob
def
initialize
(
path
,
root
)
@children
=
{}
@root
=
root
@paths
=
[
path
].
flatten
@glob
=
"**/*.rb"
end
def
push
(
path
)
@paths
.
push
path
end
alias
<<
push
def
unshift
(
path
)
@paths
.
unshift
path
end
def
load_once!
@load_once
=
true
@root
.
load_once
.
push
*
self
.
paths
end
def
load_once?
@load_once
end
def
eager_load!
@eager_load
=
true
@root
.
all_paths
<<
self
@root
.
eager_load
.
push
*
self
.
paths
end
def
eager_load?
@eager_load
end
def
load_path!
@load_path
=
true
@root
.
all_paths
<<
self
end
def
load_path?
@load_path
end
def
paths
@paths
.
map
do
|
path
|
path
.
index
(
'/'
)
==
0
?
path
:
File
.
join
(
@root
.
path
,
path
)
end
end
alias
to_a
paths
end
end
end
\ No newline at end of file
railties/lib/railties_path.rb
浏览文件 @
85ff67ce
RAILTIES_PATH
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)
RAILTIES_PATH
=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)
)
railties/test/abstract_unit.rb
浏览文件 @
85ff67ce
...
...
@@ -2,6 +2,7 @@
$:
.
unshift
File
.
dirname
(
__FILE__
)
+
"/../../activerecord/lib"
$:
.
unshift
File
.
dirname
(
__FILE__
)
+
"/../../actionpack/lib"
$:
.
unshift
File
.
dirname
(
__FILE__
)
+
"/../../actionmailer/lib"
$:
.
unshift
File
.
dirname
(
__FILE__
)
+
"/../../activeresource/lib"
$:
.
unshift
File
.
dirname
(
__FILE__
)
+
"/../lib"
$:
.
unshift
File
.
dirname
(
__FILE__
)
+
"/../builtin/rails_info"
...
...
railties/test/initializer/path_test.rb
0 → 100644
浏览文件 @
85ff67ce
require
'abstract_unit'
require
'active_support/ruby/shim'
require
'initializer'
RAILS_ROOT
.
replace
File
.
join
(
File
.
dirname
(
__FILE__
),
"root"
)
module
Rails
def
self
.
vendor_rails?
;
false
;
end
end
# TODO: Can this be reset?
Rails
::
Initializer
.
run
do
|
config
|
config
.
frameworks
=
[
:action_controller
,
:action_view
,
:action_mailer
,
:active_record
]
end
class
PathsTest
<
ActiveSupport
::
TestCase
def
setup
@paths
=
Rails
::
Initializer
.
default
.
config
.
paths
end
def
root
(
*
path
)
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"root"
,
*
path
))
end
def
assert_path
(
paths
,
*
dir
)
assert_equal
[
root
(
*
dir
)],
paths
.
paths
end
test
"booting up Rails yields a valid paths object"
do
assert_path
@paths
.
app
,
"app"
assert_path
@paths
.
app
.
metals
,
"app"
,
"metal"
assert_path
@paths
.
app
.
models
,
"app"
,
"models"
assert_path
@paths
.
app
.
helpers
,
"app"
,
"helpers"
assert_path
@paths
.
app
.
services
,
"app"
,
"services"
assert_path
@paths
.
lib
,
"lib"
assert_path
@paths
.
vendor
,
"vendor"
assert_path
@paths
.
vendor
.
plugins
,
"vendor"
,
"plugins"
assert_path
@paths
.
cache
,
"tmp"
,
"cache"
assert_path
@paths
.
config
,
"config"
assert_path
@paths
.
config
.
locales
,
"config"
,
"locales"
assert_path
@paths
.
config
.
environments
,
"config"
,
"environments"
assert_equal
Pathname
.
new
(
File
.
dirname
(
__FILE__
)).
join
(
"root"
,
"app"
,
"controllers"
).
expand_path
,
Pathname
.
new
(
@paths
.
app
.
controllers
.
to_a
.
first
).
expand_path
assert_equal
Pathname
.
new
(
File
.
dirname
(
__FILE__
)).
join
(
".."
,
".."
,
"builtin"
,
"rails_info"
).
expand_path
,
Pathname
.
new
(
@paths
.
app
.
controllers
.
to_a
[
1
]).
expand_path
end
test
"booting up Rails yields a list of paths that are eager"
do
assert
@paths
.
app
.
models
.
eager_load?
assert
@paths
.
app
.
controllers
.
eager_load?
assert
@paths
.
app
.
helpers
.
eager_load?
assert
@paths
.
app
.
metals
.
eager_load?
end
test
"environments has a glob equal to the current environment"
do
assert_equal
"
#{
RAILS_ENV
}
.rb"
,
@paths
.
config
.
environments
.
glob
end
def
assert_in_load_path
(
*
path
)
assert
$:
.
any?
{
|
p
|
File
.
expand_path
(
p
)
==
root
(
*
path
)
},
"Load path does not include '
#{
root
(
*
path
)
}
'. They are:
\n
-----
\n
#{
$:
.
join
(
"
\n
"
)
}
\n
-----"
end
def
assert_not_in_load_path
(
*
path
)
assert
!
$:
.
any?
{
|
p
|
File
.
expand_path
(
p
)
==
root
(
*
path
)
},
"Load path includes '
#{
root
(
*
path
)
}
'. They are:
\n
-----
\n
#{
$:
.
join
(
"
\n
"
)
}
\n
-----"
end
test
"load path includes each of the paths in config.paths as long as the directories exist"
do
assert_in_load_path
"app"
assert_in_load_path
"app"
,
"controllers"
assert_in_load_path
"app"
,
"metal"
assert_in_load_path
"app"
,
"models"
assert_in_load_path
"app"
,
"helpers"
assert_in_load_path
"lib"
assert_in_load_path
"vendor"
assert_not_in_load_path
"app"
,
"views"
assert_not_in_load_path
"app"
,
"services"
assert_not_in_load_path
"config"
assert_not_in_load_path
"config"
,
"locales"
assert_not_in_load_path
"config"
,
"environments"
assert_not_in_load_path
"tmp"
assert_not_in_load_path
"tmp"
,
"cache"
end
end
\ No newline at end of file
railties/test/initializer/root/app/controllers/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/app/helpers/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/app/metal/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/app/models/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/app/views/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/config/database.yml
0 → 100644
浏览文件 @
85ff67ce
development
:
adapter
:
sqlite3
database
:
db/railties.db
timeout
:
5000
\ No newline at end of file
railties/test/initializer/root/config/environments/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/config/locales/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/config/routes.rb
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/lib/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/tmp/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/tmp/cache/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/initializer/root/vendor/.keep
0 → 100644
浏览文件 @
85ff67ce
railties/test/paths_test.rb
0 → 100644
浏览文件 @
85ff67ce
require
'abstract_unit'
require
'rails/paths'
class
PathsTest
<
ActiveSupport
::
TestCase
def
setup
@root
=
Rails
::
Application
::
Root
.
new
(
"/foo/bar"
)
end
test
"the paths object is initialized with the root path"
do
root
=
Rails
::
Application
::
Root
.
new
(
"/fiz/baz"
)
assert_equal
"/fiz/baz"
,
root
.
path
end
test
"creating a root level path"
do
@root
.
app
=
"/foo/bar"
assert_equal
[
"/foo/bar"
],
@root
.
app
.
to_a
end
test
"relative paths are relative to the paths root"
do
@root
.
app
=
"app"
assert_equal
[
"/foo/bar/app"
],
@root
.
app
.
to_a
end
test
"creating a child level path"
do
@root
.
app
=
"/foo/bar"
@root
.
app
.
models
=
"/foo/bar/baz"
assert_equal
[
"/foo/bar/baz"
],
@root
.
app
.
models
.
to_a
end
test
"child level paths are relative from the root"
do
@root
.
app
=
"/app"
@root
.
app
.
models
=
"baz"
assert_equal
[
"/foo/bar/baz"
],
@root
.
app
.
models
.
to_a
end
test
"adding multiple physical paths as an array"
do
@root
.
app
=
[
"/app"
,
"/app2"
]
assert_equal
[
"/app"
,
"/app2"
],
@root
.
app
.
to_a
end
test
"adding multiple physical paths using #push"
do
@root
.
app
=
"/app"
@root
.
app
.
push
"/app2"
assert_equal
[
"/app"
,
"/app2"
],
@root
.
app
.
to_a
end
test
"adding multiple physical paths using <<"
do
@root
.
app
=
"/app"
@root
.
app
<<
"/app2"
assert_equal
[
"/app"
,
"/app2"
],
@root
.
app
.
to_a
end
test
"adding multiple physical paths using #unshift"
do
@root
.
app
=
"/app"
@root
.
app
.
unshift
"/app2"
assert_equal
[
"/app2"
,
"/app"
],
@root
.
app
.
to_a
end
test
"the root can only have one physical path"
do
assert_raise
(
RuntimeError
)
{
Rails
::
Application
::
Root
.
new
([
"/fiz"
,
"/biz"
])
}
assert_raise
(
NoMethodError
)
{
@root
.
push
"/biz"
}
assert_raise
(
NoMethodError
)
{
@root
.
unshift
"/biz"
}
assert_raise
(
NoMethodError
)
{
@root
<<
"/biz"
}
end
test
"it is possible to add a path that should be loaded only once"
do
@root
.
app
=
"/app"
@root
.
app
.
load_once!
assert
@root
.
app
.
load_once?
assert
@root
.
load_once
.
include?
(
@root
.
app
.
paths
.
first
)
end
test
"making a path load_once more than once only includes it once in @root.load_once"
do
@root
.
app
=
"/app"
@root
.
app
.
load_once!
@root
.
app
.
load_once!
assert_equal
1
,
@root
.
load_once
.
select
{
|
p
|
p
==
@root
.
app
.
paths
.
first
}.
size
end
test
"it is possible to mark a path as eager"
do
@root
.
app
=
"/app"
@root
.
app
.
eager_load!
assert
@root
.
app
.
eager_load?
assert
@root
.
eager_load
.
include?
(
@root
.
app
.
paths
.
first
)
end
test
"making a path eager more than once only includes it once in @root.eager_paths"
do
@root
.
app
=
"/app"
@root
.
app
.
eager_load!
@root
.
app
.
eager_load!
assert_equal
1
,
@root
.
eager_load
.
select
{
|
p
|
p
==
@root
.
app
.
paths
.
first
}.
size
end
test
"a path should have a glob that defaults to **/*.rb"
do
@root
.
app
=
"/app"
assert_equal
"**/*.rb"
,
@root
.
app
.
glob
end
test
"it should be possible to override a path's default glob"
do
@root
.
app
=
"/app"
@root
.
app
.
glob
=
"*.rb"
assert_equal
"*.rb"
,
@root
.
app
.
glob
end
test
"a path can be added to the load path"
do
@root
.
app
=
"app"
@root
.
app
.
load_path!
@root
.
app
.
models
=
"app/models"
assert_equal
[
"/foo/bar/app"
],
@root
.
load_paths
end
test
"adding a path to the eager paths also adds it to the load path"
do
@root
.
app
=
"app"
@root
.
app
.
eager_load!
assert_equal
[
"/foo/bar/app"
],
@root
.
load_paths
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录