diff options
author | rick <technoweenie@gmail.com> | 2008-07-16 14:20:15 -0700 |
---|---|---|
committer | rick <technoweenie@gmail.com> | 2008-07-16 14:20:15 -0700 |
commit | 0a6d75dedd79407376aae1f01302164dfd3e44b6 (patch) | |
tree | dfef7e73b3b19a65895651c82cb6e0b727394eab /actionpack/test | |
parent | a14cedc7797aef4ccd9da46ed73e36d730392814 (diff) | |
parent | fc89a951933638b051bb1f9e1339ee6ae7c94cda (diff) | |
download | rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.tar.gz rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.tar.bz2 rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.zip |
merge with local tweaks
Diffstat (limited to 'actionpack/test')
30 files changed, 1011 insertions, 94 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 70f6a28a9c..0d2e0f273a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -22,7 +22,9 @@ ActiveSupport::Deprecation.debug = true ActionController::Base.logger = nil ActionController::Routing::Routes.reload rescue nil -FIXTURE_LOAD_PATH = ActionView::ViewLoadPaths::LoadPath.new(File.join(File.dirname(__FILE__), 'fixtures')) +ActionView::Base.cache_template_loading = true +FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') +ActionController::Base.view_paths = FIXTURE_LOAD_PATH # Wrap tests that use Mocha and skip if unavailable. def uses_mocha(test_name) diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb index af2725a99b..a82a1a3023 100644 --- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb @@ -41,8 +41,6 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base end end -RenderPartialWithRecordIdentificationController.view_paths = [FIXTURE_LOAD_PATH] - class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase fixtures :developers, :projects, :developers_projects, :topics, :replies, :companies, :mascots @@ -56,26 +54,31 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase def test_rendering_partial_with_has_many_and_belongs_to_association get :render_with_has_many_and_belongs_to_association assert_template 'projects/_project' + assert_equal 'Active RecordActive Controller', @response.body end def test_rendering_partial_with_has_many_association get :render_with_has_many_association assert_template 'replies/_reply' + assert_equal 'Birdman is better!', @response.body end def test_rendering_partial_with_named_scope get :render_with_named_scope assert_template 'replies/_reply' + assert_equal 'Birdman is better!Nuh uh!', @response.body end def test_render_with_record get :render_with_record assert_template 'developers/_developer' + assert_equal 'David', @response.body end def test_render_with_record_collection get :render_with_record_collection assert_template 'developers/_developer' + assert_equal 'DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis', @response.body end def test_rendering_partial_with_has_one_association @@ -118,8 +121,6 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base end end -RenderPartialWithRecordIdentificationController.view_paths = [FIXTURE_LOAD_PATH] - class Game < Struct.new(:name, :id) def to_param id.to_s @@ -137,8 +138,6 @@ module Fun end end - NestedController.view_paths = [FIXTURE_LOAD_PATH] - module Serious class NestedDeeperController < ActionController::Base def render_with_record_in_deeper_nested_controller @@ -149,8 +148,6 @@ module Fun render :partial => [ Game.new("Chess"), Game.new("Sudoku"), Game.new("Solitaire") ] end end - - NestedDeeperController.view_paths = [FIXTURE_LOAD_PATH] end end @@ -165,11 +162,13 @@ class RenderPartialWithRecordIdentificationAndNestedControllersTest < ActiveReco def test_render_with_record_in_nested_controller get :render_with_record_in_nested_controller assert_template 'fun/games/_game' + assert_equal 'Pong', @response.body end def test_render_with_record_collection_in_nested_controller get :render_with_record_collection_in_nested_controller assert_template 'fun/games/_game' + assert_equal 'PongTank', @response.body end end @@ -184,10 +183,12 @@ class RenderPartialWithRecordIdentificationAndNestedDeeperControllersTest < Acti def test_render_with_record_in_deeper_nested_controller get :render_with_record_in_deeper_nested_controller assert_template 'fun/serious/games/_game' + assert_equal 'Chess', @response.body end def test_render_with_record_collection_in_deeper_nested_controller get :render_with_record_collection_in_deeper_nested_controller assert_template 'fun/serious/games/_game' + assert_equal 'ChessSudokuSolitaire', @response.body end end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index f5cda99977..56ba36cee5 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -164,14 +164,6 @@ module Admin end end -# --------------------------------------------------------------------------- - - -# tell the controller where to find its templates but start from parent -# directory of test_request_response to simulate the behaviour of a -# production environment -ActionPackAssertionsController.view_paths = [FIXTURE_LOAD_PATH] - # a test case to exercise the new capabilities TestRequest & TestResponse class ActionPackAssertionsControllerTest < Test::Unit::TestCase # let's get this party started @@ -336,11 +328,11 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase # check if we were rendered by a file-based template? def test_rendered_action process :nothing - assert !@response.rendered_with_file? + assert_nil @response.rendered_template process :hello_world - assert @response.rendered_with_file? - assert 'hello_world', @response.rendered_file + assert @response.rendered_template + assert 'hello_world', @response.rendered_template.to_s end # check the redirection location diff --git a/actionpack/test/controller/addresses_render_test.rb b/actionpack/test/controller/addresses_render_test.rb index df87182082..b26cae24fb 100644 --- a/actionpack/test/controller/addresses_render_test.rb +++ b/actionpack/test/controller/addresses_render_test.rb @@ -19,8 +19,6 @@ class AddressesTestController < ActionController::Base def self.controller_path; "addresses"; end end -AddressesTestController.view_paths = [FIXTURE_LOAD_PATH] - class AddressesTest < Test::Unit::TestCase def setup @controller = AddressesTestController.new diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 7aa4e0cd93..c30f7be700 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -6,7 +6,6 @@ CACHE_DIR = 'test_cache' FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR) ActionController::Base.page_cache_directory = FILE_STORE_PATH ActionController::Base.cache_store = :file_store, FILE_STORE_PATH -ActionController::Base.view_paths = [FIXTURE_LOAD_PATH] class PageCachingTestController < ActionController::Base caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? } @@ -285,9 +284,12 @@ class ActionCacheTest < Test::Unit::TestCase end def test_action_cache_conditional_options + old_use_accept_header = ActionController::Base.use_accept_header + ActionController::Base.use_accept_header = true @request.env['HTTP_ACCEPT'] = 'application/json' get :index assert !fragment_exist?('hostname.com/action_caching_test') + ActionController::Base.use_accept_header = old_use_accept_header end def test_action_cache_with_store_options @@ -633,8 +635,6 @@ class FunctionalCachingController < ActionController::Base end end -FunctionalCachingController.view_paths = [FIXTURE_LOAD_PATH] - class FunctionalFragmentCachingTest < Test::Unit::TestCase def setup ActionController::Base.perform_caching = true @@ -664,6 +664,14 @@ CACHED assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial') end + def test_render_inline_before_fragment_caching + get :inline_fragment_cached + assert_response :success + assert_match /Some inline content/, @response.body + assert_match /Some cached content/, @response.body + assert_match "Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached') + end + def test_fragment_caching_in_rjs_partials xhr :get, :js_fragment_cached_with_partial assert_response :success diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index 87f9ce8ab3..5ded6a5d26 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -23,8 +23,6 @@ class CaptureController < ActionController::Base def rescue_action(e) raise end end -CaptureController.view_paths = [FIXTURE_LOAD_PATH] - class CaptureTest < Test::Unit::TestCase def setup @controller = CaptureController.new diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index 8f55974172..d457d13aef 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -45,8 +45,6 @@ class ContentTypeController < ActionController::Base def rescue_action(e) raise end end -ContentTypeController.view_paths = [FIXTURE_LOAD_PATH] - class ContentTypeTest < Test::Unit::TestCase def setup @controller = ContentTypeController.new @@ -124,7 +122,7 @@ class AcceptBasedContentTypeTest < ActionController::TestCase ActionController::Base.use_accept_header = true end - def tear_down + def teardown ActionController::Base.use_accept_header = false end diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb index f485500b7f..86555a77df 100644 --- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb +++ b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb @@ -13,8 +13,6 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase def rescue_action(e) raise e end end - Target.view_paths = [FIXTURE_LOAD_PATH] - def setup @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 3dc311b78a..92b6aa4f2f 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -34,8 +34,8 @@ end class MabView < ActionView::TemplateHandler def initialize(view) end - - def render(template) + + def render(template, local_assigns) template.source end end @@ -63,6 +63,7 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase end def test_third_party_template_library_auto_discovers_layout + ThirdPartyTemplateLibraryController.view_paths.reload! @controller = ThirdPartyTemplateLibraryController.new get :hello assert_equal 'layouts/third_party_template_library', @controller.active_layout diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 17f5e27232..1701431858 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -162,8 +162,6 @@ class RespondToController < ActionController::Base end end -RespondToController.view_paths = [FIXTURE_LOAD_PATH] - class MimeControllerTest < Test::Unit::TestCase def setup ActionController::Base.use_accept_header = true diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index b2691d981b..d2a3a2b0b0 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -465,9 +465,6 @@ class NewRenderTestController < ActionController::Base end end -NewRenderTestController.view_paths = [FIXTURE_LOAD_PATH] -Fun::GamesController.view_paths = [FIXTURE_LOAD_PATH] - class NewRenderTest < Test::Unit::TestCase def setup @controller = NewRenderTestController.new @@ -489,6 +486,11 @@ class NewRenderTest < Test::Unit::TestCase assert_equal "<html>Hello world!</html>", @response.body end + def test_renders_default_template_for_missing_action + get :'hyphen-ated' + assert_template 'test/hyphen-ated' + end + def test_do_with_render get :render_hello_world assert_template "test/hello_world" diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 8b72426d10..28da5c6163 100755 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -227,6 +227,11 @@ class RedirectTest < Test::Unit::TestCase assert_redirected_to Workshop.new(5, true) end + def test_redirect_with_partial_params + get :module_redirect + assert_redirected_to :action => 'hello_world' + end + def test_redirect_to_nil assert_raises(ActionController::ActionControllerError) do get :redirect_to_nil diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 10264dadaa..a857810b78 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -217,9 +217,6 @@ class TestController < ActionController::Base end end -TestController.view_paths = [FIXTURE_LOAD_PATH] -Fun::GamesController.view_paths = [FIXTURE_LOAD_PATH] - class RenderTest < Test::Unit::TestCase def setup @request = ActionController::TestRequest.new diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 0d089d0f23..0f7924649a 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -28,18 +28,16 @@ module Backoffice end class ResourcesTest < Test::Unit::TestCase - - # The assertions in these tests are incompatible with the hash method # optimisation. This could indicate user level problems def setup ActionController::Base.optimise_named_routes = false end - - def tear_down + + def teardown ActionController::Base.optimise_named_routes = true end - + def test_should_arrange_actions resource = ActionController::Resources::Resource.new(:messages, :collection => { :rss => :get, :reorder => :post, :csv => :post }, @@ -159,14 +157,14 @@ class ResourcesTest < Test::Unit::TestCase def test_with_collection_actions_and_name_prefix actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete } - + with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.each do |action, method| assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method) end end - + assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.keys.each do |action| assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", :action => action @@ -177,14 +175,14 @@ class ResourcesTest < Test::Unit::TestCase def test_with_collection_action_and_name_prefix_and_formatted actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete } - + with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.each do |action, method| assert_recognizes(options.merge(:action => action, :format => 'xml'), :path => "/threads/1/messages/#{action}.xml", :method => method) end end - + assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.keys.each do |action| assert_named_route "/threads/1/messages/#{action}.xml", "formatted_#{action}_thread_messages_path", :action => action, :format => 'xml' @@ -279,7 +277,7 @@ class ResourcesTest < Test::Unit::TestCase end end end - + def test_with_new_action_with_name_prefix with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do preview_options = {:action => 'preview', :thread_id => '1'} @@ -293,7 +291,7 @@ class ResourcesTest < Test::Unit::TestCase end end end - + def test_with_formatted_new_action_with_name_prefix with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do preview_options = {:action => 'preview', :thread_id => '1', :format => 'xml'} @@ -307,7 +305,7 @@ class ResourcesTest < Test::Unit::TestCase end end end - + def test_override_new_method with_restful_routing :messages do assert_restful_routes_for :messages do |options| @@ -524,9 +522,9 @@ class ResourcesTest < Test::Unit::TestCase map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' end - + action_separator = ActionController::Base.resource_action_separator - + assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {} assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} @@ -623,7 +621,7 @@ class ResourcesTest < Test::Unit::TestCase assert_simply_restful_for :products, :controller => "backoffice/products" end end - + def test_nested_resources_using_namespace with_routing do |set| set.draw do |map| @@ -795,7 +793,7 @@ class ResourcesTest < Test::Unit::TestCase yield options[:options] if block_given? end - + def assert_singleton_routes_for(singleton_name, options = {}) options[:options] ||= {} options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize @@ -855,7 +853,7 @@ class ResourcesTest < Test::Unit::TestCase actual = @controller.send(route, options) rescue $!.class.name assert_equal expected, actual, "Error on route: #{route}(#{options.inspect})" end - + def assert_resource_methods(expected, resource, action_method, method) assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}" expected.each do |action| diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index ddec51d173..c003abf094 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -19,8 +19,6 @@ class SendFileController < ActionController::Base def rescue_action(e) raise end end -SendFileController.view_paths = [FIXTURE_LOAD_PATH] - class SendFileTest < Test::Unit::TestCase include TestFileUtils diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index 9401c87d10..85fa58a45b 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -1,8 +1,6 @@ require 'abstract_unit' class ViewLoadPathsTest < Test::Unit::TestCase - ActionController::Base.view_paths = [FIXTURE_LOAD_PATH] - class TestController < ActionController::Base def self.controller_path() "test" end def rescue_action(e) raise end @@ -146,18 +144,4 @@ class ViewLoadPathsTest < Test::Unit::TestCase assert_nothing_raised { C.view_paths << 'c/path' } assert_equal ['c/path'], C.view_paths end - - def test_find_template_file_for_path - assert_equal "test/hello_world.erb", @controller.view_paths.find_template_file_for_path("test/hello_world.erb").to_s - assert_equal "test/hello.builder", @controller.view_paths.find_template_file_for_path("test/hello.builder").to_s - assert_equal nil, @controller.view_paths.find_template_file_for_path("test/missing.erb") - end - - def test_view_paths_find_template_file_for_path - assert_equal "test/formatted_html_erb.html.erb", @controller.view_paths.find_template_file_for_path("test/formatted_html_erb.html").to_s - assert_equal "test/formatted_xml_erb.xml.erb", @controller.view_paths.find_template_file_for_path("test/formatted_xml_erb.xml").to_s - assert_equal "test/hello_world.erb", @controller.view_paths.find_template_file_for_path("test/hello_world.html").to_s - assert_equal "test/hello_world.erb", @controller.view_paths.find_template_file_for_path("test/hello_world.xml").to_s - assert_equal nil, @controller.view_paths.find_template_file_for_path("test/missing.html") - end end diff --git a/actionpack/test/fixtures/developers/_developer.erb b/actionpack/test/fixtures/developers/_developer.erb new file mode 100644 index 0000000000..904a3137e7 --- /dev/null +++ b/actionpack/test/fixtures/developers/_developer.erb @@ -0,0 +1 @@ +<%= developer.name %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/fun/games/_game.erb b/actionpack/test/fixtures/fun/games/_game.erb new file mode 100644 index 0000000000..d51b7b3ebc --- /dev/null +++ b/actionpack/test/fixtures/fun/games/_game.erb @@ -0,0 +1 @@ +<%= game.name %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/fun/serious/games/_game.erb b/actionpack/test/fixtures/fun/serious/games/_game.erb new file mode 100644 index 0000000000..d51b7b3ebc --- /dev/null +++ b/actionpack/test/fixtures/fun/serious/games/_game.erb @@ -0,0 +1 @@ +<%= game.name %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb b/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb new file mode 100644 index 0000000000..87309b8ccb --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb @@ -0,0 +1,2 @@ +<%= render :inline => 'Some inline content' %> +<% cache do %>Some cached content<% end %> diff --git a/actionpack/test/fixtures/projects/_project.erb b/actionpack/test/fixtures/projects/_project.erb new file mode 100644 index 0000000000..480c4c2af3 --- /dev/null +++ b/actionpack/test/fixtures/projects/_project.erb @@ -0,0 +1 @@ +<%= project.name %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/javascripts/subdir/subdir.js b/actionpack/test/fixtures/public/javascripts/subdir/subdir.js new file mode 100644 index 0000000000..9d23a67aa1 --- /dev/null +++ b/actionpack/test/fixtures/public/javascripts/subdir/subdir.js @@ -0,0 +1 @@ +// subdir js diff --git a/actionpack/test/fixtures/public/stylesheets/subdir/subdir.css b/actionpack/test/fixtures/public/stylesheets/subdir/subdir.css new file mode 100644 index 0000000000..241152a905 --- /dev/null +++ b/actionpack/test/fixtures/public/stylesheets/subdir/subdir.css @@ -0,0 +1 @@ +/* subdir.css */ diff --git a/actionpack/test/fixtures/replies/_reply.erb b/actionpack/test/fixtures/replies/_reply.erb new file mode 100644 index 0000000000..68baf548d8 --- /dev/null +++ b/actionpack/test/fixtures/replies/_reply.erb @@ -0,0 +1 @@ +<%= reply.content %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/hyphen-ated.erb b/actionpack/test/fixtures/test/hyphen-ated.erb new file mode 100644 index 0000000000..cd0875583a --- /dev/null +++ b/actionpack/test/fixtures/test/hyphen-ated.erb @@ -0,0 +1 @@ +Hello world! diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 4a8117a88a..020e112fd0 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -83,6 +83,7 @@ class AssetTagHelperTest < ActionView::TestCase %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>), %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), %(javascript_include_tag(:all)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>), + %(javascript_include_tag(:all, :recursive => true)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>), %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>) } @@ -108,6 +109,7 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="stylesheet" type="text/css" />), %(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />), %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />), + %(stylesheet_link_tag(:all, :recursive => true)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />), %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="all" rel="stylesheet" type="text/css" />), %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />), %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />) @@ -343,6 +345,27 @@ class AssetTagHelperTest < ActionView::TestCase FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) end + def test_caching_javascript_include_tag_with_all_and_recursive_puts_defaults_at_the_start_of_the_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.asset_host = 'http://a0.example.com' + ActionController::Base.perform_caching = true + + assert_dom_equal( + %(<script src="http://a0.example.com/javascripts/combined.js" type="text/javascript"></script>), + javascript_include_tag(:all, :cache => "combined", :recursive => true) + ) + + assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) + + assert_equal( + %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js\n\n// subdir js\n\n\n// version.1.0 js), + IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) + ) + + ensure + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) + end + def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_the_file ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' @@ -373,6 +396,11 @@ class AssetTagHelperTest < ActionView::TestCase javascript_include_tag(:all, :cache => true) ) + assert_dom_equal( + %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>), + javascript_include_tag(:all, :cache => true, :recursive => true) + ) + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) assert_dom_equal( @@ -380,6 +408,11 @@ class AssetTagHelperTest < ActionView::TestCase javascript_include_tag(:all, :cache => "money") ) + assert_dom_equal( + %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>), + javascript_include_tag(:all, :cache => "money", :recursive => true) + ) + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) end @@ -432,6 +465,11 @@ class AssetTagHelperTest < ActionView::TestCase stylesheet_link_tag(:all, :cache => true) ) + assert_dom_equal( + %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />), + stylesheet_link_tag(:all, :cache => true, :recursive => true) + ) + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) assert_dom_equal( @@ -439,6 +477,11 @@ class AssetTagHelperTest < ActionView::TestCase stylesheet_link_tag(:all, :cache => "money") ) + assert_dom_equal( + %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />), + stylesheet_link_tag(:all, :cache => "money", :recursive => true) + ) + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) end end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 2496931f4b..9dd43d7b4f 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -231,6 +231,35 @@ uses_mocha "FormOptionsHelperTest" do ) end + def test_select_under_fields_for_with_index + @post = Post.new + @post.category = "<mus>" + + fields_for :post, @post, :index => 108 do |f| + concat f.select(:category, %w( abe <mus> hest)) + end + + assert_dom_equal( + "<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>", + output_buffer + ) + end + + def test_select_under_fields_for_with_auto_index + @post = Post.new + @post.category = "<mus>" + def @post.to_param; 108; end + + fields_for "post[]", @post do |f| + concat f.select(:category, %w( abe <mus> hest)) + end + + assert_dom_equal( + "<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>", + output_buffer + ) + end + def test_select_with_blank @post = Post.new @post.category = "<mus>" @@ -351,6 +380,47 @@ uses_mocha "FormOptionsHelperTest" do ) end + def test_collection_select_under_fields_for_with_index + @posts = [ + Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] + + @post = Post.new + @post.author_name = "Babe" + + fields_for :post, @post, :index => 815 do |f| + concat f.collection_select(:author_name, @posts, :author_name, :author_name) + end + + assert_dom_equal( + "<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>", + output_buffer + ) + end + + def test_collection_select_under_fields_for_with_auto_index + @posts = [ + Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] + + @post = Post.new + @post.author_name = "Babe" + def @post.to_param; 815; end + + fields_for "post[]", @post do |f| + concat f.collection_select(:author_name, @posts, :author_name, :author_name) + end + + assert_dom_equal( + "<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>", + output_buffer + ) + end + def test_collection_select_with_blank_and_style @posts = [ Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"), @@ -1165,6 +1235,782 @@ uses_mocha "FormOptionsHelperTest" do assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) end + def test_country_select_under_fields_for + @post = Post.new + @post.origin = "Australia" + expected_select = <<-COUNTRIES +<select id="post_origin" name="post[origin]"><option value="Afghanistan">Afghanistan</option> +<option value="Aland Islands">Aland Islands</option> +<option value="Albania">Albania</option> +<option value="Algeria">Algeria</option> +<option value="American Samoa">American Samoa</option> +<option value="Andorra">Andorra</option> +<option value="Angola">Angola</option> +<option value="Anguilla">Anguilla</option> +<option value="Antarctica">Antarctica</option> +<option value="Antigua And Barbuda">Antigua And Barbuda</option> +<option value="Argentina">Argentina</option> +<option value="Armenia">Armenia</option> +<option value="Aruba">Aruba</option> +<option selected="selected" value="Australia">Australia</option> +<option value="Austria">Austria</option> +<option value="Azerbaijan">Azerbaijan</option> +<option value="Bahamas">Bahamas</option> +<option value="Bahrain">Bahrain</option> +<option value="Bangladesh">Bangladesh</option> +<option value="Barbados">Barbados</option> +<option value="Belarus">Belarus</option> +<option value="Belgium">Belgium</option> +<option value="Belize">Belize</option> +<option value="Benin">Benin</option> +<option value="Bermuda">Bermuda</option> +<option value="Bhutan">Bhutan</option> +<option value="Bolivia">Bolivia</option> +<option value="Bosnia and Herzegowina">Bosnia and Herzegowina</option> +<option value="Botswana">Botswana</option> +<option value="Bouvet Island">Bouvet Island</option> +<option value="Brazil">Brazil</option> +<option value="British Indian Ocean Territory">British Indian Ocean Territory</option> +<option value="Brunei Darussalam">Brunei Darussalam</option> +<option value="Bulgaria">Bulgaria</option> +<option value="Burkina Faso">Burkina Faso</option> +<option value="Burundi">Burundi</option> +<option value="Cambodia">Cambodia</option> +<option value="Cameroon">Cameroon</option> +<option value="Canada">Canada</option> +<option value="Cape Verde">Cape Verde</option> +<option value="Cayman Islands">Cayman Islands</option> +<option value="Central African Republic">Central African Republic</option> +<option value="Chad">Chad</option> +<option value="Chile">Chile</option> +<option value="China">China</option> +<option value="Christmas Island">Christmas Island</option> +<option value="Cocos (Keeling) Islands">Cocos (Keeling) Islands</option> +<option value="Colombia">Colombia</option> +<option value="Comoros">Comoros</option> +<option value="Congo">Congo</option> +<option value="Congo, the Democratic Republic of the">Congo, the Democratic Republic of the</option> +<option value="Cook Islands">Cook Islands</option> +<option value="Costa Rica">Costa Rica</option> +<option value="Cote d'Ivoire">Cote d'Ivoire</option> +<option value="Croatia">Croatia</option> +<option value="Cuba">Cuba</option> +<option value="Cyprus">Cyprus</option> +<option value="Czech Republic">Czech Republic</option> +<option value="Denmark">Denmark</option> +<option value="Djibouti">Djibouti</option> +<option value="Dominica">Dominica</option> +<option value="Dominican Republic">Dominican Republic</option> +<option value="Ecuador">Ecuador</option> +<option value="Egypt">Egypt</option> +<option value="El Salvador">El Salvador</option> +<option value="Equatorial Guinea">Equatorial Guinea</option> +<option value="Eritrea">Eritrea</option> +<option value="Estonia">Estonia</option> +<option value="Ethiopia">Ethiopia</option> +<option value="Falkland Islands (Malvinas)">Falkland Islands (Malvinas)</option> +<option value="Faroe Islands">Faroe Islands</option> +<option value="Fiji">Fiji</option> +<option value="Finland">Finland</option> +<option value="France">France</option> +<option value="French Guiana">French Guiana</option> +<option value="French Polynesia">French Polynesia</option> +<option value="French Southern Territories">French Southern Territories</option> +<option value="Gabon">Gabon</option> +<option value="Gambia">Gambia</option> +<option value="Georgia">Georgia</option> +<option value="Germany">Germany</option> +<option value="Ghana">Ghana</option> +<option value="Gibraltar">Gibraltar</option> +<option value="Greece">Greece</option> +<option value="Greenland">Greenland</option> +<option value="Grenada">Grenada</option> +<option value="Guadeloupe">Guadeloupe</option> +<option value="Guam">Guam</option> +<option value="Guatemala">Guatemala</option> +<option value="Guernsey">Guernsey</option> +<option value="Guinea">Guinea</option> +<option value="Guinea-Bissau">Guinea-Bissau</option> +<option value="Guyana">Guyana</option> +<option value="Haiti">Haiti</option> +<option value="Heard and McDonald Islands">Heard and McDonald Islands</option> +<option value="Holy See (Vatican City State)">Holy See (Vatican City State)</option> +<option value="Honduras">Honduras</option> +<option value="Hong Kong">Hong Kong</option> +<option value="Hungary">Hungary</option> +<option value="Iceland">Iceland</option> +<option value="India">India</option> +<option value="Indonesia">Indonesia</option> +<option value="Iran, Islamic Republic of">Iran, Islamic Republic of</option> +<option value="Iraq">Iraq</option> +<option value="Ireland">Ireland</option> +<option value="Isle of Man">Isle of Man</option> +<option value="Israel">Israel</option> +<option value="Italy">Italy</option> +<option value="Jamaica">Jamaica</option> +<option value="Japan">Japan</option> +<option value="Jersey">Jersey</option> +<option value="Jordan">Jordan</option> +<option value="Kazakhstan">Kazakhstan</option> +<option value="Kenya">Kenya</option> +<option value="Kiribati">Kiribati</option> +<option value="Korea, Democratic People's Republic of">Korea, Democratic People's Republic of</option> +<option value="Korea, Republic of">Korea, Republic of</option> +<option value="Kuwait">Kuwait</option> +<option value="Kyrgyzstan">Kyrgyzstan</option> +<option value="Lao People's Democratic Republic">Lao People's Democratic Republic</option> +<option value="Latvia">Latvia</option> +<option value="Lebanon">Lebanon</option> +<option value="Lesotho">Lesotho</option> +<option value="Liberia">Liberia</option> +<option value="Libyan Arab Jamahiriya">Libyan Arab Jamahiriya</option> +<option value="Liechtenstein">Liechtenstein</option> +<option value="Lithuania">Lithuania</option> +<option value="Luxembourg">Luxembourg</option> +<option value="Macao">Macao</option> +<option value="Macedonia, The Former Yugoslav Republic Of">Macedonia, The Former Yugoslav Republic Of</option> +<option value="Madagascar">Madagascar</option> +<option value="Malawi">Malawi</option> +<option value="Malaysia">Malaysia</option> +<option value="Maldives">Maldives</option> +<option value="Mali">Mali</option> +<option value="Malta">Malta</option> +<option value="Marshall Islands">Marshall Islands</option> +<option value="Martinique">Martinique</option> +<option value="Mauritania">Mauritania</option> +<option value="Mauritius">Mauritius</option> +<option value="Mayotte">Mayotte</option> +<option value="Mexico">Mexico</option> +<option value="Micronesia, Federated States of">Micronesia, Federated States of</option> +<option value="Moldova, Republic of">Moldova, Republic of</option> +<option value="Monaco">Monaco</option> +<option value="Mongolia">Mongolia</option> +<option value="Montenegro">Montenegro</option> +<option value="Montserrat">Montserrat</option> +<option value="Morocco">Morocco</option> +<option value="Mozambique">Mozambique</option> +<option value="Myanmar">Myanmar</option> +<option value="Namibia">Namibia</option> +<option value="Nauru">Nauru</option> +<option value="Nepal">Nepal</option> +<option value="Netherlands">Netherlands</option> +<option value="Netherlands Antilles">Netherlands Antilles</option> +<option value="New Caledonia">New Caledonia</option> +<option value="New Zealand">New Zealand</option> +<option value="Nicaragua">Nicaragua</option> +<option value="Niger">Niger</option> +<option value="Nigeria">Nigeria</option> +<option value="Niue">Niue</option> +<option value="Norfolk Island">Norfolk Island</option> +<option value="Northern Mariana Islands">Northern Mariana Islands</option> +<option value="Norway">Norway</option> +<option value="Oman">Oman</option> +<option value="Pakistan">Pakistan</option> +<option value="Palau">Palau</option> +<option value="Palestinian Territory, Occupied">Palestinian Territory, Occupied</option> +<option value="Panama">Panama</option> +<option value="Papua New Guinea">Papua New Guinea</option> +<option value="Paraguay">Paraguay</option> +<option value="Peru">Peru</option> +<option value="Philippines">Philippines</option> +<option value="Pitcairn">Pitcairn</option> +<option value="Poland">Poland</option> +<option value="Portugal">Portugal</option> +<option value="Puerto Rico">Puerto Rico</option> +<option value="Qatar">Qatar</option> +<option value="Reunion">Reunion</option> +<option value="Romania">Romania</option> +<option value="Russian Federation">Russian Federation</option> +<option value="Rwanda">Rwanda</option> +<option value="Saint Barthelemy">Saint Barthelemy</option> +<option value="Saint Helena">Saint Helena</option> +<option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option> +<option value="Saint Lucia">Saint Lucia</option> +<option value="Saint Pierre and Miquelon">Saint Pierre and Miquelon</option> +<option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option> +<option value="Samoa">Samoa</option> +<option value="San Marino">San Marino</option> +<option value="Sao Tome and Principe">Sao Tome and Principe</option> +<option value="Saudi Arabia">Saudi Arabia</option> +<option value="Senegal">Senegal</option> +<option value="Serbia">Serbia</option> +<option value="Seychelles">Seychelles</option> +<option value="Sierra Leone">Sierra Leone</option> +<option value="Singapore">Singapore</option> +<option value="Slovakia">Slovakia</option> +<option value="Slovenia">Slovenia</option> +<option value="Solomon Islands">Solomon Islands</option> +<option value="Somalia">Somalia</option> +<option value="South Africa">South Africa</option> +<option value="South Georgia and the South Sandwich Islands">South Georgia and the South Sandwich Islands</option> +<option value="Spain">Spain</option> +<option value="Sri Lanka">Sri Lanka</option> +<option value="Sudan">Sudan</option> +<option value="Suriname">Suriname</option> +<option value="Svalbard and Jan Mayen">Svalbard and Jan Mayen</option> +<option value="Swaziland">Swaziland</option> +<option value="Sweden">Sweden</option> +<option value="Switzerland">Switzerland</option> +<option value="Syrian Arab Republic">Syrian Arab Republic</option> +<option value="Taiwan, Province of China">Taiwan, Province of China</option> +<option value="Tajikistan">Tajikistan</option> +<option value="Tanzania, United Republic of">Tanzania, United Republic of</option> +<option value="Thailand">Thailand</option> +<option value="Timor-Leste">Timor-Leste</option> +<option value="Togo">Togo</option> +<option value="Tokelau">Tokelau</option> +<option value="Tonga">Tonga</option> +<option value="Trinidad and Tobago">Trinidad and Tobago</option> +<option value="Tunisia">Tunisia</option> +<option value="Turkey">Turkey</option> +<option value="Turkmenistan">Turkmenistan</option> +<option value="Turks and Caicos Islands">Turks and Caicos Islands</option> +<option value="Tuvalu">Tuvalu</option> +<option value="Uganda">Uganda</option> +<option value="Ukraine">Ukraine</option> +<option value="United Arab Emirates">United Arab Emirates</option> +<option value="United Kingdom">United Kingdom</option> +<option value="United States">United States</option> +<option value="United States Minor Outlying Islands">United States Minor Outlying Islands</option> +<option value="Uruguay">Uruguay</option> +<option value="Uzbekistan">Uzbekistan</option> +<option value="Vanuatu">Vanuatu</option> +<option value="Venezuela">Venezuela</option> +<option value="Viet Nam">Viet Nam</option> +<option value="Virgin Islands, British">Virgin Islands, British</option> +<option value="Virgin Islands, U.S.">Virgin Islands, U.S.</option> +<option value="Wallis and Futuna">Wallis and Futuna</option> +<option value="Western Sahara">Western Sahara</option> +<option value="Yemen">Yemen</option> +<option value="Zambia">Zambia</option> +<option value="Zimbabwe">Zimbabwe</option></select> + COUNTRIES + + fields_for :post, @post do |f| + concat f.country_select("origin") + end + + assert_dom_equal(expected_select[0..-2], output_buffer) + end + + def test_country_select_under_fields_for_with_index + @post = Post.new + @post.origin = "United States" + expected_select = <<-COUNTRIES +<select id="post_325_origin" name="post[325][origin]"><option value="Afghanistan">Afghanistan</option> +<option value="Aland Islands">Aland Islands</option> +<option value="Albania">Albania</option> +<option value="Algeria">Algeria</option> +<option value="American Samoa">American Samoa</option> +<option value="Andorra">Andorra</option> +<option value="Angola">Angola</option> +<option value="Anguilla">Anguilla</option> +<option value="Antarctica">Antarctica</option> +<option value="Antigua And Barbuda">Antigua And Barbuda</option> +<option value="Argentina">Argentina</option> +<option value="Armenia">Armenia</option> +<option value="Aruba">Aruba</option> +<option value="Australia">Australia</option> +<option value="Austria">Austria</option> +<option value="Azerbaijan">Azerbaijan</option> +<option value="Bahamas">Bahamas</option> +<option value="Bahrain">Bahrain</option> +<option value="Bangladesh">Bangladesh</option> +<option value="Barbados">Barbados</option> +<option value="Belarus">Belarus</option> +<option value="Belgium">Belgium</option> +<option value="Belize">Belize</option> +<option value="Benin">Benin</option> +<option value="Bermuda">Bermuda</option> +<option value="Bhutan">Bhutan</option> +<option value="Bolivia">Bolivia</option> +<option value="Bosnia and Herzegowina">Bosnia and Herzegowina</option> +<option value="Botswana">Botswana</option> +<option value="Bouvet Island">Bouvet Island</option> +<option value="Brazil">Brazil</option> +<option value="British Indian Ocean Territory">British Indian Ocean Territory</option> +<option value="Brunei Darussalam">Brunei Darussalam</option> +<option value="Bulgaria">Bulgaria</option> +<option value="Burkina Faso">Burkina Faso</option> +<option value="Burundi">Burundi</option> +<option value="Cambodia">Cambodia</option> +<option value="Cameroon">Cameroon</option> +<option value="Canada">Canada</option> +<option value="Cape Verde">Cape Verde</option> +<option value="Cayman Islands">Cayman Islands</option> +<option value="Central African Republic">Central African Republic</option> +<option value="Chad">Chad</option> +<option value="Chile">Chile</option> +<option value="China">China</option> +<option value="Christmas Island">Christmas Island</option> +<option value="Cocos (Keeling) Islands">Cocos (Keeling) Islands</option> +<option value="Colombia">Colombia</option> +<option value="Comoros">Comoros</option> +<option value="Congo">Congo</option> +<option value="Congo, the Democratic Republic of the">Congo, the Democratic Republic of the</option> +<option value="Cook Islands">Cook Islands</option> +<option value="Costa Rica">Costa Rica</option> +<option value="Cote d'Ivoire">Cote d'Ivoire</option> +<option value="Croatia">Croatia</option> +<option value="Cuba">Cuba</option> +<option value="Cyprus">Cyprus</option> +<option value="Czech Republic">Czech Republic</option> +<option value="Denmark">Denmark</option> +<option value="Djibouti">Djibouti</option> +<option value="Dominica">Dominica</option> +<option value="Dominican Republic">Dominican Republic</option> +<option value="Ecuador">Ecuador</option> +<option value="Egypt">Egypt</option> +<option value="El Salvador">El Salvador</option> +<option value="Equatorial Guinea">Equatorial Guinea</option> +<option value="Eritrea">Eritrea</option> +<option value="Estonia">Estonia</option> +<option value="Ethiopia">Ethiopia</option> +<option value="Falkland Islands (Malvinas)">Falkland Islands (Malvinas)</option> +<option value="Faroe Islands">Faroe Islands</option> +<option value="Fiji">Fiji</option> +<option value="Finland">Finland</option> +<option value="France">France</option> +<option value="French Guiana">French Guiana</option> +<option value="French Polynesia">French Polynesia</option> +<option value="French Southern Territories">French Southern Territories</option> +<option value="Gabon">Gabon</option> +<option value="Gambia">Gambia</option> +<option value="Georgia">Georgia</option> +<option value="Germany">Germany</option> +<option value="Ghana">Ghana</option> +<option value="Gibraltar">Gibraltar</option> +<option value="Greece">Greece</option> +<option value="Greenland">Greenland</option> +<option value="Grenada">Grenada</option> +<option value="Guadeloupe">Guadeloupe</option> +<option value="Guam">Guam</option> +<option value="Guatemala">Guatemala</option> +<option value="Guernsey">Guernsey</option> +<option value="Guinea">Guinea</option> +<option value="Guinea-Bissau">Guinea-Bissau</option> +<option value="Guyana">Guyana</option> +<option value="Haiti">Haiti</option> +<option value="Heard and McDonald Islands">Heard and McDonald Islands</option> +<option value="Holy See (Vatican City State)">Holy See (Vatican City State)</option> +<option value="Honduras">Honduras</option> +<option value="Hong Kong">Hong Kong</option> +<option value="Hungary">Hungary</option> +<option value="Iceland">Iceland</option> +<option value="India">India</option> +<option value="Indonesia">Indonesia</option> +<option value="Iran, Islamic Republic of">Iran, Islamic Republic of</option> +<option value="Iraq">Iraq</option> +<option value="Ireland">Ireland</option> +<option value="Isle of Man">Isle of Man</option> +<option value="Israel">Israel</option> +<option value="Italy">Italy</option> +<option value="Jamaica">Jamaica</option> +<option value="Japan">Japan</option> +<option value="Jersey">Jersey</option> +<option value="Jordan">Jordan</option> +<option value="Kazakhstan">Kazakhstan</option> +<option value="Kenya">Kenya</option> +<option value="Kiribati">Kiribati</option> +<option value="Korea, Democratic People's Republic of">Korea, Democratic People's Republic of</option> +<option value="Korea, Republic of">Korea, Republic of</option> +<option value="Kuwait">Kuwait</option> +<option value="Kyrgyzstan">Kyrgyzstan</option> +<option value="Lao People's Democratic Republic">Lao People's Democratic Republic</option> +<option value="Latvia">Latvia</option> +<option value="Lebanon">Lebanon</option> +<option value="Lesotho">Lesotho</option> +<option value="Liberia">Liberia</option> +<option value="Libyan Arab Jamahiriya">Libyan Arab Jamahiriya</option> +<option value="Liechtenstein">Liechtenstein</option> +<option value="Lithuania">Lithuania</option> +<option value="Luxembourg">Luxembourg</option> +<option value="Macao">Macao</option> +<option value="Macedonia, The Former Yugoslav Republic Of">Macedonia, The Former Yugoslav Republic Of</option> +<option value="Madagascar">Madagascar</option> +<option value="Malawi">Malawi</option> +<option value="Malaysia">Malaysia</option> +<option value="Maldives">Maldives</option> +<option value="Mali">Mali</option> +<option value="Malta">Malta</option> +<option value="Marshall Islands">Marshall Islands</option> +<option value="Martinique">Martinique</option> +<option value="Mauritania">Mauritania</option> +<option value="Mauritius">Mauritius</option> +<option value="Mayotte">Mayotte</option> +<option value="Mexico">Mexico</option> +<option value="Micronesia, Federated States of">Micronesia, Federated States of</option> +<option value="Moldova, Republic of">Moldova, Republic of</option> +<option value="Monaco">Monaco</option> +<option value="Mongolia">Mongolia</option> +<option value="Montenegro">Montenegro</option> +<option value="Montserrat">Montserrat</option> +<option value="Morocco">Morocco</option> +<option value="Mozambique">Mozambique</option> +<option value="Myanmar">Myanmar</option> +<option value="Namibia">Namibia</option> +<option value="Nauru">Nauru</option> +<option value="Nepal">Nepal</option> +<option value="Netherlands">Netherlands</option> +<option value="Netherlands Antilles">Netherlands Antilles</option> +<option value="New Caledonia">New Caledonia</option> +<option value="New Zealand">New Zealand</option> +<option value="Nicaragua">Nicaragua</option> +<option value="Niger">Niger</option> +<option value="Nigeria">Nigeria</option> +<option value="Niue">Niue</option> +<option value="Norfolk Island">Norfolk Island</option> +<option value="Northern Mariana Islands">Northern Mariana Islands</option> +<option value="Norway">Norway</option> +<option value="Oman">Oman</option> +<option value="Pakistan">Pakistan</option> +<option value="Palau">Palau</option> +<option value="Palestinian Territory, Occupied">Palestinian Territory, Occupied</option> +<option value="Panama">Panama</option> +<option value="Papua New Guinea">Papua New Guinea</option> +<option value="Paraguay">Paraguay</option> +<option value="Peru">Peru</option> +<option value="Philippines">Philippines</option> +<option value="Pitcairn">Pitcairn</option> +<option value="Poland">Poland</option> +<option value="Portugal">Portugal</option> +<option value="Puerto Rico">Puerto Rico</option> +<option value="Qatar">Qatar</option> +<option value="Reunion">Reunion</option> +<option value="Romania">Romania</option> +<option value="Russian Federation">Russian Federation</option> +<option value="Rwanda">Rwanda</option> +<option value="Saint Barthelemy">Saint Barthelemy</option> +<option value="Saint Helena">Saint Helena</option> +<option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option> +<option value="Saint Lucia">Saint Lucia</option> +<option value="Saint Pierre and Miquelon">Saint Pierre and Miquelon</option> +<option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option> +<option value="Samoa">Samoa</option> +<option value="San Marino">San Marino</option> +<option value="Sao Tome and Principe">Sao Tome and Principe</option> +<option value="Saudi Arabia">Saudi Arabia</option> +<option value="Senegal">Senegal</option> +<option value="Serbia">Serbia</option> +<option value="Seychelles">Seychelles</option> +<option value="Sierra Leone">Sierra Leone</option> +<option value="Singapore">Singapore</option> +<option value="Slovakia">Slovakia</option> +<option value="Slovenia">Slovenia</option> +<option value="Solomon Islands">Solomon Islands</option> +<option value="Somalia">Somalia</option> +<option value="South Africa">South Africa</option> +<option value="South Georgia and the South Sandwich Islands">South Georgia and the South Sandwich Islands</option> +<option value="Spain">Spain</option> +<option value="Sri Lanka">Sri Lanka</option> +<option value="Sudan">Sudan</option> +<option value="Suriname">Suriname</option> +<option value="Svalbard and Jan Mayen">Svalbard and Jan Mayen</option> +<option value="Swaziland">Swaziland</option> +<option value="Sweden">Sweden</option> +<option value="Switzerland">Switzerland</option> +<option value="Syrian Arab Republic">Syrian Arab Republic</option> +<option value="Taiwan, Province of China">Taiwan, Province of China</option> +<option value="Tajikistan">Tajikistan</option> +<option value="Tanzania, United Republic of">Tanzania, United Republic of</option> +<option value="Thailand">Thailand</option> +<option value="Timor-Leste">Timor-Leste</option> +<option value="Togo">Togo</option> +<option value="Tokelau">Tokelau</option> +<option value="Tonga">Tonga</option> +<option value="Trinidad and Tobago">Trinidad and Tobago</option> +<option value="Tunisia">Tunisia</option> +<option value="Turkey">Turkey</option> +<option value="Turkmenistan">Turkmenistan</option> +<option value="Turks and Caicos Islands">Turks and Caicos Islands</option> +<option value="Tuvalu">Tuvalu</option> +<option value="Uganda">Uganda</option> +<option value="Ukraine">Ukraine</option> +<option value="United Arab Emirates">United Arab Emirates</option> +<option value="United Kingdom">United Kingdom</option> +<option selected="selected" value="United States">United States</option> +<option value="United States Minor Outlying Islands">United States Minor Outlying Islands</option> +<option value="Uruguay">Uruguay</option> +<option value="Uzbekistan">Uzbekistan</option> +<option value="Vanuatu">Vanuatu</option> +<option value="Venezuela">Venezuela</option> +<option value="Viet Nam">Viet Nam</option> +<option value="Virgin Islands, British">Virgin Islands, British</option> +<option value="Virgin Islands, U.S.">Virgin Islands, U.S.</option> +<option value="Wallis and Futuna">Wallis and Futuna</option> +<option value="Western Sahara">Western Sahara</option> +<option value="Yemen">Yemen</option> +<option value="Zambia">Zambia</option> +<option value="Zimbabwe">Zimbabwe</option></select> + COUNTRIES + + fields_for :post, @post, :index => 325 do |f| + concat f.country_select("origin") + end + + assert_dom_equal(expected_select[0..-2], output_buffer) + end + + def test_country_select_under_fields_for_with_auto_index + @post = Post.new + @post.origin = "Iraq" + def @post.to_param; 325; end + + expected_select = <<-COUNTRIES +<select id="post_325_origin" name="post[325][origin]"><option value="Afghanistan">Afghanistan</option> +<option value="Aland Islands">Aland Islands</option> +<option value="Albania">Albania</option> +<option value="Algeria">Algeria</option> +<option value="American Samoa">American Samoa</option> +<option value="Andorra">Andorra</option> +<option value="Angola">Angola</option> +<option value="Anguilla">Anguilla</option> +<option value="Antarctica">Antarctica</option> +<option value="Antigua And Barbuda">Antigua And Barbuda</option> +<option value="Argentina">Argentina</option> +<option value="Armenia">Armenia</option> +<option value="Aruba">Aruba</option> +<option value="Australia">Australia</option> +<option value="Austria">Austria</option> +<option value="Azerbaijan">Azerbaijan</option> +<option value="Bahamas">Bahamas</option> +<option value="Bahrain">Bahrain</option> +<option value="Bangladesh">Bangladesh</option> +<option value="Barbados">Barbados</option> +<option value="Belarus">Belarus</option> +<option value="Belgium">Belgium</option> +<option value="Belize">Belize</option> +<option value="Benin">Benin</option> +<option value="Bermuda">Bermuda</option> +<option value="Bhutan">Bhutan</option> +<option value="Bolivia">Bolivia</option> +<option value="Bosnia and Herzegowina">Bosnia and Herzegowina</option> +<option value="Botswana">Botswana</option> +<option value="Bouvet Island">Bouvet Island</option> +<option value="Brazil">Brazil</option> +<option value="British Indian Ocean Territory">British Indian Ocean Territory</option> +<option value="Brunei Darussalam">Brunei Darussalam</option> +<option value="Bulgaria">Bulgaria</option> +<option value="Burkina Faso">Burkina Faso</option> +<option value="Burundi">Burundi</option> +<option value="Cambodia">Cambodia</option> +<option value="Cameroon">Cameroon</option> +<option value="Canada">Canada</option> +<option value="Cape Verde">Cape Verde</option> +<option value="Cayman Islands">Cayman Islands</option> +<option value="Central African Republic">Central African Republic</option> +<option value="Chad">Chad</option> +<option value="Chile">Chile</option> +<option value="China">China</option> +<option value="Christmas Island">Christmas Island</option> +<option value="Cocos (Keeling) Islands">Cocos (Keeling) Islands</option> +<option value="Colombia">Colombia</option> +<option value="Comoros">Comoros</option> +<option value="Congo">Congo</option> +<option value="Congo, the Democratic Republic of the">Congo, the Democratic Republic of the</option> +<option value="Cook Islands">Cook Islands</option> +<option value="Costa Rica">Costa Rica</option> +<option value="Cote d'Ivoire">Cote d'Ivoire</option> +<option value="Croatia">Croatia</option> +<option value="Cuba">Cuba</option> +<option value="Cyprus">Cyprus</option> +<option value="Czech Republic">Czech Republic</option> +<option value="Denmark">Denmark</option> +<option value="Djibouti">Djibouti</option> +<option value="Dominica">Dominica</option> +<option value="Dominican Republic">Dominican Republic</option> +<option value="Ecuador">Ecuador</option> +<option value="Egypt">Egypt</option> +<option value="El Salvador">El Salvador</option> +<option value="Equatorial Guinea">Equatorial Guinea</option> +<option value="Eritrea">Eritrea</option> +<option value="Estonia">Estonia</option> +<option value="Ethiopia">Ethiopia</option> +<option value="Falkland Islands (Malvinas)">Falkland Islands (Malvinas)</option> +<option value="Faroe Islands">Faroe Islands</option> +<option value="Fiji">Fiji</option> +<option value="Finland">Finland</option> +<option value="France">France</option> +<option value="French Guiana">French Guiana</option> +<option value="French Polynesia">French Polynesia</option> +<option value="French Southern Territories">French Southern Territories</option> +<option value="Gabon">Gabon</option> +<option value="Gambia">Gambia</option> +<option value="Georgia">Georgia</option> +<option value="Germany">Germany</option> +<option value="Ghana">Ghana</option> +<option value="Gibraltar">Gibraltar</option> +<option value="Greece">Greece</option> +<option value="Greenland">Greenland</option> +<option value="Grenada">Grenada</option> +<option value="Guadeloupe">Guadeloupe</option> +<option value="Guam">Guam</option> +<option value="Guatemala">Guatemala</option> +<option value="Guernsey">Guernsey</option> +<option value="Guinea">Guinea</option> +<option value="Guinea-Bissau">Guinea-Bissau</option> +<option value="Guyana">Guyana</option> +<option value="Haiti">Haiti</option> +<option value="Heard and McDonald Islands">Heard and McDonald Islands</option> +<option value="Holy See (Vatican City State)">Holy See (Vatican City State)</option> +<option value="Honduras">Honduras</option> +<option value="Hong Kong">Hong Kong</option> +<option value="Hungary">Hungary</option> +<option value="Iceland">Iceland</option> +<option value="India">India</option> +<option value="Indonesia">Indonesia</option> +<option value="Iran, Islamic Republic of">Iran, Islamic Republic of</option> +<option selected="selected" value="Iraq">Iraq</option> +<option value="Ireland">Ireland</option> +<option value="Isle of Man">Isle of Man</option> +<option value="Israel">Israel</option> +<option value="Italy">Italy</option> +<option value="Jamaica">Jamaica</option> +<option value="Japan">Japan</option> +<option value="Jersey">Jersey</option> +<option value="Jordan">Jordan</option> +<option value="Kazakhstan">Kazakhstan</option> +<option value="Kenya">Kenya</option> +<option value="Kiribati">Kiribati</option> +<option value="Korea, Democratic People's Republic of">Korea, Democratic People's Republic of</option> +<option value="Korea, Republic of">Korea, Republic of</option> +<option value="Kuwait">Kuwait</option> +<option value="Kyrgyzstan">Kyrgyzstan</option> +<option value="Lao People's Democratic Republic">Lao People's Democratic Republic</option> +<option value="Latvia">Latvia</option> +<option value="Lebanon">Lebanon</option> +<option value="Lesotho">Lesotho</option> +<option value="Liberia">Liberia</option> +<option value="Libyan Arab Jamahiriya">Libyan Arab Jamahiriya</option> +<option value="Liechtenstein">Liechtenstein</option> +<option value="Lithuania">Lithuania</option> +<option value="Luxembourg">Luxembourg</option> +<option value="Macao">Macao</option> +<option value="Macedonia, The Former Yugoslav Republic Of">Macedonia, The Former Yugoslav Republic Of</option> +<option value="Madagascar">Madagascar</option> +<option value="Malawi">Malawi</option> +<option value="Malaysia">Malaysia</option> +<option value="Maldives">Maldives</option> +<option value="Mali">Mali</option> +<option value="Malta">Malta</option> +<option value="Marshall Islands">Marshall Islands</option> +<option value="Martinique">Martinique</option> +<option value="Mauritania">Mauritania</option> +<option value="Mauritius">Mauritius</option> +<option value="Mayotte">Mayotte</option> +<option value="Mexico">Mexico</option> +<option value="Micronesia, Federated States of">Micronesia, Federated States of</option> +<option value="Moldova, Republic of">Moldova, Republic of</option> +<option value="Monaco">Monaco</option> +<option value="Mongolia">Mongolia</option> +<option value="Montenegro">Montenegro</option> +<option value="Montserrat">Montserrat</option> +<option value="Morocco">Morocco</option> +<option value="Mozambique">Mozambique</option> +<option value="Myanmar">Myanmar</option> +<option value="Namibia">Namibia</option> +<option value="Nauru">Nauru</option> +<option value="Nepal">Nepal</option> +<option value="Netherlands">Netherlands</option> +<option value="Netherlands Antilles">Netherlands Antilles</option> +<option value="New Caledonia">New Caledonia</option> +<option value="New Zealand">New Zealand</option> +<option value="Nicaragua">Nicaragua</option> +<option value="Niger">Niger</option> +<option value="Nigeria">Nigeria</option> +<option value="Niue">Niue</option> +<option value="Norfolk Island">Norfolk Island</option> +<option value="Northern Mariana Islands">Northern Mariana Islands</option> +<option value="Norway">Norway</option> +<option value="Oman">Oman</option> +<option value="Pakistan">Pakistan</option> +<option value="Palau">Palau</option> +<option value="Palestinian Territory, Occupied">Palestinian Territory, Occupied</option> +<option value="Panama">Panama</option> +<option value="Papua New Guinea">Papua New Guinea</option> +<option value="Paraguay">Paraguay</option> +<option value="Peru">Peru</option> +<option value="Philippines">Philippines</option> +<option value="Pitcairn">Pitcairn</option> +<option value="Poland">Poland</option> +<option value="Portugal">Portugal</option> +<option value="Puerto Rico">Puerto Rico</option> +<option value="Qatar">Qatar</option> +<option value="Reunion">Reunion</option> +<option value="Romania">Romania</option> +<option value="Russian Federation">Russian Federation</option> +<option value="Rwanda">Rwanda</option> +<option value="Saint Barthelemy">Saint Barthelemy</option> +<option value="Saint Helena">Saint Helena</option> +<option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option> +<option value="Saint Lucia">Saint Lucia</option> +<option value="Saint Pierre and Miquelon">Saint Pierre and Miquelon</option> +<option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option> +<option value="Samoa">Samoa</option> +<option value="San Marino">San Marino</option> +<option value="Sao Tome and Principe">Sao Tome and Principe</option> +<option value="Saudi Arabia">Saudi Arabia</option> +<option value="Senegal">Senegal</option> +<option value="Serbia">Serbia</option> +<option value="Seychelles">Seychelles</option> +<option value="Sierra Leone">Sierra Leone</option> +<option value="Singapore">Singapore</option> +<option value="Slovakia">Slovakia</option> +<option value="Slovenia">Slovenia</option> +<option value="Solomon Islands">Solomon Islands</option> +<option value="Somalia">Somalia</option> +<option value="South Africa">South Africa</option> +<option value="South Georgia and the South Sandwich Islands">South Georgia and the South Sandwich Islands</option> +<option value="Spain">Spain</option> +<option value="Sri Lanka">Sri Lanka</option> +<option value="Sudan">Sudan</option> +<option value="Suriname">Suriname</option> +<option value="Svalbard and Jan Mayen">Svalbard and Jan Mayen</option> +<option value="Swaziland">Swaziland</option> +<option value="Sweden">Sweden</option> +<option value="Switzerland">Switzerland</option> +<option value="Syrian Arab Republic">Syrian Arab Republic</option> +<option value="Taiwan, Province of China">Taiwan, Province of China</option> +<option value="Tajikistan">Tajikistan</option> +<option value="Tanzania, United Republic of">Tanzania, United Republic of</option> +<option value="Thailand">Thailand</option> +<option value="Timor-Leste">Timor-Leste</option> +<option value="Togo">Togo</option> +<option value="Tokelau">Tokelau</option> +<option value="Tonga">Tonga</option> +<option value="Trinidad and Tobago">Trinidad and Tobago</option> +<option value="Tunisia">Tunisia</option> +<option value="Turkey">Turkey</option> +<option value="Turkmenistan">Turkmenistan</option> +<option value="Turks and Caicos Islands">Turks and Caicos Islands</option> +<option value="Tuvalu">Tuvalu</option> +<option value="Uganda">Uganda</option> +<option value="Ukraine">Ukraine</option> +<option value="United Arab Emirates">United Arab Emirates</option> +<option value="United Kingdom">United Kingdom</option> +<option value="United States">United States</option> +<option value="United States Minor Outlying Islands">United States Minor Outlying Islands</option> +<option value="Uruguay">Uruguay</option> +<option value="Uzbekistan">Uzbekistan</option> +<option value="Vanuatu">Vanuatu</option> +<option value="Venezuela">Venezuela</option> +<option value="Viet Nam">Viet Nam</option> +<option value="Virgin Islands, British">Virgin Islands, British</option> +<option value="Virgin Islands, U.S.">Virgin Islands, U.S.</option> +<option value="Wallis and Futuna">Wallis and Futuna</option> +<option value="Western Sahara">Western Sahara</option> +<option value="Yemen">Yemen</option> +<option value="Zambia">Zambia</option> +<option value="Zimbabwe">Zimbabwe</option></select> + COUNTRIES + + fields_for "post[]", @post do |f| + concat f.country_select("origin") + end + + assert_dom_equal(expected_select[0..-2], output_buffer) + end + def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) @@ -1197,6 +2043,45 @@ uses_mocha "FormOptionsHelperTest" do ) end + def test_time_zone_select_under_fields_for_with_index + @firm = Firm.new("D") + + fields_for :firm, @firm, :index => 305 do |f| + concat f.time_zone_select(:time_zone) + end + + assert_dom_equal( + "<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" + + "<option value=\"A\">A</option>\n" + + "<option value=\"B\">B</option>\n" + + "<option value=\"C\">C</option>\n" + + "<option value=\"D\" selected=\"selected\">D</option>\n" + + "<option value=\"E\">E</option>" + + "</select>", + output_buffer + ) + end + + def test_time_zone_select_under_fields_for_with_auto_index + @firm = Firm.new("D") + def @firm.to_param; 305; end + + fields_for "firm[]", @firm do |f| + concat f.time_zone_select(:time_zone) + end + + assert_dom_equal( + "<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" + + "<option value=\"A\">A</option>\n" + + "<option value=\"B\">B</option>\n" + + "<option value=\"C\">C</option>\n" + + "<option value=\"D\" selected=\"selected\">D</option>\n" + + "<option value=\"E\">E</option>" + + "</select>", + output_buffer + ) + end + def test_time_zone_select_with_blank @firm = Firm.new("D") html = time_zone_select("firm", "time_zone", nil, :include_blank => true) diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 60b83b476d..1d9bc5eb9b 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -201,9 +201,9 @@ class PrototypeHelperTest < PrototypeHelperBaseTest end - def test_submit_to_remote + def test_button_to_remote assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />), - submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle") + button_to_remote("More beer!", 1_000_000, :update => "empty_bottle") end def test_observe_field diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 726cf37026..cc5b4900dc 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -4,7 +4,7 @@ require 'controller/fake_models' class ViewRenderTest < Test::Unit::TestCase def setup @assigns = { :secret => 'in the sauce' } - @view = ActionView::Base.new([FIXTURE_LOAD_PATH], @assigns) + @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns) end def test_render_file @@ -95,8 +95,8 @@ class ViewRenderTest < Test::Unit::TestCase end class CustomHandler < ActionView::TemplateHandler - def render(template) - [template.source, template.locals].inspect + def render(template, local_assigns) + [template.source, local_assigns].inspect end end @@ -115,18 +115,17 @@ class ViewRenderTest < Test::Unit::TestCase def compile(template) "@output_buffer = ''\n" + - "@output_buffer << 'locals: #{template.locals.inspect}, '\n" + "@output_buffer << 'source: #{template.source.inspect}'\n" end end def test_render_inline_with_compilable_custom_type ActionView::Template.register_template_handler :foo, CompilableCustomHandler - assert_equal 'locals: {}, source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo) + assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo) end def test_render_inline_with_locals_and_compilable_custom_type ActionView::Template.register_template_handler :foo, CompilableCustomHandler - assert_equal 'locals: {:name=>"Josh"}, source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) + assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 3d5f7eae11..91d5c6ffb5 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -292,6 +292,7 @@ class UrlHelperTest < ActionView::TestCase assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)") assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain(dot)com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)") assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%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", :replace_at => "(at)", :replace_dot => "(dot)") + assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%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%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") end def protect_against_forgery? @@ -301,8 +302,6 @@ end class UrlHelperWithControllerTest < ActionView::TestCase class UrlHelperController < ActionController::Base - self.view_paths = [FIXTURE_LOAD_PATH] - def self.controller_path; 'url_helper_with_controller' end def show_url_for @@ -313,6 +312,10 @@ class UrlHelperWithControllerTest < ActionView::TestCase render :inline => "<%= show_named_route_#{params[:kind]} %>" end + def nil_url_for + render :inline => '<%= url_for(nil) %>' + end + def rescue_action(e) raise e end end @@ -329,7 +332,7 @@ class UrlHelperWithControllerTest < ActionView::TestCase assert_equal '/url_helper_with_controller/show_url_for', @response.body end - def test_named_route_shows_host_and_path + def test_named_route_url_shows_host_and_path with_url_helper_routing do get :show_named_route, :kind => 'url' assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body @@ -343,6 +346,11 @@ class UrlHelperWithControllerTest < ActionView::TestCase end end + def test_url_for_nil_returns_current_path + get :nil_url_for + assert_equal '/url_helper_with_controller/nil_url_for', @response.body + end + protected def with_url_helper_routing with_routing do |set| @@ -356,8 +364,6 @@ end class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase class TasksController < ActionController::Base - self.view_paths = [FIXTURE_LOAD_PATH] - def self.controller_path; 'tasks' end def index @@ -448,8 +454,6 @@ end class PolymorphicControllerTest < ActionView::TestCase class WorkshopsController < ActionController::Base - self.view_paths = [FIXTURE_LOAD_PATH] - def self.controller_path; 'workshops' end def index @@ -466,8 +470,6 @@ class PolymorphicControllerTest < ActionView::TestCase end class SessionsController < ActionController::Base - self.view_paths = [FIXTURE_LOAD_PATH] - def self.controller_path; 'sessions' end def index |