aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/cookie_test.rb6
-rw-r--r--actionpack/test/controller/filters_test.rb147
-rw-r--r--actionpack/test/controller/flash_test.rb22
-rw-r--r--actionpack/test/controller/routing_test.rb13
-rw-r--r--actionpack/test/controller/view_paths_test.rb4
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb3
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb4
-rw-r--r--actionpack/test/fixtures/test/utf8.html.erb5
-rw-r--r--actionpack/test/template/body_parts_test.rb5
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb6
-rw-r--r--actionpack/test/template/output_buffer_test.rb75
-rw-r--r--actionpack/test/template/render_test.rb2
12 files changed, 184 insertions, 108 deletions
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index 39d0017dd8..7199da3441 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -123,6 +123,12 @@ class CookieTest < ActionController::TestCase
assert_cookie_header "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end
+ def test_cookies_persist_throughout_request
+ get :authenticate
+ cookies = @controller.send(:cookies)
+ assert_equal 'david', cookies['user_name']
+ end
+
private
def assert_cookie_header(expected)
header = @response.headers["Set-Cookie"]
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index 22aa50adb2..5e28ef6007 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -1,15 +1,36 @@
require 'abstract_unit'
+require 'active_support/core_ext/symbol'
-class << ActionController::Base
- %w(append_around_filter prepend_after_filter prepend_around_filter prepend_before_filter skip_after_filter skip_before_filter skip_filter).each do |pending|
- define_method(pending) do |*args|
- $stderr.puts "#{pending} unimplemented: #{args.inspect}"
- end unless method_defined?(pending)
+class ActionController::Base
+ class << self
+ %w(append_around_filter prepend_after_filter prepend_around_filter prepend_before_filter skip_after_filter skip_before_filter skip_filter).each do |pending|
+ define_method(pending) do |*args|
+ $stderr.puts "#{pending} unimplemented: #{args.inspect}"
+ end unless method_defined?(pending)
+ end
+
+ if defined?(ActionController::Http)
+ def before_filters
+ filters = _process_action_callbacks.select { |c| c.kind == :before }
+ filters.map! { |c| c.instance_variable_get(:@raw_filter) }
+ end
+ end
+ end
+
+ if defined?(ActionController::Http)
+ def assigns(key = nil)
+ assigns = {}
+ instance_variable_names.each do |ivar|
+ next if ActionController::Base.protected_instance_variables.include?(ivar)
+ assigns[ivar[1..-1]] = instance_variable_get(ivar)
+ end
+
+ key.nil? ? assigns : assigns[key.to_s]
+ end
end
end
-class FilterTest < Test::Unit::TestCase
- include ActionController::TestProcess
+class FilterTest < ActionController::TestCase
class TestController < ActionController::Base
before_filter :ensure_login
@@ -468,108 +489,108 @@ class FilterTest < Test::Unit::TestCase
def test_running_filters
test_process(PrependingController)
- assert_equal %w( wonderful_life ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( wonderful_life ensure_login ), assigns["ran_filter"]
end
def test_running_filters_with_proc
test_process(ProcController)
- assert @controller.template.assigns["ran_proc_filter"]
+ assert assigns["ran_proc_filter"]
end
def test_running_filters_with_implicit_proc
test_process(ImplicitProcController)
- assert @controller.template.assigns["ran_proc_filter"]
+ assert assigns["ran_proc_filter"]
end
def test_running_filters_with_class
test_process(AuditController)
- assert @controller.template.assigns["was_audited"]
+ assert assigns["was_audited"]
end
def test_running_anomolous_yet_valid_condition_filters
test_process(AnomolousYetValidConditionController)
- assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"]
- assert @controller.template.assigns["ran_class_filter"]
- assert @controller.template.assigns["ran_proc_filter1"]
- assert @controller.template.assigns["ran_proc_filter2"]
+ assert_equal %w( ensure_login ), assigns["ran_filter"]
+ assert assigns["ran_class_filter"]
+ assert assigns["ran_proc_filter1"]
+ assert assigns["ran_proc_filter2"]
test_process(AnomolousYetValidConditionController, "show_without_filter")
- assert_equal nil, @controller.template.assigns["ran_filter"]
- assert !@controller.template.assigns["ran_class_filter"]
- assert !@controller.template.assigns["ran_proc_filter1"]
- assert !@controller.template.assigns["ran_proc_filter2"]
+ assert_equal nil, assigns["ran_filter"]
+ assert !assigns["ran_class_filter"]
+ assert !assigns["ran_proc_filter1"]
+ assert !assigns["ran_proc_filter2"]
end
def test_running_conditional_options
test_process(ConditionalOptionsFilter)
- assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login ), assigns["ran_filter"]
end
def test_running_collection_condition_filters
test_process(ConditionalCollectionFilterController)
- assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login ), assigns["ran_filter"]
test_process(ConditionalCollectionFilterController, "show_without_filter")
- assert_equal nil, @controller.template.assigns["ran_filter"]
+ assert_equal nil, assigns["ran_filter"]
test_process(ConditionalCollectionFilterController, "another_action")
- assert_equal nil, @controller.template.assigns["ran_filter"]
+ assert_equal nil, assigns["ran_filter"]
end
def test_running_only_condition_filters
test_process(OnlyConditionSymController)
- assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login ), assigns["ran_filter"]
test_process(OnlyConditionSymController, "show_without_filter")
- assert_equal nil, @controller.template.assigns["ran_filter"]
+ assert_equal nil, assigns["ran_filter"]
test_process(OnlyConditionProcController)
- assert @controller.template.assigns["ran_proc_filter"]
+ assert assigns["ran_proc_filter"]
test_process(OnlyConditionProcController, "show_without_filter")
- assert !@controller.template.assigns["ran_proc_filter"]
+ assert !assigns["ran_proc_filter"]
test_process(OnlyConditionClassController)
- assert @controller.template.assigns["ran_class_filter"]
+ assert assigns["ran_class_filter"]
test_process(OnlyConditionClassController, "show_without_filter")
- assert !@controller.template.assigns["ran_class_filter"]
+ assert !assigns["ran_class_filter"]
end
def test_running_except_condition_filters
test_process(ExceptConditionSymController)
- assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login ), assigns["ran_filter"]
test_process(ExceptConditionSymController, "show_without_filter")
- assert_equal nil, @controller.template.assigns["ran_filter"]
+ assert_equal nil, assigns["ran_filter"]
test_process(ExceptConditionProcController)
- assert @controller.template.assigns["ran_proc_filter"]
+ assert assigns["ran_proc_filter"]
test_process(ExceptConditionProcController, "show_without_filter")
- assert !@controller.template.assigns["ran_proc_filter"]
+ assert !assigns["ran_proc_filter"]
test_process(ExceptConditionClassController)
- assert @controller.template.assigns["ran_class_filter"]
+ assert assigns["ran_class_filter"]
test_process(ExceptConditionClassController, "show_without_filter")
- assert !@controller.template.assigns["ran_class_filter"]
+ assert !assigns["ran_class_filter"]
end
def test_running_before_and_after_condition_filters
test_process(BeforeAndAfterConditionController)
- assert_equal %w( ensure_login clean_up_tmp), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login clean_up_tmp), assigns["ran_filter"]
test_process(BeforeAndAfterConditionController, "show_without_filter")
- assert_equal nil, @controller.template.assigns["ran_filter"]
+ assert_equal nil, assigns["ran_filter"]
end
def test_around_filter
test_process(AroundFilterController)
- assert @controller.template.assigns["before_ran"]
- assert @controller.template.assigns["after_ran"]
+ assert assigns["before_ran"]
+ assert assigns["after_ran"]
end
def test_before_after_class_filter
test_process(BeforeAfterClassFilterController)
- assert @controller.template.assigns["before_ran"]
- assert @controller.template.assigns["after_ran"]
+ assert assigns["before_ran"]
+ assert assigns["after_ran"]
end
def test_having_properties_in_around_filter
test_process(AroundFilterController)
- assert_equal "before and after", @controller.template.assigns["execution_log"]
+ assert_equal "before and after", assigns["execution_log"]
end
def test_prepending_and_appending_around_filter
@@ -582,7 +603,7 @@ class FilterTest < Test::Unit::TestCase
def test_rendering_breaks_filtering_chain
response = test_process(RenderingController)
assert_equal "something else", response.body
- assert !@controller.template.assigns["ran_action"]
+ assert !assigns["ran_action"]
end
def test_filters_with_mixed_specialization_run_in_order
@@ -601,33 +622,33 @@ class FilterTest < Test::Unit::TestCase
%w(foo bar baz).each do |action|
request = ActionController::TestRequest.new
request.query_parameters[:choose] = action
- response = DynamicDispatchController.action.call(request.env).last
+ response = DynamicDispatchController.action(action).call(request.env).last
assert_equal action, response.body
end
end
def test_running_prepended_before_and_after_filter
test_process(PrependingBeforeAndAfterController)
- assert_equal %w( before_all between_before_all_and_after_all after_all ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( before_all between_before_all_and_after_all after_all ), assigns["ran_filter"]
end
def test_skipping_and_limiting_controller
test_process(SkippingAndLimitedController, "index")
- assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login ), assigns["ran_filter"]
test_process(SkippingAndLimitedController, "public")
- assert_nil @controller.template.assigns["ran_filter"]
+ assert_nil assigns["ran_filter"]
end
def test_skipping_and_reordering_controller
test_process(SkippingAndReorderingController, "index")
- assert_equal %w( find_record ensure_login ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( find_record ensure_login ), assigns["ran_filter"]
end
def test_conditional_skipping_of_filters
test_process(ConditionalSkippingController, "login")
- assert_nil @controller.template.assigns["ran_filter"]
+ assert_nil assigns["ran_filter"]
test_process(ConditionalSkippingController, "change_password")
- assert_equal %w( ensure_login find_user ), @controller.template.assigns["ran_filter"]
+ assert_equal %w( ensure_login find_user ), assigns["ran_filter"]
test_process(ConditionalSkippingController, "login")
assert_nil @controller.template.controller.instance_variable_get("@ran_after_filter")
@@ -637,23 +658,23 @@ class FilterTest < Test::Unit::TestCase
def test_conditional_skipping_of_filters_when_parent_filter_is_also_conditional
test_process(ChildOfConditionalParentController)
- assert_equal %w( conditional_in_parent conditional_in_parent ), @controller.template.assigns['ran_filter']
+ assert_equal %w( conditional_in_parent conditional_in_parent ), assigns['ran_filter']
test_process(ChildOfConditionalParentController, 'another_action')
- assert_nil @controller.template.assigns['ran_filter']
+ assert_nil assigns['ran_filter']
end
def test_condition_skipping_of_filters_when_siblings_also_have_conditions
test_process(ChildOfConditionalParentController)
- assert_equal %w( conditional_in_parent conditional_in_parent ), @controller.template.assigns['ran_filter'], "1"
+ assert_equal %w( conditional_in_parent conditional_in_parent ), assigns['ran_filter'], "1"
test_process(AnotherChildOfConditionalParentController)
- assert_equal nil, @controller.template.assigns['ran_filter']
+ assert_equal nil, assigns['ran_filter']
test_process(ChildOfConditionalParentController)
- assert_equal %w( conditional_in_parent conditional_in_parent ), @controller.template.assigns['ran_filter']
+ assert_equal %w( conditional_in_parent conditional_in_parent ), assigns['ran_filter']
end
def test_changing_the_requirements
test_process(ChangingTheRequirementsController, "go_wild")
- assert_equal nil, @controller.template.assigns['ran_filter']
+ assert_equal nil, assigns['ran_filter']
end
def test_a_rescuing_around_filter
@@ -806,9 +827,8 @@ class ControllerWithTwoLessFilters < ControllerWithAllTypesOfFilters
skip_filter :after
end
-class YieldingAroundFiltersTest < Test::Unit::TestCase
+class YieldingAroundFiltersTest < ActionController::TestCase
include PostsController::AroundExceptions
- include ActionController::TestProcess
def test_base
controller = PostsController
@@ -846,8 +866,8 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase
def test_with_proc
test_process(ControllerWithProcFilter,'no_raise')
- assert @controller.template.assigns['before']
- assert @controller.template.assigns['after']
+ assert assigns['before']
+ assert assigns['after']
end
def test_nested_filters
@@ -868,12 +888,12 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase
def test_filter_order_with_all_filter_types
test_process(ControllerWithAllTypesOfFilters,'no_raise')
- assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', @controller.template.assigns['ran_filter'].join(' ')
+ assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', assigns['ran_filter'].join(' ')
end
def test_filter_order_with_skip_filter_method
test_process(ControllerWithTwoLessFilters,'no_raise')
- assert_equal 'before around (before yield) around (after yield)', @controller.template.assigns['ran_filter'].join(' ')
+ assert_equal 'before around (before yield) around (after yield)', assigns['ran_filter'].join(' ')
end
def test_first_filter_in_multiple_before_filter_chain_halts
@@ -903,9 +923,6 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase
protected
def test_process(controller, action = "show")
@controller = controller.is_a?(Class) ? controller.new : controller
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
process(action)
end
end
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index 84e27d7779..c448f36cb3 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -122,7 +122,7 @@ class FlashTest < ActionController::TestCase
assert_nil assigns["flash_copy"]["that"], "On second flash"
assert_equal "hello again", assigns["flash_copy"]["this"], "On second flash"
end
-
+
def test_flash_after_reset_session
get :use_flash_after_reset_session
assert_equal "hello", assigns["flashy_that"]
@@ -130,6 +130,11 @@ class FlashTest < ActionController::TestCase
assert_nil assigns["flashy_that_reset"]
end
+ def test_does_not_set_the_session_if_the_flash_is_empty
+ get :std_action
+ assert_nil session["flash"]
+ end
+
def test_sweep_after_halted_filter_chain
get :std_action
assert_nil assigns["flash_copy"]["foo"]
@@ -140,4 +145,19 @@ class FlashTest < ActionController::TestCase
get :std_action
assert_nil assigns["flash_copy"]["foo"]
end
+
+ def test_keep_and_discard_return_values
+ flash = ActionController::Flash::FlashHash.new
+ flash.update(:foo => :foo_indeed, :bar => :bar_indeed)
+
+ assert_equal(:foo_indeed, flash.discard(:foo)) # valid key passed
+ assert_nil flash.discard(:unknown) # non existant key passed
+ assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard()) # nothing passed
+ assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard(nil)) # nothing passed
+
+ assert_equal(:foo_indeed, flash.keep(:foo)) # valid key passed
+ assert_nil flash.keep(:unknown) # non existant key passed
+ assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep()) # nothing passed
+ assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep(nil)) # nothing passed
+ end
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 11bffdb42e..6b08a04b10 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -90,6 +90,11 @@ class StaticSegmentTest < Test::Unit::TestCase
assert_equal 'Hello World', s.interpolation_chunk
end
+ def test_value_should_not_be_double_unescaped
+ s = ROUTING::StaticSegment.new('%D0%9A%D0%B0%D1%80%D1%82%D0%B0') # Карта
+ assert_equal '%D0%9A%D0%B0%D1%80%D1%82%D0%B0', s.interpolation_chunk
+ end
+
def test_regexp_chunk_should_escape_specials
s = ROUTING::StaticSegment.new('Hello*World')
assert_equal 'Hello\*World', s.regexp_chunk
@@ -644,9 +649,8 @@ class RoutingTest < Test::Unit::TestCase
ActionController::Routing.use_controllers! nil
- silence_warnings do
- Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + '/controller_fixtures')
- end
+ Object.send(:remove_const, :RAILS_ROOT) if defined?(::RAILS_ROOT)
+ Object.const_set(:RAILS_ROOT, File.dirname(__FILE__) + '/controller_fixtures')
ActionController::Routing.controller_paths = [
RAILS_ROOT, RAILS_ROOT + '/app/controllers', RAILS_ROOT + '/vendor/plugins/bad_plugin/lib'
@@ -2482,7 +2486,8 @@ end
class RouteLoadingTest < Test::Unit::TestCase
def setup
routes.instance_variable_set '@routes_last_modified', nil
- silence_warnings { Object.const_set :RAILS_ROOT, '.' }
+ Object.remove_const(:RAILS_ROOT) if defined?(::RAILS_ROOT)
+ Object.const_set :RAILS_ROOT, '.'
routes.add_configuration_file(File.join(RAILS_ROOT, 'config', 'routes.rb'))
@stat = stub_everything
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 0ac10634b2..c732d1c910 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -22,7 +22,7 @@ class ViewLoadPathsTest < ActionController::TestCase
end
def setup
- TestController.view_paths = nil
+ # TestController.view_paths = nil
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -48,7 +48,7 @@ class ViewLoadPathsTest < ActionController::TestCase
def assert_paths(*paths)
controller = paths.first.is_a?(Class) ? paths.shift : @controller
- assert_equal expand(paths), controller.view_paths.map(&:to_s)
+ assert_equal expand(paths), controller.view_paths.map { |p| p.to_s }
end
def test_template_load_path_was_set_correctly
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 3090a70244..2db76818ac 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -5,6 +5,9 @@ class CookieStoreTest < ActionController::IntegrationTest
SessionKey = '_myapp_session'
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
+ # Make sure Session middleware doesnt get included in the middleware stack
+ ActionController::Base.session_store = nil
+
DispatcherApp = ActionController::Dispatcher.new
CookieStoreApp = ActionDispatch::Session::CookieStore.new(DispatcherApp,
:key => SessionKey, :secret => SessionSecret)
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index 0c0c087340..ce1973853e 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -61,7 +61,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
get "/not_found"
assert_response 404
- assert_match /ActionController::UnknownAction/, body
+ assert_match /#{ActionController::UnknownAction.name}/, body
get "/method_not_allowed"
assert_response 405
@@ -99,7 +99,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
get "/not_found"
assert_response 404
- assert_match /ActionController::UnknownAction/, body
+ assert_match /#{ActionController::UnknownAction.name}/, body
get "/method_not_allowed"
assert_response 405
diff --git a/actionpack/test/fixtures/test/utf8.html.erb b/actionpack/test/fixtures/test/utf8.html.erb
index 0b4d19aa0e..58cd03b439 100644
--- a/actionpack/test/fixtures/test/utf8.html.erb
+++ b/actionpack/test/fixtures/test/utf8.html.erb
@@ -1,2 +1,5 @@
+<%# encoding: utf-8 -%>
Русский текст
-日本語のテキスト \ No newline at end of file
+<%= "日".encoding %>
+<%= @output_buffer.encoding %>
+<%= __ENCODING__ %>
diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb
index e17092a452..4e7aa63f96 100644
--- a/actionpack/test/template/body_parts_test.rb
+++ b/actionpack/test/template/body_parts_test.rb
@@ -4,6 +4,9 @@ class BodyPartsTest < ActionController::TestCase
RENDERINGS = [Object.new, Object.new, Object.new]
class TestController < ActionController::Base
+ def performed?
+ defined?(ActionController::Http) ? true : super
+ end
def index
RENDERINGS.each do |rendering|
@template.punctuate_body! rendering
@@ -16,7 +19,7 @@ class BodyPartsTest < ActionController::TestCase
def test_body_parts
get :index
- pending do
+ pending(:old_base) do
# TestProcess buffers body_parts into body
# TODO: Rewrite test w/o going through process
assert_equal RENDERINGS, @response.body_parts
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index ea0be4a27a..5ca4d4d6ea 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -253,14 +253,14 @@ class FormTagHelperTest < ActionView::TestCase
def test_submit_tag
assert_dom_equal(
- %(<input name='commit' type='submit' value='Save' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
+ %(<input name='commit' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = document.createElement('input');hiddenCommit.type = 'hidden';hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" type="submit" value="Save" />),
submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
)
end
def test_submit_tag_with_no_onclick_options
assert_dom_equal(
- %(<input name='commit' type='submit' value='Save' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
+ %(<input name='commit' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = document.createElement('input');hiddenCommit.type = 'hidden';hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" type="submit" value="Save" />),
submit_tag("Save", :disable_with => "Saving...")
)
end
@@ -274,7 +274,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_submit_tag_with_confirmation_and_with_disable_with
assert_dom_equal(
- %(<input name="commit" type="submit" value="Save" onclick="if (!confirm('Are you sure?')) return false; if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
+ %(<input name="commit" onclick="if (!confirm('Are you sure?')) return false; if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = document.createElement('input');hiddenCommit.type = 'hidden';hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" type="submit" value="Save" />),
submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?")
)
end
diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb
index 171cfb63e1..36bbaf9099 100644
--- a/actionpack/test/template/output_buffer_test.rb
+++ b/actionpack/test/template/output_buffer_test.rb
@@ -9,33 +9,52 @@ class OutputBufferTest < ActionController::TestCase
tests TestController
- def test_flush_output_buffer
- pending
- # TODO: This tests needs to be rewritten due
- # The @response is not the same response object assigned
- # to the @controller.template
-
- # Start with the default body parts
- # ---
- # get :index
- # assert_equal ['foo'], @response.body_parts
- # assert_nil @controller.template.output_buffer
- #
- # # Nil output buffer is skipped
- # @controller.template.flush_output_buffer
- # assert_nil @controller.template.output_buffer
- # assert_equal ['foo'], @response.body_parts
- #
- # # Empty output buffer is skipped
- # @controller.template.output_buffer = ''
- # @controller.template.flush_output_buffer
- # assert_equal '', @controller.template.output_buffer
- # assert_equal ['foo'], @response.body_parts
- #
- # # Flushing appends the output buffer to the body parts
- # @controller.template.output_buffer = 'bar'
- # @controller.template.flush_output_buffer
- # assert_equal '', @controller.template.output_buffer
- # assert_equal ['foo', 'bar'], @response.body_parts
+ def setup
+ get :index
+ assert_equal ['foo'], body_parts
end
+
+ test 'output buffer is nil after rendering' do
+ assert_nil output_buffer
+ end
+
+ test 'flushing ignores nil output buffer' do
+ @controller.template.flush_output_buffer
+ assert_nil output_buffer
+ assert_equal ['foo'], body_parts
+ end
+
+ test 'flushing ignores empty output buffer' do
+ @controller.template.output_buffer = ''
+ @controller.template.flush_output_buffer
+ assert_equal '', output_buffer
+ assert_equal ['foo'], body_parts
+ end
+
+ test 'flushing appends the output buffer to the body parts' do
+ @controller.template.output_buffer = 'bar'
+ @controller.template.flush_output_buffer
+ assert_equal '', output_buffer
+ assert_equal ['foo', 'bar'], body_parts
+ end
+
+ if '1.9'.respond_to?(:force_encoding)
+ test 'flushing preserves output buffer encoding' do
+ original_buffer = ' '.force_encoding(Encoding::EUC_JP)
+ @controller.template.output_buffer = original_buffer
+ @controller.template.flush_output_buffer
+ assert_equal ['foo', original_buffer], body_parts
+ assert_not_equal original_buffer, output_buffer
+ assert_equal Encoding::EUC_JP, output_buffer.encoding
+ end
+ end
+
+ protected
+ def output_buffer
+ @controller.template.output_buffer
+ end
+
+ def body_parts
+ @controller.template.response.body_parts
+ end
end
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 71291f009c..a56d7aee75 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -249,7 +249,7 @@ module RenderTestCases
if '1.9'.respond_to?(:force_encoding)
def test_render_utf8_template
result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
- assert_equal "Русский текст\n日本語のテキスト", result
+ assert_equal "Русский текст\nUTF-8\nUTF-8\nUTF-8\n", result
assert_equal Encoding::UTF_8, result.encoding
end
end