提交 d40e3ea9 编写于 作者: R Raimonds Simanovskis

Oracle saves empty string as NULL

上级 71c32d3c
......@@ -154,7 +154,8 @@ def test_should_save_parent_but_not_invalid_child
end
def test_save_fails_for_invalid_belongs_to
assert log = AuditLog.create(:developer_id => 0, :message => "")
# Oracle saves empty string as NULL therefore :message changed to one space
assert log = AuditLog.create(:developer_id => 0, :message => " ")
log.developer = Developer.new
assert !log.developer.valid?
......@@ -164,7 +165,8 @@ def test_save_fails_for_invalid_belongs_to
end
def test_save_succeeds_for_invalid_belongs_to_with_validate_false
assert log = AuditLog.create(:developer_id => 0, :message=> "")
# Oracle saves empty string as NULL therefore :message changed to one space
assert log = AuditLog.create(:developer_id => 0, :message=> " ")
log.unvalidated_developer = Developer.new
assert !log.unvalidated_developer.valid?
......@@ -666,7 +668,12 @@ def test_should_still_allow_to_bypass_validations_on_the_associated_model
@pirate.catchphrase = ''
@pirate.ship.name = ''
@pirate.save(false)
assert_equal ['', ''], [@pirate.reload.catchphrase, @pirate.ship.name]
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil], [@pirate.reload.catchphrase, @pirate.ship.name]
else
assert_equal ['', ''], [@pirate.reload.catchphrase, @pirate.ship.name]
end
end
def test_should_allow_to_bypass_validations_on_associated_models_at_any_depth
......@@ -678,7 +685,12 @@ def test_should_allow_to_bypass_validations_on_associated_models_at_any_depth
@pirate.save(false)
values = [@pirate.reload.catchphrase, @pirate.ship.name, *@pirate.ship.parts.map(&:name)]
assert_equal ['', '', '', ''], values
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil, nil, nil], values
else
assert_equal ['', '', '', ''], values
end
end
def test_should_still_raise_an_ActiveRecordRecord_Invalid_exception_if_we_want_that
......@@ -756,7 +768,12 @@ def test_should_still_allow_to_bypass_validations_on_the_associated_model
@ship.pirate.catchphrase = ''
@ship.name = ''
@ship.save(false)
assert_equal ['', ''], [@ship.reload.name, @ship.pirate.catchphrase]
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil], [@ship.reload.name, @ship.pirate.catchphrase]
else
assert_equal ['', ''], [@ship.reload.name, @ship.pirate.catchphrase]
end
end
def test_should_still_raise_an_ActiveRecordRecord_Invalid_exception_if_we_want_that
......@@ -837,11 +854,20 @@ def test_should_allow_to_bypass_validations_on_the_associated_models_on_update
@pirate.send(@association_name).each { |child| child.name = '' }
assert @pirate.save(false)
assert_equal ['', '', ''], [
@pirate.reload.catchphrase,
@pirate.send(@association_name).first.name,
@pirate.send(@association_name).last.name
]
# Oracle saves empty string as NULL
if current_adapter?(:OracleAdapter)
assert_equal [nil, nil, nil], [
@pirate.reload.catchphrase,
@pirate.send(@association_name).first.name,
@pirate.send(@association_name).last.name
]
else
assert_equal ['', '', ''], [
@pirate.reload.catchphrase,
@pirate.send(@association_name).first.name,
@pirate.send(@association_name).last.name
]
end
end
def test_should_validation_the_associated_models_on_create
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册