aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-02-01 23:42:38 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-02-01 23:42:38 +0000
commitfdcf4d6c5191b25ee3b6c357dafaf17156eb09d3 (patch)
tree347f771202054a443f9df23a8f65f91d49a52209 /activesupport/test
parent27fa38cc3e162b2f8c4bb2d50130fbc17bad6039 (diff)
parent16c0d1d3b6089bb4b0b0baf7c3eeb5949f31f02b (diff)
downloadrails-fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3.tar.gz
rails-fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3.tar.bz2
rails-fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3.zip
Merge remote branch 'mainstream/master'
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/abstract_unit.rb10
-rw-r--r--activesupport/test/callbacks_test.rb8
-rw-r--r--activesupport/test/core_ext/class/attribute_test.rb47
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb67
-rw-r--r--activesupport/test/fixtures/custom.rb2
-rw-r--r--activesupport/test/fixtures/omgomg.rb2
-rw-r--r--activesupport/test/isolation_test.rb12
-rw-r--r--activesupport/test/multibyte_chars_test.rb22
-rw-r--r--activesupport/test/notifications_test.rb6
-rw-r--r--activesupport/test/safe_buffer_test.rb41
10 files changed, 149 insertions, 68 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb
index d91e0415c4..33be6f65bf 100644
--- a/activesupport/test/abstract_unit.rb
+++ b/activesupport/test/abstract_unit.rb
@@ -1,12 +1,4 @@
-ORIG_ARGV = ARGV.dup
-
-begin
- require File.expand_path('../../../vendor/gems/environment', __FILE__)
-rescue LoadError
-end
-
-lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
+require File.expand_path('../../../load_paths', __FILE__)
require 'test/unit'
require 'mocha'
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index df98644436..11494e951e 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -264,12 +264,12 @@ module CallbacksTest
define_callbacks :save
attr_reader :stuff
- set_callback :save, :before, :omg, :per_key => {:if => :yes}
+ set_callback :save, :before, :action, :per_key => {:if => :yes}
def yes() true end
- def omg
- @stuff = "OMG"
+ def action
+ @stuff = "ACTION"
end
def save
@@ -522,7 +522,7 @@ module CallbacksTest
def test_save
obj = HyphenatedCallbacks.new
obj.save
- assert_equal obj.stuff, "OMG"
+ assert_equal obj.stuff, "ACTION"
end
end
end
diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb
new file mode 100644
index 0000000000..ef84b9f255
--- /dev/null
+++ b/activesupport/test/core_ext/class/attribute_test.rb
@@ -0,0 +1,47 @@
+require 'abstract_unit'
+require 'active_support/core_ext/class/attribute'
+
+class ClassAttributeTest < ActiveSupport::TestCase
+ class Base
+ class_attribute :setting
+ end
+
+ class Subclass < Base
+ end
+
+ def setup
+ @klass = Class.new { class_attribute :setting }
+ @sub = Class.new(@klass)
+ end
+
+ test 'defaults to nil' do
+ assert_nil @klass.setting
+ assert_nil @sub.setting
+ end
+
+ test 'inheritable' do
+ @klass.setting = 1
+ assert_equal 1, @sub.setting
+ end
+
+ test 'overridable' do
+ @sub.setting = 1
+ assert_nil @klass.setting
+
+ @klass.setting = 2
+ assert_equal 1, @sub.setting
+
+ assert_equal 1, Class.new(@sub).setting
+ end
+
+ test 'query method' do
+ assert_equal false, @klass.setting?
+ @klass.setting = 1
+ assert_equal true, @klass.setting?
+ end
+
+ test 'no instance delegates' do
+ assert_raise(NoMethodError) { @klass.new.setting }
+ assert_raise(NoMethodError) { @klass.new.setting? }
+ end
+end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 9a805bc010..ca26f91e8c 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -342,12 +342,12 @@ class OutputSafetyTest < ActiveSupport::TestCase
end
test "A string can be marked safe" do
- @string.html_safe!
- assert @string.html_safe?
+ string = @string.html_safe
+ assert string.html_safe?
end
test "Marking a string safe returns the string" do
- assert_equal @string, @string.html_safe!
+ assert_equal @string, @string.html_safe
end
test "A fixnum is safe by default" do
@@ -361,7 +361,7 @@ class OutputSafetyTest < ActiveSupport::TestCase
end
end
- @string.html_safe!
+ @string.html_safe
@string << klass.new
assert_equal "helloother", @string
@@ -369,44 +369,44 @@ class OutputSafetyTest < ActiveSupport::TestCase
end
test "Adding a safe string to another safe string returns a safe string" do
- @other_string = "other".html_safe!
- @string.html_safe!
- @combination = @other_string + @string
+ @other_string = "other".html_safe
+ string = @string.html_safe
+ @combination = @other_string + string
assert_equal "otherhello", @combination
assert @combination.html_safe?
end
- test "Adding an unsafe string to a safe string returns an unsafe string" do
- @other_string = "other".html_safe!
- @combination = @other_string + @string
- @other_combination = @string + @other_string
+ test "Adding an unsafe string to a safe string escapes it and returns a safe string" do
+ @other_string = "other".html_safe
+ @combination = @other_string + "<foo>"
+ @other_combination = @string + "<foo>"
- assert_equal "otherhello", @combination
- assert_equal "helloother", @other_combination
+ assert_equal "other&lt;foo&gt;", @combination
+ assert_equal "hello<foo>", @other_combination
- assert !@combination.html_safe?
+ assert @combination.html_safe?
assert !@other_combination.html_safe?
end
test "Concatting safe onto unsafe yields unsafe" do
@other_string = "other"
- @string.html_safe!
+ @string.html_safe
@other_string.concat(@string)
assert !@other_string.html_safe?
end
- test "Concatting unsafe onto safe yields unsafe" do
- @other_string = "other".html_safe!
-
- @other_string.concat(@string)
- assert !@other_string.html_safe?
+ test "Concatting unsafe onto safe yields escaped safe" do
+ @other_string = "other".html_safe
+ string = @other_string.concat("<foo>")
+ assert_equal "other&lt;foo&gt;", string
+ assert string.html_safe?
end
test "Concatting safe onto safe yields safe" do
- @other_string = "other".html_safe!
- @string.html_safe!
+ @other_string = "other".html_safe
+ @string.html_safe
@other_string.concat(@string)
assert @other_string.html_safe?
@@ -414,31 +414,32 @@ class OutputSafetyTest < ActiveSupport::TestCase
test "Concatting safe onto unsafe with << yields unsafe" do
@other_string = "other"
- @string.html_safe!
+ @string.html_safe
@other_string << @string
assert !@other_string.html_safe?
end
- test "Concatting unsafe onto safe with << yields unsafe" do
- @other_string = "other".html_safe!
-
- @other_string << @string
- assert !@other_string.html_safe?
+ test "Concatting unsafe onto safe with << yields escaped safe" do
+ @other_string = "other".html_safe
+ string = @other_string << "<foo>"
+ assert_equal "other&lt;foo&gt;", string
+ assert string.html_safe?
end
test "Concatting safe onto safe with << yields safe" do
- @other_string = "other".html_safe!
- @string.html_safe!
+ @other_string = "other".html_safe
+ @string.html_safe
@other_string << @string
assert @other_string.html_safe?
end
test "Concatting a fixnum to safe always yields safe" do
- @string.html_safe!
- @string.concat(13)
- assert @string.html_safe?
+ string = @string.html_safe
+ string = string.concat(13)
+ assert_equal "hello".concat(13), string
+ assert string.html_safe?
end
end
diff --git a/activesupport/test/fixtures/custom.rb b/activesupport/test/fixtures/custom.rb
new file mode 100644
index 0000000000..0eefce0c25
--- /dev/null
+++ b/activesupport/test/fixtures/custom.rb
@@ -0,0 +1,2 @@
+class Custom
+end \ No newline at end of file
diff --git a/activesupport/test/fixtures/omgomg.rb b/activesupport/test/fixtures/omgomg.rb
deleted file mode 100644
index a512a93ae4..0000000000
--- a/activesupport/test/fixtures/omgomg.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-class OmgOmg
-end \ No newline at end of file
diff --git a/activesupport/test/isolation_test.rb b/activesupport/test/isolation_test.rb
index a7af5e96f6..2c2986ea28 100644
--- a/activesupport/test/isolation_test.rb
+++ b/activesupport/test/isolation_test.rb
@@ -59,15 +59,15 @@ elsif ENV['CHILD']
end
test "resets requires one" do
- assert !defined?(OmgOmg)
- assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
- require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
+ assert !defined?(Custom)
+ assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/custom/).size
+ require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "custom"))
end
test "resets requires two" do
- assert !defined?(OmgOmg)
- assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
- require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
+ assert !defined?(Custom)
+ assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/custom/).size
+ require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "custom"))
end
end
else
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 0e489c10e1..0f68dcfe23 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -301,10 +301,10 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_equal " #{UNICODE_STRING}", @chars.rjust(5)
assert_equal " #{UNICODE_STRING}", @chars.rjust(7)
assert_equal "---#{UNICODE_STRING}", @chars.rjust(7, '-')
- assert_equal "ααα#{UNICODE_STRING}", @chars.rjust(7, 'α')
+ assert_equal "αα#{UNICODE_STRING}", @chars.rjust(7, 'α')
assert_equal "aba#{UNICODE_STRING}", @chars.rjust(7, 'ab')
assert_equal "αηα#{UNICODE_STRING}", @chars.rjust(7, 'αη')
- assert_equal "αηαη#{UNICODE_STRING}", @chars.rjust(8, 'αη')
+ assert_equal "αη#{UNICODE_STRING}", @chars.rjust(8, 'αη')
end
def test_ljust_should_raise_argument_errors_on_bad_arguments
@@ -319,10 +319,10 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_equal "#{UNICODE_STRING} ", @chars.ljust(5)
assert_equal "#{UNICODE_STRING} ", @chars.ljust(7)
assert_equal "#{UNICODE_STRING}---", @chars.ljust(7, '-')
- assert_equal "#{UNICODE_STRING}ααα", @chars.ljust(7, 'α')
+ assert_equal "#{UNICODE_STRING}αα", @chars.ljust(7, 'α')
assert_equal "#{UNICODE_STRING}aba", @chars.ljust(7, 'ab')
assert_equal "#{UNICODE_STRING}αηα", @chars.ljust(7, 'αη')
- assert_equal "#{UNICODE_STRING}αηαη", @chars.ljust(8, 'αη')
+ assert_equal "#{UNICODE_STRING}αη", @chars.ljust(8, 'αη')
end
def test_center_should_raise_argument_errors_on_bad_arguments
@@ -339,13 +339,13 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_equal " #{UNICODE_STRING} ", @chars.center(7)
assert_equal "--#{UNICODE_STRING}--", @chars.center(8, '-')
assert_equal "--#{UNICODE_STRING}---", @chars.center(9, '-')
- assert_equal "αα#{UNICODE_STRING}αα", @chars.center(8, 'α')
- assert_equal "αα#{UNICODE_STRING}ααα", @chars.center(9, 'α')
- assert_equal "a#{UNICODE_STRING}ab", @chars.center(7, 'ab')
- assert_equal "ab#{UNICODE_STRING}ab", @chars.center(8, 'ab')
- assert_equal "abab#{UNICODE_STRING}abab", @chars.center(12, 'ab')
- assert_equal "α#{UNICODE_STRING}αη", @chars.center(7, 'αη')
- assert_equal "αη#{UNICODE_STRING}αη", @chars.center(8, 'αη')
+ assert_equal "α#{UNICODE_STRING}α", @chars.center(8, 'α')
+ assert_equal "α#{UNICODE_STRING}αα", @chars.center(9, 'α')
+ assert_equal "a#{UNICODE_STRING}", @chars.center(7, 'ab')
+ assert_equal UNICODE_STRING, @chars.center(8, 'ab')
+ assert_equal "ab#{UNICODE_STRING}ab", @chars.center(12, 'ab')
+ assert_equal "α#{UNICODE_STRING}", @chars.center(7, 'αη')
+ assert_equal UNICODE_STRING, @chars.center(8, 'αη')
end
def test_lstrip_strips_whitespace_from_the_left_of_the_string
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index d3af535c26..0b78b53c73 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -77,7 +77,7 @@ module Notifications
def test_instrument_with_bang_returns_result_even_on_failure
begin
instrument!(:awesome, :payload => "notifications") do
- raise "OMG"
+ raise "FAIL"
end
flunk
rescue
@@ -126,10 +126,10 @@ module Notifications
def test_instrument_does_not_publish_when_exception_is_raised
begin
instrument(:awesome, :payload => "notifications") do
- raise "OMG"
+ raise "FAIL"
end
rescue RuntimeError => e
- assert_equal "OMG", e.message
+ assert_equal "FAIL", e.message
end
drain
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
new file mode 100644
index 0000000000..bf61f9e58c
--- /dev/null
+++ b/activesupport/test/safe_buffer_test.rb
@@ -0,0 +1,41 @@
+require 'abstract_unit'
+
+class SafeBufferTest < ActiveSupport::TestCase
+ def setup
+ @buffer = ActiveSupport::SafeBuffer.new
+ end
+
+ test "Should look like a string" do
+ assert @buffer.is_a?(String)
+ assert_equal "", @buffer
+ end
+
+ test "Should escape a raw string which is passed to them" do
+ @buffer << "<script>"
+ assert_equal "&lt;script&gt;", @buffer
+ end
+
+ test "Should NOT escape a safe value passed to it" do
+ @buffer << "<script>".html_safe
+ assert_equal "<script>", @buffer
+ end
+
+ test "Should not mess with an innocuous string" do
+ @buffer << "Hello"
+ assert_equal "Hello", @buffer
+ end
+
+ test "Should not mess with a previously escape test" do
+ @buffer << ERB::Util.html_escape("<script>")
+ assert_equal "&lt;script&gt;", @buffer
+ end
+
+ test "Should be considered safe" do
+ assert @buffer.html_safe?
+ end
+
+ test "Should return a safe buffer when calling to_s" do
+ new_buffer = @buffer.to_s
+ assert_equal ActiveSupport::SafeBuffer, new_buffer.class
+ end
+end