parent
de78c7e8e4
commit
7276fc63be
|
@ -1,15 +0,0 @@
|
|||
module TestingSandbox
|
||||
# Temporarily replaces KCODE for the block
|
||||
def with_kcode(kcode)
|
||||
if RUBY_VERSION < '1.9'
|
||||
old_kcode, $KCODE = $KCODE, kcode
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
$KCODE = old_kcode
|
||||
end
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,7 @@
|
|||
require 'abstract_unit'
|
||||
require 'testing_sandbox'
|
||||
|
||||
class OutputSafetyHelperTest < ActionView::TestCase
|
||||
tests ActionView::Helpers::OutputSafetyHelper
|
||||
include TestingSandbox
|
||||
|
||||
def setup
|
||||
@string = "hello"
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
require 'abstract_unit'
|
||||
require 'testing_sandbox'
|
||||
|
||||
# The exhaustive tests are in test/controller/html/sanitizer_test.rb.
|
||||
# This tests the that the helpers hook up correctly to the sanitizer classes.
|
||||
class SanitizeHelperTest < ActionView::TestCase
|
||||
tests ActionView::Helpers::SanitizeHelper
|
||||
include TestingSandbox
|
||||
|
||||
def test_strip_links
|
||||
assert_equal "Dont touch me", strip_links("Dont touch me")
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# encoding: utf-8
|
||||
require 'abstract_unit'
|
||||
require 'testing_sandbox'
|
||||
|
||||
class TextHelperTest < ActionView::TestCase
|
||||
tests ActionView::Helpers::TextHelper
|
||||
include TestingSandbox
|
||||
|
||||
def setup
|
||||
super
|
||||
|
|
|
@ -56,18 +56,5 @@ module ActiveRecord
|
|||
ensure
|
||||
ActiveRecord::SQLCounter.ignored_sql = prev_ignored_sql
|
||||
end
|
||||
|
||||
def with_kcode(kcode)
|
||||
if RUBY_VERSION < '1.9'
|
||||
orig_kcode, $KCODE = $KCODE, kcode
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
$KCODE = orig_kcode
|
||||
end
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -91,14 +91,12 @@ class AssociationValidationTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_validates_size_of_association_utf8
|
||||
with_kcode('UTF8') do
|
||||
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
|
||||
o = Owner.new('name' => 'あいうえおかきくけこ')
|
||||
assert !o.save
|
||||
assert o.errors[:pets].any?
|
||||
o.pets.build('name' => 'あいうえおかきくけこ')
|
||||
assert o.valid?
|
||||
end
|
||||
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
|
||||
o = Owner.new('name' => 'あいうえおかきくけこ')
|
||||
assert !o.save
|
||||
assert o.errors[:pets].any?
|
||||
o.pets.build('name' => 'あいうえおかきくけこ')
|
||||
assert o.valid?
|
||||
end
|
||||
|
||||
def test_validates_presence_of_belongs_to_association__parent_is_new_record
|
||||
|
|
|
@ -149,16 +149,14 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|||
assert t2.valid?, "should validate with nil"
|
||||
assert t2.save, "should save with nil"
|
||||
|
||||
with_kcode('UTF8') do
|
||||
t_utf8 = Topic.new("title" => "Я тоже уникальный!")
|
||||
assert t_utf8.save, "Should save t_utf8 as unique"
|
||||
t_utf8 = Topic.new("title" => "Я тоже уникальный!")
|
||||
assert t_utf8.save, "Should save t_utf8 as unique"
|
||||
|
||||
# If database hasn't UTF-8 character set, this test fails
|
||||
if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
|
||||
t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
|
||||
assert !t2_utf8.valid?, "Shouldn't be valid"
|
||||
assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
|
||||
end
|
||||
# If database hasn't UTF-8 character set, this test fails
|
||||
if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
|
||||
t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
|
||||
assert !t2_utf8.valid?, "Shouldn't be valid"
|
||||
assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -256,13 +254,11 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_validate_uniqueness_with_limit_and_utf8
|
||||
with_kcode('UTF8') do
|
||||
# Event.title is limited to 5 characters
|
||||
e1 = Event.create(:title => "一二三四五")
|
||||
assert e1.valid?, "Could not create an event with a unique, 5 character title"
|
||||
e2 = Event.create(:title => "一二三四五六七八")
|
||||
assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
|
||||
end
|
||||
# Event.title is limited to 5 characters
|
||||
e1 = Event.create(:title => "一二三四五")
|
||||
assert e1.valid?, "Could not create an event with a unique, 5 character title"
|
||||
e2 = Event.create(:title => "一二三四五六七八")
|
||||
assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
|
||||
end
|
||||
|
||||
def test_validate_straight_inheritance_uniqueness
|
||||
|
|
Loading…
Reference in New Issue