Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b97a3f33
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,发现更多精彩内容 >>
提交
b97a3f33
编写于
6月 07, 2010
作者:
W
wycats
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'rsim/oracle_enhanced_rails3'
上级
0042f416
acef8fea
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
54 addition
and
47 deletion
+54
-47
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+2
-1
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+5
-2
activerecord/test/cases/adapter_test.rb
activerecord/test/cases/adapter_test.rb
+4
-13
activerecord/test/cases/associations/belongs_to_associations_test.rb
...d/test/cases/associations/belongs_to_associations_test.rb
+4
-0
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+1
-1
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+4
-3
activerecord/test/cases/date_time_test.rb
activerecord/test/cases/date_time_test.rb
+3
-1
activerecord/test/cases/log_subscriber_test.rb
activerecord/test/cases/log_subscriber_test.rb
+2
-2
activerecord/test/cases/migration_test.rb
activerecord/test/cases/migration_test.rb
+16
-17
activerecord/test/connections/native_oracle/connection.rb
activerecord/test/connections/native_oracle/connection.rb
+1
-1
activerecord/test/models/topic.rb
activerecord/test/models/topic.rb
+6
-0
activesupport/lib/active_support/core_ext/date_time/conversions.rb
...port/lib/active_support/core_ext/date_time/conversions.rb
+3
-3
activesupport/test/abstract_unit.rb
activesupport/test/abstract_unit.rb
+1
-1
activesupport/test/core_ext/date_time_ext_test.rb
activesupport/test/core_ext/date_time_ext_test.rb
+2
-2
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
b97a3f33
...
...
@@ -1756,7 +1756,8 @@ def join_base
end
def
count_aliases_from_table_joins
(
name
)
quoted_name
=
join_base
.
active_record
.
connection
.
quote_table_name
(
name
.
downcase
)
# quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase
quoted_name
=
join_base
.
active_record
.
connection
.
quote_table_name
(
name
.
downcase
).
downcase
join_sql
=
join_base
.
table_joins
.
to_s
.
downcase
join_sql
.
blank?
?
0
:
# Table names
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
b97a3f33
...
...
@@ -356,13 +356,16 @@ def with_create_scope
end
def
references_eager_loaded_tables?
joined_tables
=
(
tables_in_string
(
arel
.
joins
(
arel
))
+
[
table
.
name
,
table
.
table_alias
]).
compact
.
uniq
# always convert table names to downcase as in Oracle quoted table names are in uppercase
joined_tables
=
(
tables_in_string
(
arel
.
joins
(
arel
))
+
[
table
.
name
,
table
.
table_alias
]).
compact
.
map
(
&
:downcase
).
uniq
(
tables_in_string
(
to_sql
)
-
joined_tables
).
any?
end
def
tables_in_string
(
string
)
return
[]
if
string
.
blank?
string
.
scan
(
/([a-zA-Z_][\.\w]+).?\./
).
flatten
.
uniq
# always convert table names to downcase as in Oracle quoted table names are in uppercase
# ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries
string
.
scan
(
/([a-zA-Z_][\.\w]+).?\./
).
flatten
.
map
(
&
:downcase
).
uniq
-
[
'raw_sql_'
]
end
end
...
...
activerecord/test/cases/adapter_test.rb
浏览文件 @
b97a3f33
...
...
@@ -145,22 +145,13 @@ def test_foreign_key_violations_are_translated_to_specific_exception
def
test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
sql_inject
=
"1 select * from schema"
assert_equal
" LIMIT 1"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
)
if
current_adapter?
(
:MysqlAdapter
)
assert_equal
" LIMIT 7, 1"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
else
assert_equal
" LIMIT 1 OFFSET 7"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
end
assert_no_match
/schema/
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
)
assert_no_match
/schema/
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
end
def
test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
sql_inject
=
"1, 7 procedure help()"
if
current_adapter?
(
:MysqlAdapter
)
assert_equal
" LIMIT 1,7"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
)
assert_equal
" LIMIT 7, 1"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
'1 ; DROP TABLE USERS'
,
:offset
=>
7
)
else
assert_equal
" LIMIT 1,7"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
)
assert_equal
" LIMIT 1,7 OFFSET 7"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
end
assert_no_match
/procedure/
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
)
assert_no_match
/procedure/
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
end
end
activerecord/test/cases/associations/belongs_to_associations_test.rb
浏览文件 @
b97a3f33
...
...
@@ -37,6 +37,10 @@ def test_belongs_to_with_primary_key_joins_on_correct_column
if
current_adapter?
(
:MysqlAdapter
)
assert_no_match
(
/`firm_with_primary_keys_companies`\.`id`/
,
sql
)
assert_match
(
/`firm_with_primary_keys_companies`\.`name`/
,
sql
)
elsif
current_adapter?
(
:OracleAdapter
)
# on Oracle aliases are truncated to 30 characters and are quoted in uppercase
assert_no_match
(
/"firm_with_primary_keys_compani"\."id"/i
,
sql
)
assert_match
(
/"firm_with_primary_keys_compani"\."name"/i
,
sql
)
else
assert_no_match
(
/"firm_with_primary_keys_companies"\."id"/
,
sql
)
assert_match
(
/"firm_with_primary_keys_companies"\."name"/
,
sql
)
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
b97a3f33
...
...
@@ -511,7 +511,7 @@ def test_deleting_before_save
end
def
test_deleting_updates_counter_cache
topic
=
Topic
.
first
topic
=
Topic
.
first
(
:order
=>
"id ASC"
)
assert_equal
topic
.
replies
.
to_a
.
size
,
topic
.
replies_count
topic
.
replies
.
delete
(
topic
.
replies
.
first
)
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
b97a3f33
...
...
@@ -430,14 +430,14 @@ def test_non_attribute_access_and_assignment
end
def
test_preserving_date_objects
if
current_adapter?
(
:SybaseAdapter
,
:OracleAdapter
)
if
current_adapter?
(
:SybaseAdapter
)
# Sybase ctlib does not (yet?) support the date type; use datetime instead.
# Oracle treats all dates/times as Time.
assert_kind_of
(
Time
,
Topic
.
find
(
1
).
last_read
,
"The last_read attribute should be of the Time class"
)
else
# Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
assert_kind_of
(
Date
,
Topic
.
find
(
1
).
last_read
,
"The last_read attribute should be of the Date class"
...
...
@@ -2125,10 +2125,11 @@ def test_to_xml
assert_equal
"integer"
,
xml
.
elements
[
"//parent-id"
].
attributes
[
'type'
]
assert_equal
"true"
,
xml
.
elements
[
"//parent-id"
].
attributes
[
'nil'
]
if
current_adapter?
(
:SybaseAdapter
,
:OracleAdapter
)
if
current_adapter?
(
:SybaseAdapter
)
assert_equal
last_read_in_current_timezone
,
xml
.
elements
[
"//last-read"
].
text
assert_equal
"datetime"
,
xml
.
elements
[
"//last-read"
].
attributes
[
'type'
]
else
# Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
assert_equal
"2004-04-15"
,
xml
.
elements
[
"//last-read"
].
text
assert_equal
"date"
,
xml
.
elements
[
"//last-read"
].
attributes
[
'type'
]
end
...
...
activerecord/test/cases/date_time_test.rb
浏览文件 @
b97a3f33
...
...
@@ -5,7 +5,9 @@
class
DateTimeTest
<
ActiveRecord
::
TestCase
def
test_saves_both_date_and_time
time_values
=
[
1807
,
2
,
10
,
15
,
30
,
45
]
now
=
DateTime
.
civil
(
*
time_values
)
# create DateTime value with local time zone offset
local_offset
=
Rational
(
Time
.
local_time
(
*
time_values
).
utc_offset
,
86400
)
now
=
DateTime
.
civil
(
*
(
time_values
+
[
local_offset
]))
task
=
Task
.
new
task
.
starting
=
now
...
...
activerecord/test/cases/log_subscriber_test.rb
浏览文件 @
b97a3f33
...
...
@@ -27,7 +27,7 @@ def test_basic_query_logging
wait
assert_equal
1
,
@logger
.
logged
(
:debug
).
size
assert_match
(
/Developer Load/
,
@logger
.
logged
(
:debug
).
last
)
assert_match
(
/SELECT .*?FROM .?developers.?/
,
@logger
.
logged
(
:debug
).
last
)
assert_match
(
/SELECT .*?FROM .?developers.?/
i
,
@logger
.
logged
(
:debug
).
last
)
end
def
test_cached_queries
...
...
@@ -38,6 +38,6 @@ def test_cached_queries
wait
assert_equal
2
,
@logger
.
logged
(
:debug
).
size
assert_match
(
/CACHE/
,
@logger
.
logged
(
:debug
).
last
)
assert_match
(
/SELECT .*?FROM .?developers.?/
,
@logger
.
logged
(
:debug
).
last
)
assert_match
(
/SELECT .*?FROM .?developers.?/
i
,
@logger
.
logged
(
:debug
).
last
)
end
end
activerecord/test/cases/migration_test.rb
浏览文件 @
b97a3f33
...
...
@@ -30,13 +30,14 @@ def test_add_schema_info_respects_prefix_and_suffix
conn
=
ActiveRecord
::
Base
.
connection
conn
.
drop_table
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)
if
conn
.
table_exists?
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)
ActiveRecord
::
Base
.
table_name_prefix
=
'foo_'
ActiveRecord
::
Base
.
table_name_suffix
=
'_bar'
# Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters
ActiveRecord
::
Base
.
table_name_prefix
=
'p_'
ActiveRecord
::
Base
.
table_name_suffix
=
'_s'
conn
.
drop_table
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)
if
conn
.
table_exists?
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)
conn
.
initialize_schema_migrations_table
assert_equal
"
foo_unique_schema_migrations_bar
"
,
conn
.
indexes
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)[
0
][
:name
]
assert_equal
"
p_unique_schema_migrations_s
"
,
conn
.
indexes
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)[
0
][
:name
]
ensure
ActiveRecord
::
Base
.
table_name_prefix
=
""
ActiveRecord
::
Base
.
table_name_suffix
=
""
...
...
@@ -83,13 +84,17 @@ def test_add_index
# Orcl nds shrt indx nms. Sybs 2.
# OpenBase does not have named indexes. You must specify a single column name
unless
current_adapter?
(
:
OracleAdapter
,
:
SybaseAdapter
,
:OpenBaseAdapter
)
unless
current_adapter?
(
:SybaseAdapter
,
:OpenBaseAdapter
)
assert_nothing_raised
{
Person
.
connection
.
add_index
(
"people"
,
[
"last_name"
,
"first_name"
])
}
assert_nothing_raised
{
Person
.
connection
.
remove_index
(
"people"
,
:column
=>
[
"last_name"
,
"first_name"
])
}
# Oracle adapter cannot have specified index name larger than 30 characters
# Oracle adapter is shortening index name when just column list is given
unless
current_adapter?
(
:OracleAdapter
)
assert_nothing_raised
{
Person
.
connection
.
add_index
(
"people"
,
[
"last_name"
,
"first_name"
])
}
assert_nothing_raised
{
Person
.
connection
.
remove_index
(
"people"
,
:name
=>
"index_people_on_last_name_and_first_name"
)
}
assert_nothing_raised
{
Person
.
connection
.
add_index
(
"people"
,
[
"last_name"
,
"first_name"
])
}
assert_nothing_raised
{
Person
.
connection
.
remove_index
(
"people"
,
"last_name_and_first_name"
)
}
end
assert_nothing_raised
{
Person
.
connection
.
add_index
(
"people"
,
[
"last_name"
,
"first_name"
])
}
assert_nothing_raised
{
Person
.
connection
.
remove_index
(
"people"
,
[
"last_name"
,
"first_name"
])
}
assert_nothing_raised
{
Person
.
connection
.
add_index
(
"people"
,
[
"last_name"
],
:length
=>
10
)
}
...
...
@@ -736,13 +741,7 @@ def test_remove_column_with_multi_column_index
table
.
column
:hat_size
,
:integer
table
.
column
:hat_style
,
:string
,
:limit
=>
100
end
# Oracle index names should be 30 or less characters
if
current_adapter?
(
:OracleAdapter
)
ActiveRecord
::
Base
.
connection
.
add_index
"hats"
,
[
"hat_style"
,
"hat_size"
],
:unique
=>
true
,
:name
=>
'index_hats_on_hat_style_size'
else
ActiveRecord
::
Base
.
connection
.
add_index
"hats"
,
[
"hat_style"
,
"hat_size"
],
:unique
=>
true
end
assert_nothing_raised
{
Person
.
connection
.
remove_column
(
"hats"
,
"hat_size"
)
}
ensure
...
...
@@ -1375,8 +1374,8 @@ def test_create_table_with_custom_sequence_name
return
unless
current_adapter?
:OracleAdapter
# table name is 29 chars, the standard sequence name will
# be 33 chars and
fail
assert_
raise
(
ActiveRecord
::
StatementInvalid
)
do
# be 33 chars and
should be shortened
assert_
nothing_raised
do
begin
Person
.
connection
.
create_table
:table_with_name_thats_just_ok
do
|
t
|
t
.
column
:foo
,
:string
,
:null
=>
false
...
...
activerecord/test/connections/native_oracle/connection.rb
浏览文件 @
b97a3f33
...
...
@@ -53,7 +53,7 @@
# for assert_queries test helper
ActiveRecord
::
Base
.
connection
.
class
.
class_eval
do
IGNORED_SELECT_SQL
=
[
/^select .*nextval/i
,
/^SAVEPOINT/
,
/^ROLLBACK TO
SAVEPOINT/
,
/^RELEASE SAVEPOINT/
,
/^\s*select .* from all_tab_columns
/im
]
IGNORED_SELECT_SQL
=
[
/^select .*nextval/i
,
/^SAVEPOINT/
,
/^ROLLBACK TO
/
,
/^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)
/im
]
def
select_with_query_record
(
sql
,
name
=
nil
,
return_column_names
=
false
)
$queries_executed
||=
[]
...
...
activerecord/test/models/topic.rb
浏览文件 @
b97a3f33
...
...
@@ -43,6 +43,12 @@ def extension_two
before_create
:default_written_on
before_destroy
:destroy_children
# Explicitly define as :date column so that returned Oracle DATE values would be typecasted to Date and not Time.
# Some tests depend on assumption that this attribute will have Date values.
if
current_adapter?
(
:OracleEnhancedAdapter
)
set_date_columns
:last_read
end
def
parent
Topic
.
find
(
parent_id
)
end
...
...
activesupport/lib/active_support/core_ext/date_time/conversions.rb
浏览文件 @
b97a3f33
...
...
@@ -60,7 +60,7 @@ def readable_inspect
# Converts self to a Ruby Date object; time portion is discarded
def
to_date
::
Date
.
new
(
year
,
month
,
day
)
end
unless
method_defined
?
(
:to_date
)
end
unless
instance_methods
(
false
).
include
?
(
:to_date
)
# Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
# If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
...
...
@@ -71,7 +71,7 @@ def to_time
# To be able to keep Times, Dates and DateTimes interchangeable on conversions
def
to_datetime
self
end
unless
method_defined
?
(
:to_datetime
)
end
unless
instance_methods
(
false
).
include
?
(
:to_datetime
)
def
self
.
civil_from_format
(
utc_or_local
,
year
,
month
=
1
,
day
=
1
,
hour
=
0
,
min
=
0
,
sec
=
0
)
offset
=
utc_or_local
.
to_sym
==
:local
?
local_offset
:
0
...
...
@@ -81,7 +81,7 @@ def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, se
# Converts datetime to an appropriate format for use in XML
def
xmlschema
strftime
(
"%Y-%m-%dT%H:%M:%S%Z"
)
end
unless
method_defined
?
(
:xmlschema
)
end
unless
instance_methods
(
false
).
include
?
(
:xmlschema
)
# Converts self to a floating-point number of seconds since the Unix epoch
def
to_f
...
...
activesupport/test/abstract_unit.rb
浏览文件 @
b97a3f33
...
...
@@ -18,7 +18,7 @@
require
'active_support'
# Include shims until we get off 1.8.6
require
'active_support/ruby/shim'
require
'active_support/ruby/shim'
if
RUBY_VERSION
<
'1.8.7'
def
uses_memcached
(
test_name
)
require
'memcache'
...
...
activesupport/test/core_ext/date_time_ext_test.rb
浏览文件 @
b97a3f33
...
...
@@ -26,11 +26,11 @@ def test_custom_date_format
end
def
test_to_date
assert_equal
Date
.
new
(
2005
,
2
,
21
),
DateTime
.
new
(
2005
,
2
,
21
).
to_date
assert_equal
Date
.
new
(
2005
,
2
,
21
),
DateTime
.
new
(
2005
,
2
,
21
,
14
,
30
,
0
).
to_date
end
def
test_to_datetime
assert_equal
DateTime
.
new
(
2005
,
2
,
21
),
DateTime
.
new
(
2005
,
2
,
21
).
to_datetime
assert_equal
DateTime
.
new
(
2005
,
2
,
21
,
14
,
30
,
0
),
DateTime
.
new
(
2005
,
2
,
21
,
14
,
30
,
0
).
to_datetime
end
def
test_to_time
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录