"
- end
- assert_select "div" do |elements|
- assert elements.size == 2
- assert_select "#1"
- assert_select "#2"
- end
- assert_select "div#?", /\d+/ do |elements|
- assert_select "#1"
- assert_select "#2"
- end
- end
-
- # With multiple results.
- def test_assert_select_from_rjs_with_multiple_results
- render_rjs do |page|
- page.replace_html "test", "
foo
"
- page.replace_html "test2", "
foo
"
- end
- assert_select "div" do |elements|
- assert elements.size == 2
- assert_select "#1"
- assert_select "#2"
- end
- end
-
- # With one result.
- def test_css_select_from_rjs_with_single_result
- render_rjs do |page|
- page.replace_html "test", "
foo
\n
foo
"
- end
- assert_equal 2, css_select("div").size
- assert_equal 1, css_select("#1").size
- assert_equal 1, css_select("#2").size
- end
-
- # With multiple results.
- def test_css_select_from_rjs_with_multiple_results
- render_rjs do |page|
- page.replace_html "test", "
foo
"
- page.replace_html "test2", "
foo
"
- end
-
- assert_equal 2, css_select("div").size
- assert_equal 1, css_select("#1").size
- assert_equal 1, css_select("#2").size
- end
-
- #
- # Test assert_select_rjs.
- #
-
- def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_arguments
- render_rjs do |page|
- page.insert_html :top, "test1", "
foo
"
- page.insert_html :bottom, "test2", "
foo
"
- end
- assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"}
- end
-
- # Test that we can pick up all statements in the result.
- def test_assert_select_rjs_picks_up_all_statements
- render_rjs do |page|
- page.replace "test", "
foo
"
- page.replace_html "test2", "
foo
"
- page.insert_html :top, "test3", "
foo
"
- end
-
- found = false
- assert_select_rjs do
- assert_select "#1"
- assert_select "#2"
- assert_select "#3"
- found = true
- end
- assert found
- end
-
- # Test that we fail if there is nothing to pick.
- def test_assert_select_rjs_fails_if_nothing_to_pick
- render_rjs { }
- assert_raise(Assertion) { assert_select_rjs }
- end
-
- def test_assert_select_rjs_with_unicode
- # Test that non-ascii characters (which are converted into \uXXXX in RJS) are decoded correctly.
-
- unicode = "\343\203\201\343\202\261\343\203\203\343\203\210"
- render_rjs do |page|
- page.replace "test", %(
#{unicode}
)
- end
-
- assert_select_rjs do
- str = "#1"
- assert_select str, :text => unicode
- assert_select str, unicode
- if str.respond_to?(:force_encoding)
- assert_select str, /\343\203\201..\343\203\210/u
- assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
- else
- assert_select str, Regexp.new("\343\203\201..\343\203\210", 0, 'U')
- assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210", 0, 'U') }
- end
- end
- end
-
- def test_assert_select_rjs_with_id
- # Test that we can pick up all statements in the result.
- render_rjs do |page|
- page.replace "test1", "
foo
"
- page.replace_html "test2", "
foo
"
- page.insert_html :top, "test3", "
foo
"
- end
- assert_select_rjs "test1" do
- assert_select "div", 1
- assert_select "#1"
- end
- assert_select_rjs "test2" do
- assert_select "div", 1
- assert_select "#2"
- end
- assert_select_rjs "test3" do
- assert_select "div", 1
- assert_select "#3"
- end
- assert_raise(Assertion) { assert_select_rjs "test4" }
- end
-
- def test_assert_select_rjs_for_replace
- render_rjs do |page|
- page.replace "test1", "
foo
"
- page.replace_html "test2", "
foo
"
- page.insert_html :top, "test3", "
foo
"
- end
- # Replace.
- assert_select_rjs :replace do
- assert_select "div", 1
- assert_select "#1"
- end
- assert_select_rjs :replace, "test1" do
- assert_select "div", 1
- assert_select "#1"
- end
- assert_raise(Assertion) { assert_select_rjs :replace, "test2" }
- # Replace HTML.
- assert_select_rjs :replace_html do
- assert_select "div", 1
- assert_select "#2"
- end
- assert_select_rjs :replace_html, "test2" do
- assert_select "div", 1
- assert_select "#2"
- end
- assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
- end
-
- def test_assert_select_rjs_for_chained_replace
- render_rjs do |page|
- page['test1'].replace "
foo
"
- page['test2'].replace_html "
foo
"
- page.insert_html :top, "test3", "
foo
"
- end
- # Replace.
- assert_select_rjs :chained_replace do
- assert_select "div", 1
- assert_select "#1"
- end
- assert_select_rjs :chained_replace, "test1" do
- assert_select "div", 1
- assert_select "#1"
- end
- assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" }
- # Replace HTML.
- assert_select_rjs :chained_replace_html do
- assert_select "div", 1
- assert_select "#2"
- end
- assert_select_rjs :chained_replace_html, "test2" do
- assert_select "div", 1
- assert_select "#2"
- end
- assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
- end
-
- # Simple remove
- def test_assert_select_rjs_for_remove
- render_rjs do |page|
- page.remove "test1"
- end
-
- assert_select_rjs :remove, "test1"
- end
-
- def test_assert_select_rjs_for_remove_offers_useful_error_when_assertion_fails
- render_rjs do |page|
- page.remove "test_with_typo"
- end
-
- assert_select_rjs :remove, "test1"
-
- rescue Assertion => e
- assert_equal "No RJS statement that removes 'test1' was rendered.", e.message
- end
-
- def test_assert_select_rjs_for_remove_ignores_block
- render_rjs do |page|
- page.remove "test1"
- end
-
- assert_nothing_raised do
- assert_select_rjs :remove, "test1" do
- assert_select "p"
- end
- end
- end
-
- # Simple show
- def test_assert_select_rjs_for_show
- render_rjs do |page|
- page.show "test1"
- end
-
- assert_select_rjs :show, "test1"
- end
-
- def test_assert_select_rjs_for_show_offers_useful_error_when_assertion_fails
- render_rjs do |page|
- page.show "test_with_typo"
- end
-
- assert_select_rjs :show, "test1"
-
- rescue Assertion => e
- assert_equal "No RJS statement that shows 'test1' was rendered.", e.message
- end
-
- def test_assert_select_rjs_for_show_ignores_block
- render_rjs do |page|
- page.show "test1"
- end
-
- assert_nothing_raised do
- assert_select_rjs :show, "test1" do
- assert_select "p"
- end
- end
- end
-
- # Simple hide
- def test_assert_select_rjs_for_hide
- render_rjs do |page|
- page.hide "test1"
- end
-
- assert_select_rjs :hide, "test1"
- end
-
- def test_assert_select_rjs_for_hide_offers_useful_error_when_assertion_fails
- render_rjs do |page|
- page.hide "test_with_typo"
- end
-
- assert_select_rjs :hide, "test1"
-
- rescue Assertion => e
- assert_equal "No RJS statement that hides 'test1' was rendered.", e.message
- end
-
- def test_assert_select_rjs_for_hide_ignores_block
- render_rjs do |page|
- page.hide "test1"
- end
-
- assert_nothing_raised do
- assert_select_rjs :hide, "test1" do
- assert_select "p"
- end
- end
- end
-
- # Simple toggle
- def test_assert_select_rjs_for_toggle
- render_rjs do |page|
- page.toggle "test1"
- end
-
- assert_select_rjs :toggle, "test1"
- end
-
- def test_assert_select_rjs_for_toggle_offers_useful_error_when_assertion_fails
- render_rjs do |page|
- page.toggle "test_with_typo"
- end
-
- assert_select_rjs :toggle, "test1"
-
- rescue Assertion => e
- assert_equal "No RJS statement that toggles 'test1' was rendered.", e.message
- end
-
- def test_assert_select_rjs_for_toggle_ignores_block
- render_rjs do |page|
- page.toggle "test1"
- end
-
- assert_nothing_raised do
- assert_select_rjs :toggle, "test1" do
- assert_select "p"
- end
- end
- end
-
- # Non-positioned insert.
- def test_assert_select_rjs_for_nonpositioned_insert
- render_rjs do |page|
- page.replace "test1", "
foo
"
- page.replace_html "test2", "
foo
"
- page.insert_html :top, "test3", "
foo
"
- end
- assert_select_rjs :insert_html do
- assert_select "div", 1
- assert_select "#3"
- end
- assert_select_rjs :insert_html, "test3" do
- assert_select "div", 1
- assert_select "#3"
- end
- assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" }
- end
-
- # Positioned insert.
- def test_assert_select_rjs_for_positioned_insert
- render_rjs do |page|
- page.insert_html :top, "test1", "
foo
"
- page.insert_html :bottom, "test2", "
foo
"
- page.insert_html :before, "test3", "
foo
"
- page.insert_html :after, "test4", "
foo
"
- end
- assert_select_rjs :insert, :top do
- assert_select "div", 1
- assert_select "#1"
- end
- assert_select_rjs :insert, :bottom do
- assert_select "div", 1
- assert_select "#2"
- end
- assert_select_rjs :insert, :before do
- assert_select "div", 1
- assert_select "#3"
- end
- assert_select_rjs :insert, :after do
- assert_select "div", 1
- assert_select "#4"
- end
- assert_select_rjs :insert_html do
- assert_select "div", 4
- end
- end
-
- def test_assert_select_rjs_raise_errors
- assert_raise(ArgumentError) { assert_select_rjs(:destroy) }
- assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) }
- end
-
- # Simple selection from a single result.
- def test_nested_assert_select_rjs_with_single_result
- render_rjs do |page|
- page.replace_html "test", "
foo
\n
foo
"
- end
-
- assert_select_rjs "test" do |elements|
- assert_equal 2, elements.size
- assert_select "#1"
- assert_select "#2"
- end
- end
-
- # Deal with two results.
- def test_nested_assert_select_rjs_with_two_results
- render_rjs do |page|
- page.replace_html "test", "
foo
"
- page.replace_html "test2", "
foo
"
- end
-
- assert_select_rjs "test" do |elements|
- assert_equal 1, elements.size
- assert_select "#1"
- end
-
- assert_select_rjs "test2" do |elements|
- assert_equal 1, elements.size
- assert_select "#2"
- end
- end
-
- def test_assert_select_rjs_for_redirect_to
- render_rjs do |page|
- page.redirect_to '/'
- end
- assert_select_rjs :redirect, '/'
- end
-
- protected
- def render_html(html)
- @controller.response_with = html
- get :html
- end
-
- def render_rjs(&block)
- @controller.response_with(&block)
- get :rjs
- end
-
- def render_xml(xml)
- @controller.response_with = xml
- get :xml
- end
-end
diff --git a/test/controller/caching_test.rb b/test/controller/caching_test.rb
index 5bc1617..20ce6c8 100644
--- a/test/controller/caching_test.rb
+++ b/test/controller/caching_test.rb
@@ -30,7 +30,7 @@ def setup
@controller = FunctionalCachingController.new
@controller.perform_caching = true
@controller.cache_store = @store
- @request = ActionController::TestRequest.new
+ @request = ActionController::TestRequest.create
@response = ActionController::TestResponse.new
end
diff --git a/test/controller/content_type_test.rb b/test/controller/content_type_test.rb
index db32e11..ca6a882 100644
--- a/test/controller/content_type_test.rb
+++ b/test/controller/content_type_test.rb
@@ -10,7 +10,7 @@ class ContentTypeTest < ActionController::TestCase
def test_default_for_rjs
xhr :post, :render_default_for_rjs
- assert_equal Mime::JS, @response.content_type
+ assert_equal Mime[:js], @response.content_type
assert_equal "utf-8", @response.charset
end
end
diff --git a/test/controller/mime_responds_test.rb b/test/controller/mime_responds_test.rb
index 280b4b7..262e45c 100644
--- a/test/controller/mime_responds_test.rb
+++ b/test/controller/mime_responds_test.rb
@@ -184,10 +184,13 @@ def test_xhr
end
class RespondWithController < ActionController::Base
- respond_to :html, :json, :js
def using_resource
- respond_with(resource)
+ respond_to do |format|
+ format.html { render html: resource }
+ format.json { render json: resource }
+ format.js { render js: resource }
+ end
end
protected
@@ -196,7 +199,7 @@ def resource
end
def _render_js(js, options)
- self.content_type ||= Mime::JS
+ self.content_type ||= Mime[:js]
self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
end
diff --git a/test/controller/render_js_test.rb b/test/controller/render_js_test.rb
index 5b9c550..59e0a3e 100644
--- a/test/controller/render_js_test.rb
+++ b/test/controller/render_js_test.rb
@@ -2,7 +2,6 @@
class RenderJSTest < ActionController::TestCase
class TestController < ActionController::Base
- protect_from_forgery
def self.controller_path
'test'
diff --git a/test/javascript_helper_test.rb b/test/javascript_helper_test.rb
index c79b067..daad92d 100644
--- a/test/javascript_helper_test.rb
+++ b/test/javascript_helper_test.rb
@@ -26,14 +26,14 @@ def test_link_to_function_with_rjs_block
html = link_to_function( "Greet me!" ) do |page|
page.replace_html 'header', "
Greetings
"
end
- assert_dom_equal %(Greet me!), html
+ assert_dom_equal %(Greet me!), html
end
def test_link_to_function_with_rjs_block_and_options
html = link_to_function( "Greet me!", :class => "updater" ) do |page|
page.replace_html 'header', "
Greetings
"
end
- assert_dom_equal %(Greet me!), html
+ assert_dom_equal %(Greet me!), html
end
def test_link_to_function_with_inner_block_does_not_raise_exception
@@ -42,20 +42,20 @@ def test_link_to_function_with_inner_block_does_not_raise_exception
'Greetings'
end)
end
- assert_dom_equal %(Greet me!), html
+ assert_dom_equal %(Greet me!), html
end
def test_button_to_function_with_rjs_block
html = button_to_function( "Greet me!" ) do |page|
page.replace_html 'header', "
Greetings
"
end
- assert_dom_equal %(), html
+ assert_dom_equal %(), html
end
def test_button_to_function_with_rjs_block_and_options
html = button_to_function( "Greet me!", :class => "greeter" ) do |page|
page.replace_html 'header', "
Greetings
"
end
- assert_dom_equal %(), html
+ assert_dom_equal %(), html
end
-end
\ No newline at end of file
+end
diff --git a/test/render_other_test.rb b/test/render_other_test.rb
index 27a533e..e72ba43 100644
--- a/test/render_other_test.rb
+++ b/test/render_other_test.rb
@@ -3,13 +3,12 @@
require 'securerandom'
ActionController.add_renderer :simon do |says, options|
- self.content_type = Mime::TEXT
+ self.content_type = Mime[:text]
self.response_body = "Simon says: #{says}"
end
class RenderOtherTest < ActionController::TestCase
class TestController < ActionController::Base
- protect_from_forgery
def self.controller_path
'test'
diff --git a/test/template/prototype_helper_test.rb b/test/template/prototype_helper_test.rb
index a6aa848..685bb67 100644
--- a/test/template/prototype_helper_test.rb
+++ b/test/template/prototype_helper_test.rb
@@ -142,23 +142,23 @@ def teardown
def _evaluate_assigns_and_ivars() end
def test_insert_html_with_string
- assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });',
+ assert_equal 'Element.insert("element", { top: "\\u003cp\\u003eThis is a test\\u003c/p\\u003e" });',
@generator.insert_html(:top, 'element', '
This is a test
')
- assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
+ assert_equal 'Element.insert("element", { bottom: "\\u003cp\u003eThis is a test\\u003c/p\u003e" });',
@generator.insert_html(:bottom, 'element', '
This is a test
')
- assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
+ assert_equal 'Element.insert("element", { before: "\\u003cp\u003eThis is a test\\u003c/p\u003e" });',
@generator.insert_html(:before, 'element', '
This is a test
')
- assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
+ assert_equal 'Element.insert("element", { after: "\\u003cp\u003eThis is a test\\u003c/p\u003e" });',
@generator.insert_html(:after, 'element', '
This is a test
')
end
def test_replace_html_with_string
- assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
+ assert_equal 'Element.update("element", "\\u003cp\\u003eThis is a test\\u003c/p\\u003e");',
@generator.replace_html('element', '
This is a test
')
end
def test_replace_element_with_string
- assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");',
+ assert_equal 'Element.replace("element", "\\u003cdiv id=\"element\"\\u003e\\u003cp\\u003eThis is a test\\u003c/p\\u003e\\u003c/div\\u003e");',
@generator.replace('element', '
This is a test
')
end
@@ -221,10 +221,10 @@ def test_to_s
@generator.replace_html('baz', '
This is a test
')
assert_equal <<-EOS.chomp, @generator.to_s
-Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
-Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
+Element.insert("element", { top: "\\u003cp\\u003eThis is a test\\u003c/p\\u003e" });
+Element.insert("element", { bottom: "\\u003cp\\u003eThis is a test\\u003c/p\\u003e" });
["foo","bar"].each(Element.remove);
-Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
+Element.update("baz", "\\u003cp\\u003eThis is a test\\u003c/p\\u003e");
EOS
end