aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/caching_test.rb20
-rw-r--r--actionpack/test/controller/log_subscriber_test.rb8
-rw-r--r--actionpack/test/controller/mime_responds_test.rb1
-rw-r--r--actionpack/test/controller/new_base/content_type_test.rb18
-rw-r--r--actionpack/test/controller/test_test.rb16
-rw-r--r--actionpack/test/dispatch/routing_test.rb9
-rw-r--r--actionpack/test/template/erb_util_test.rb4
-rw-r--r--actionpack/test/template/form_options_helper_test.rb4
-rw-r--r--actionpack/test/template/url_helper_test.rb8
9 files changed, 58 insertions, 30 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 217260fdcd..115cc91467 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -53,16 +53,16 @@ class PageCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
-
@request = ActionController::TestRequest.new
@request.host = 'hostname.com'
@request.env.delete('PATH_INFO')
- @response = ActionController::TestResponse.new
@controller = PageCachingTestController.new
+ @controller.perform_caching = true
@controller.cache_store = :file_store, FILE_STORE_PATH
+ @response = ActionController::TestResponse.new
+
@params = {:controller => 'posts', :action => 'index', :only_path => true}
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
@@ -71,7 +71,7 @@ class PageCachingTest < ActionController::TestCase
def teardown
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
end
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
@@ -538,9 +538,9 @@ end
class FragmentCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
@controller = FragmentCachingTestController.new
+ @controller.perform_caching = true
@controller.cache_store = @store
@params = {:controller => 'posts', :action => 'index'}
@request = ActionController::TestRequest.new
@@ -564,7 +564,7 @@ class FragmentCachingTest < ActionController::TestCase
end
def test_read_fragment_with_caching_disabled
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
@store.write('views/name', 'value')
assert_nil @controller.read_fragment('name')
end
@@ -576,7 +576,7 @@ class FragmentCachingTest < ActionController::TestCase
end
def test_fragment_exist_with_caching_disabled
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
@store.write('views/name', 'value')
assert !@controller.fragment_exist?('name')
assert !@controller.fragment_exist?('other_name')
@@ -590,7 +590,7 @@ class FragmentCachingTest < ActionController::TestCase
def test_write_fragment_with_caching_disabled
assert_nil @store.read('views/name')
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
assert_equal 'value', @controller.write_fragment('name', 'value')
assert_nil @store.read('views/name')
end
@@ -614,7 +614,7 @@ class FragmentCachingTest < ActionController::TestCase
end
def test_fragment_for_with_disabled_caching
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
@store.write('views/expensive', 'fragment content')
fragment_computed = false
@@ -688,9 +688,9 @@ end
class FunctionalFragmentCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
@controller = FunctionalCachingController.new
+ @controller.perform_caching = true
@controller.cache_store = @store
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb
index 20d3e77b6e..b11eba2f89 100644
--- a/actionpack/test/controller/log_subscriber_test.rb
+++ b/actionpack/test/controller/log_subscriber_test.rb
@@ -143,7 +143,7 @@ class ACLogSubscriberTest < ActionController::TestCase
end
def test_with_fragment_cache
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
get :with_fragment_cache
wait
@@ -151,11 +151,11 @@ class ACLogSubscriberTest < ActionController::TestCase
assert_match /Exist fragment\? views\/foo/, logs[1]
assert_match /Write fragment views\/foo/, logs[2]
ensure
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
end
def test_with_page_cache
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
get :with_page_cache
wait
@@ -163,7 +163,7 @@ class ACLogSubscriberTest < ActionController::TestCase
assert_match /Write page/, logs[1]
assert_match /\/index\.html/, logs[1]
ensure
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
end
def logs
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 53cd3f0801..c8ba8bcaf3 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'controller/fake_models'
+require 'active_support/core_ext/hash/conversions'
class RespondToController < ActionController::Base
layout :set_layout
diff --git a/actionpack/test/controller/new_base/content_type_test.rb b/actionpack/test/controller/new_base/content_type_test.rb
index 700b71a7f3..33c2e442f0 100644
--- a/actionpack/test/controller/new_base/content_type_test.rb
+++ b/actionpack/test/controller/new_base/content_type_test.rb
@@ -21,17 +21,11 @@ module ContentType
self.view_paths = [ActionView::FixtureResolver.new(
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
- "content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
+ "content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
"content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'",
- "content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'",
- "content_type/implied/i_am_rjs_in_html.html.erb" => "<%= render 'i_am_rjs_partial' %>",
- "content_type/implied/_i_am_rjs_partial.js.rjs" => ""
+ "content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'",
+ "content_type/implied/i_am_js_rjs.js.rjs" => "page.alert 'hello'"
)]
-
- def i_am_html_erb() end
- def i_am_xml_erb() end
- def i_am_html_builder() end
- def i_am_xml_builder() end
end
class CharsetController < ActionController::Base
@@ -94,10 +88,10 @@ module ContentType
assert_header "Content-Type", "application/xml; charset=utf-8"
end
- test "sets Content-Type as text/html when rendering *.html.erb with a RJS partial" do
- get "/content_type/implied/i_am_rjs_in_html"
+ test "sets Content-Type as text/javascript when rendering *.js" do
+ get "/content_type/implied/i_am_js_rjs", "format" => "js"
- assert_header "Content-Type", "text/html; charset=utf-8"
+ assert_header "Content-Type", "text/javascript; charset=utf-8"
end
end
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 6f1ce2fef7..f9fc7a0976 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -113,6 +113,11 @@ XML
render :nothing => true
end
+ def test_assigns
+ @foo = "foo"
+ render :nothing => true
+ end
+
private
def rescue_action(e)
raise e
@@ -230,6 +235,17 @@ XML
assert_equal "OK", @response.body
end
+ def test_assigns
+ process :test_assigns
+ # assigns can be accessed using assigns(key)
+ # or assigns[key], where key is a string or
+ # a symbol
+ assert_equal "foo", assigns(:foo)
+ assert_equal "foo", assigns("foo")
+ assert_equal "foo", assigns[:foo]
+ assert_equal "foo", assigns["foo"]
+ end
+
def test_assert_tag_tag
process :test_html_output
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 8940990712..5bca476b27 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -54,6 +54,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match "/local/:action", :controller => "local"
+ match "/projects/status(.:format)"
+
constraints(:ip => /192\.168\.1\.\d\d\d/) do
get 'admin' => "queenbee#index"
end
@@ -426,6 +428,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_projects_status
+ with_test_routes do
+ assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true)
+ assert_equal '/projects/status.json', url_for(:controller => 'projects', :action => 'status', :format => 'json', :only_path => true)
+ end
+ end
+
def test_projects
with_test_routes do
get '/projects'
diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb
index 06155b1f30..d3129d0e1a 100644
--- a/actionpack/test/template/erb_util_test.rb
+++ b/actionpack/test/template/erb_util_test.rb
@@ -4,12 +4,12 @@ class ErbUtilTest < Test::Unit::TestCase
include ERB::Util
ERB::Util::HTML_ESCAPE.each do |given, expected|
- define_method "test_html_escape_#{expected.gsub /\W/, ''}" do
+ define_method "test_html_escape_#{expected.gsub(/\W/, '')}" do
assert_equal expected, html_escape(given)
end
unless given == '"'
- define_method "test_json_escape_#{expected.gsub /\W/, ''}" do
+ define_method "test_json_escape_#{expected.gsub(/\W/, '')}" do
assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given)
end
end
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 5799e3db53..98503c32fd 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -207,6 +207,10 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
+ def test_grouped_options_for_select_returns_html_safe_string
+ assert grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]]).html_safe?
+ end
+
def test_optgroups_with_with_options_with_hash
assert_dom_equal(
"<optgroup label=\"Europe\"><option value=\"Denmark\">Denmark</option>\n<option value=\"Germany\">Germany</option></optgroup><optgroup label=\"North America\"><option value=\"United States\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup>",
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index de63030714..4474949749 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -356,11 +356,15 @@ class UrlHelperTest < ActiveSupport::TestCase
end
def test_mail_to_with_javascript
- assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript")
+ snippet = mail_to("me@domain.com", "My email", :encode => "javascript")
+ assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", snippet
+ assert snippet.html_safe?
end
def test_mail_to_with_javascript_unicode
- assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%3e%c3%ba%6e%69%63%6f%64%65%3c%2f%61%3e%27%29%3b'))</script>", mail_to("unicode@example.com", "Ășnicode", :encode => "javascript")
+ snippet = mail_to("unicode@example.com", "Ășnicode", :encode => "javascript")
+ assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%3e%c3%ba%6e%69%63%6f%64%65%3c%2f%61%3e%27%29%3b'))</script>", snippet
+ assert snippet.html_safe
end
def test_mail_with_options