diff options
author | rick <technoweenie@gmail.com> | 2008-08-26 11:53:33 -0700 |
---|---|---|
committer | rick <technoweenie@gmail.com> | 2008-08-26 11:53:33 -0700 |
commit | 0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2 (patch) | |
tree | 1a782151632dd80c8a18c3960536bdf8643debe3 /actionpack/test/template | |
parent | 0a6d75dedd79407376aae1f01302164dfd3e44b6 (diff) | |
parent | 229eedfda87a7706dbb5e3e51af8707b3adae375 (diff) | |
download | rails-0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2.tar.gz rails-0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2.tar.bz2 rails-0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2.zip |
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'actionpack/test/template')
20 files changed, 2556 insertions, 1759 deletions
diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb new file mode 100644 index 0000000000..7ba9659814 --- /dev/null +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -0,0 +1,46 @@ +require 'abstract_unit' + +class ActiveRecordHelperI18nTest < Test::Unit::TestCase + include ActionView::Helpers::ActiveRecordHelper + + attr_reader :request + uses_mocha 'active_record_helper_i18n_test' do + def setup + @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) + @object_name = 'book' + stubs(:content_tag).returns 'content_tag' + + I18n.stubs(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved" + I18n.stubs(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' + end + + def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message + I18n.expects(:translate).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never + error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') + end + + def test_error_messages_for_given_no_header_option_it_translates_header_message + I18n.expects(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message' + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' + error_messages_for(:object => @object, :locale => 'en-US') + end + + def test_error_messages_for_given_a_message_option_it_does_not_translate_message + I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).never + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' + error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') + end + + def test_error_messages_for_given_no_message_option_it_translates_message + I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' + error_messages_for(:object => @object, :locale => 'en-US') + end + + def test_error_messages_for_given_object_name_it_translates_object_name + I18n.expects(:t).with(:header, :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved" + I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name + error_messages_for(:object => @object, :locale => 'en-US', :object_name => @object_name) + end + end +end diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index dfc30e651a..e46f95d18b 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -10,17 +10,17 @@ class ActiveRecordHelperTest < ActionView::TestCase alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast) alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast) end - + User = Struct.new("User", :email) User.class_eval do alias_method :email_before_type_cast, :email unless respond_to?(:email_before_type_cast) end - + Column = Struct.new("Column", :type, :name, :human_name) end def setup_post - @post = Post.new + @post = Post.new def @post.errors Class.new { def on(field) @@ -33,12 +33,12 @@ class ActiveRecordHelperTest < ActionView::TestCase false end end - def empty?() false end - def count() 1 end + def empty?() false end + def count() 1 end def full_messages() [ "Author name can't be empty" ] end }.new end - + def @post.new_record?() true end def @post.to_param() nil end @@ -58,16 +58,16 @@ class ActiveRecordHelperTest < ActionView::TestCase end def setup_user - @user = User.new + @user = User.new def @user.errors Class.new { def on(field) field == "email" end - def empty?() false end - def count() 1 end + def empty?() false end + def count() 1 end def full_messages() [ "User email can't be empty" ] end }.new end - + def @user.new_record?() true end def @user.to_param() nil end @@ -81,7 +81,7 @@ class ActiveRecordHelperTest < ActionView::TestCase @user.email = "" end - + def protect_against_forgery? @protect_against_forgery ? true : false end @@ -92,7 +92,7 @@ class ActiveRecordHelperTest < ActionView::TestCase setup_user @response = ActionController::TestResponse.new - + @controller = Object.new def @controller.url_for(options) options = options.symbolize_keys @@ -111,7 +111,7 @@ class ActiveRecordHelperTest < ActionView::TestCase assert_dom_equal( %(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>), text_area("post", "body") - ) + ) end def test_text_field_with_errors @@ -140,7 +140,7 @@ class ActiveRecordHelperTest < ActionView::TestCase form("post") ) end - + def test_form_with_protect_against_forgery @protect_against_forgery = true @request_forgery_protection_token = 'authenticity_token' @@ -150,7 +150,7 @@ class ActiveRecordHelperTest < ActionView::TestCase form("post") ) end - + def test_form_with_method_option assert_dom_equal( %(<form action="create" method="get"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), @@ -211,9 +211,9 @@ class ActiveRecordHelperTest < ActionView::TestCase other_post = @post assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name) end - - def test_error_message_on_should_use_options - assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, "before", "after", "differentError") + + def test_error_message_on_with_options_hash + assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') end def test_error_messages_for_many_objects @@ -224,10 +224,10 @@ class ActiveRecordHelperTest < ActionView::TestCase # add the default to put post back in the title assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post") - + # symbols work as well assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post) - + # any default works too assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey") @@ -242,7 +242,7 @@ class ActiveRecordHelperTest < ActionView::TestCase message = "Please fix the following fields and resubmit:" assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message) end - + def test_error_messages_for_non_instance_variable actual_user = @user actual_post = @post @@ -251,14 +251,14 @@ class ActiveRecordHelperTest < ActionView::TestCase #explicitly set object assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post) - + #multiple objects assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post]) - + #nil object assert_equal '', error_messages_for('user', :object => nil) end - + def test_form_with_string_multipart assert_dom_equal( %(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 020e112fd0..7e40a55dc5 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -30,7 +30,6 @@ class AssetTagHelperTest < ActionView::TestCase end.new @request = Class.new do - def relative_url_root() "" end def protocol() 'http://' end def ssl?() false end def host_with_port() 'localhost' end @@ -39,8 +38,7 @@ class AssetTagHelperTest < ActionView::TestCase @controller.request = @request ActionView::Helpers::AssetTagHelper::reset_javascript_include_default - - ActionView::Base.computed_public_paths.clear + COMPUTED_PUBLIC_PATHS.clear end def teardown @@ -119,7 +117,7 @@ class AssetTagHelperTest < ActionView::TestCase %(image_path("xml")) => %(/images/xml), %(image_path("xml.png")) => %(/images/xml.png), %(image_path("dir/xml.png")) => %(/images/dir/xml.png), - %(image_path("/dir/xml.png")) => %(/dir/xml.png) + %(image_path("/dir/xml.png")) => %(/dir/xml.png) } PathToImageToTag = { @@ -161,7 +159,7 @@ class AssetTagHelperTest < ActionView::TestCase ENV["RAILS_ASSET_ID"] = "" JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } - ActionView::Base.computed_public_paths.clear + COMPUTED_PUBLIC_PATHS.clear ENV["RAILS_ASSET_ID"] = "1" assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>), javascript_include_tag(:defaults)) @@ -174,7 +172,7 @@ class AssetTagHelperTest < ActionView::TestCase ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2' 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/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults) end - + def test_custom_javascript_expansions ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"] assert_dom_equal %(<script src="/javascripts/first.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>), javascript_include_tag('first', :monkey, 'last') @@ -217,7 +215,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_image_path ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - + def test_path_to_image_alias_for_image_path PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -225,7 +223,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_image_tag ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - + def test_timebased_asset_id expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png") @@ -234,7 +232,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_should_skip_asset_id_on_complete_url assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png") end - + def test_should_use_preset_asset_id ENV["RAILS_ASSET_ID"] = "4500" assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png") @@ -256,14 +254,14 @@ class AssetTagHelperTest < ActionView::TestCase 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/all.js" type="text/javascript"></script>), javascript_include_tag(:all, :cache => true) ) assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) - + assert_dom_equal( %(<script src="http://a0.example.com/javascripts/money.js" type="text/javascript"></script>), javascript_include_tag(:all, :cache => "money") @@ -335,8 +333,9 @@ class AssetTagHelperTest < ActionView::TestCase ActionController::Base.asset_host = 'http://a%d.example.com' ActionController::Base.perform_caching = true + hash = '/javascripts/cache/money.js'.hash % 4 assert_dom_equal( - %(<script src="http://a3.example.com/javascripts/cache/money.js" type="text/javascript"></script>), + %(<script src="http://a#{hash}.example.com/javascripts/cache/money.js" type="text/javascript"></script>), javascript_include_tag(:all, :cache => "cache/money") ) @@ -344,7 +343,7 @@ class AssetTagHelperTest < ActionView::TestCase ensure 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' @@ -390,7 +389,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_caching_javascript_include_tag_when_caching_off ENV["RAILS_ASSET_ID"] = "" ActionController::Base.perform_caching = false - + 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/version.1.0.js" type="text/javascript"></script>), javascript_include_tag(:all, :cache => true) @@ -402,7 +401,7 @@ class AssetTagHelperTest < ActionView::TestCase ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) - + 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/version.1.0.js" type="text/javascript"></script>), javascript_include_tag(:all, :cache => "money") @@ -420,13 +419,14 @@ class AssetTagHelperTest < ActionView::TestCase ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' ActionController::Base.perform_caching = true - + assert_dom_equal( %(<link href="http://a0.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag(:all, :cache => true) ) - assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) + expected = Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/*.css"].map { |p| File.mtime(p) }.max + assert_equal expected, File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) assert_dom_equal( %(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />), @@ -459,7 +459,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_caching_stylesheet_include_tag_when_caching_off ENV["RAILS_ASSET_ID"] = "" ActionController::Base.perform_caching = false - + 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/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag(:all, :cache => true) @@ -471,7 +471,7 @@ class AssetTagHelperTest < ActionView::TestCase ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) - + 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/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag(:all, :cache => "money") @@ -490,6 +490,8 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase tests ActionView::Helpers::AssetTagHelper def setup + ActionController::Base.relative_url_root = "/collaboration/hieraki" + @controller = Class.new do attr_accessor :request @@ -497,22 +499,22 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase "http://www.example.com/collaboration/hieraki" end end.new - - @request = Class.new do - def relative_url_root - "/collaboration/hieraki" - end + @request = Class.new do def protocol 'gopher://' end end.new - + @controller.request = @request - + ActionView::Helpers::AssetTagHelper::reset_javascript_include_default end + def teardown + ActionController::Base.relative_url_root = nil + end + def test_should_compute_proper_path assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag) assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr")) @@ -521,7 +523,7 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse.png'" src="/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse2.png'" src="/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) end - + def test_should_ignore_relative_root_path_on_complete_url assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png")) end diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index 9f7e5b4c6c..ef31ab2c76 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -74,12 +74,30 @@ class ScrollsController < ActionController::Base end end EOT + FEEDS["feed_with_overridden_ids"] = <<-EOT + atom_feed({:id => 'tag:test.rubyonrails.org,2008:test/'}) do |feed| + feed.title("My great blog!") + feed.updated((@scrolls.first.created_at)) + + for scroll in @scrolls + feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry| + entry.title(scroll.title) + entry.content(scroll.body, :type => 'html') + entry.tag!('app:edited', Time.now) + + entry.author do |author| + author.name("DHH") + end + end + end + end + EOT def index @scrolls = [ Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)), Scroll.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)), ] - + render :inline => FEEDS[params[:id]], :type => :builder end @@ -98,21 +116,21 @@ class AtomFeedTest < Test::Unit::TestCase @request.host = "www.nextangle.com" end - + def test_feed_should_use_default_language_if_none_is_given with_restful_routing(:scrolls) do get :index, :id => "defaults" assert_match %r{xml:lang="en-US"}, @response.body end end - + def test_feed_should_include_two_entries with_restful_routing(:scrolls) do get :index, :id => "defaults" assert_select "entry", 2 end end - + def test_entry_should_only_use_published_if_created_at_is_present with_restful_routing(:scrolls) do get :index, :id => "defaults" @@ -167,7 +185,16 @@ class AtomFeedTest < Test::Unit::TestCase end end - private + def test_feed_should_allow_overriding_ids + with_restful_routing(:scrolls) do + get :index, :id => "feed_with_overridden_ids" + assert_select "id", :text => "tag:test.rubyonrails.org,2008:test/" + assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:1" + assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:2" + end + end + +private def with_restful_routing(resources) with_routing do |set| set.draw do |map| diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb new file mode 100644 index 0000000000..e005aa0f03 --- /dev/null +++ b/actionpack/test/template/compiled_templates_test.rb @@ -0,0 +1,47 @@ +require 'abstract_unit' +require 'controller/fake_models' + +uses_mocha 'TestTemplateRecompilation' do + class CompiledTemplatesTest < Test::Unit::TestCase + def setup + @compiled_templates = ActionView::Base::CompiledTemplates + @compiled_templates.instance_methods.each do |m| + @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ + end + end + + def test_template_gets_compiled + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal 1, @compiled_templates.instance_methods.size + end + + def test_template_gets_recompiled_when_using_different_keys_in_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"}) + assert_equal 2, @compiled_templates.instance_methods.size + end + + def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render("test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", render("test/hello_world.erb") + end + + def test_compiled_template_will_always_be_recompiled_when_eager_loaded_templates_is_off + ActionView::PathSet::Path.expects(:eager_load_templates?).times(4).returns(false) + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).times(3) + 3.times { assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + assert_equal 1, @compiled_templates.instance_methods.size + end + + private + def render(*args) + ActionView::Base.new(ActionController::Base.view_paths, {}).render(*args) + end + end +end diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb new file mode 100644 index 0000000000..bf3b2588c8 --- /dev/null +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -0,0 +1,113 @@ +require 'abstract_unit' + +class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase + include ActionView::Helpers::DateHelper + attr_reader :request + + def setup + @from = Time.mktime(2004, 6, 6, 21, 45, 0) + end + + uses_mocha 'date_helper_distance_of_time_in_words_i18n_test' do + # distance_of_time_in_words + + def test_distance_of_time_in_words_calls_i18n + { # with include_seconds + [2.seconds, true] => [:'less_than_x_seconds', 5], + [9.seconds, true] => [:'less_than_x_seconds', 10], + [19.seconds, true] => [:'less_than_x_seconds', 20], + [30.seconds, true] => [:'half_a_minute', nil], + [59.seconds, true] => [:'less_than_x_minutes', 1], + [60.seconds, true] => [:'x_minutes', 1], + + # without include_seconds + [29.seconds, false] => [:'less_than_x_minutes', 1], + [60.seconds, false] => [:'x_minutes', 1], + [44.minutes, false] => [:'x_minutes', 44], + [61.minutes, false] => [:'about_x_hours', 1], + [24.hours, false] => [:'x_days', 1], + [30.days, false] => [:'about_x_months', 1], + [60.days, false] => [:'x_months', 2], + [1.year, false] => [:'about_x_years', 1], + [3.years, false] => [:'over_x_years', 3] + + }.each do |passed, expected| + assert_distance_of_time_in_words_translates_key passed, expected + end + end + + def assert_distance_of_time_in_words_translates_key(passed, expected) + diff, include_seconds = *passed + key, count = *expected + to = @from + diff + + options = {:locale => 'en-US', :scope => :'datetime.distance_in_words'} + options[:count] = count if count + + I18n.expects(:t).with(key, options) + distance_of_time_in_words(@from, to, include_seconds, :locale => 'en-US') + end + + def test_distance_of_time_pluralizations + { [:'less_than_x_seconds', 1] => 'less than 1 second', + [:'less_than_x_seconds', 2] => 'less than 2 seconds', + [:'less_than_x_minutes', 1] => 'less than a minute', + [:'less_than_x_minutes', 2] => 'less than 2 minutes', + [:'x_minutes', 1] => '1 minute', + [:'x_minutes', 2] => '2 minutes', + [:'about_x_hours', 1] => 'about 1 hour', + [:'about_x_hours', 2] => 'about 2 hours', + [:'x_days', 1] => '1 day', + [:'x_days', 2] => '2 days', + [:'about_x_years', 1] => 'about 1 year', + [:'about_x_years', 2] => 'about 2 years', + [:'over_x_years', 1] => 'over 1 year', + [:'over_x_years', 2] => 'over 2 years' + + }.each do |args, expected| + key, count = *args + assert_equal expected, I18n.t(key, :count => count, :scope => 'datetime.distance_in_words') + end + end + end +end + +class DateHelperSelectTagsI18nTests < Test::Unit::TestCase + include ActionView::Helpers::DateHelper + attr_reader :request + + uses_mocha 'date_helper_select_tags_i18n_tests' do + def setup + I18n.stubs(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES + end + + # select_month + + def test_select_month_given_use_month_names_option_does_not_translate_monthnames + I18n.expects(:translate).never + select_month(8, :locale => 'en-US', :use_month_names => Date::MONTHNAMES) + end + + def test_select_month_translates_monthnames + I18n.expects(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES + select_month(8, :locale => 'en-US') + end + + def test_select_month_given_use_short_month_option_translates_abbr_monthnames + I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en-US').returns Date::ABBR_MONTHNAMES + select_month(8, :locale => 'en-US', :use_short_month => true) + end + + # date_or_time_select + + def test_date_or_time_select_given_an_order_options_does_not_translate_order + I18n.expects(:translate).never + datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en-US') + end + + def test_date_or_time_select_given_no_order_options_translates_order + I18n.expects(:translate).with(:'date.order', :locale => 'en-US').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en-US') + end + end +end
\ No newline at end of file diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 8b4e94c67f..1a645bccc6 100755..100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -17,7 +17,7 @@ class DateHelperTest < ActionView::TestCase end end end - + def assert_distance_of_time_in_words(from, to=nil) to ||= from @@ -86,13 +86,13 @@ class DateHelperTest < ActionView::TestCase from = Time.mktime(2004, 6, 6, 21, 45, 0) assert_distance_of_time_in_words(from) end - + def test_distance_in_words_with_time_zones from = Time.mktime(2004, 6, 6, 21, 45, 0) assert_distance_of_time_in_words(from.in_time_zone('Alaska')) assert_distance_of_time_in_words(from.in_time_zone('Hawaii')) end - + def test_distance_in_words_with_different_time_zones from = Time.mktime(2004, 6, 6, 21, 45, 0) assert_distance_of_time_in_words( @@ -100,13 +100,13 @@ class DateHelperTest < ActionView::TestCase from.in_time_zone('Hawaii') ) end - + def test_distance_in_words_with_dates start_date = Date.new 1975, 1, 31 end_date = Date.new 1977, 1, 31 assert_equal("over 2 years", distance_of_time_in_words(start_date, end_date)) end - + def test_distance_in_words_with_integers assert_equal "less than a minute", distance_of_time_in_words(59) assert_equal "about 1 hour", distance_of_time_in_words(60*60) @@ -557,11 +557,8 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_incomplete_order - expected = %(<select id="date_first_day" name="date[first][day]">\n) - expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) - expected << "</select>\n" - - expected << %(<select id="date_first_year" name="date[first][year]">\n) + # NOTE: modified this test because of minimal API change + expected = %(<select id="date_first_year" name="date[first][year]">\n) expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -569,6 +566,10 @@ class DateHelperTest < ActionView::TestCase expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" + expected << %(<select id="date_first_day" name="date[first][day]">\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << "</select>\n" + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :order => [:day]) end @@ -757,6 +758,26 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]"}, :class => "selector") end + def test_select_date_with_separator + expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) + expected << "</select>\n" + + expected << " / " + + expected << %(<select id="date_first_month" name="date[first][month]">\n) + expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) + expected << "</select>\n" + + expected << " / " + + expected << %(<select id="date_first_day" name="date[first][day]">\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << "</select>\n" + + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :start_year => 2003, :end_year => 2005, :prefix => "date[first]"}) + end + def test_select_datetime expected = %(<select id="date_first_year" name="date[first][year]">\n) expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) @@ -857,6 +878,42 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]"}, :class => 'selector') end + def test_select_datetime_with_all_separators + expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n) + expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) + expected << "</select>\n" + + expected << "/" + + expected << %(<select id="date_first_month" name="date[first][month]" class="selector">\n) + expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) + expected << "</select>\n" + + expected << "/" + + expected << %(<select id="date_first_day" name="date[first][day]" class="selector">\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << "</select>\n" + + expected << "—" + + expected << %(<select id="date_first_hour" name="date[first][hour]" class="selector">\n) + expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) + expected << "</select>\n" + + expected << ":" + + expected << %(<select id="date_first_minute" name="date[first][minute]" class="selector">\n) + expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) + expected << "</select>\n" + + assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), { :datetime_separator => "—", :date_separator => "/", :time_separator => ":", :start_year => 2003, :end_year => 2005, :prefix => "date[first]"}, :class => 'selector') + end + + def test_select_datetime_should_work_with_date + assert_nothing_raised { select_datetime(Date.today) } + end + def test_select_time expected = %(<select id="date_hour" name="date[hour]">\n) expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) @@ -933,32 +990,9 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_time(Time.mktime(2003, 8, 16, 8, 4, 18), {}, :class => 'selector') assert_dom_equal expected, select_time(Time.mktime(2003, 8, 16, 8, 4, 18), {:include_seconds => false}, :class => 'selector') end - - uses_mocha 'TestDatetimeAndTimeSelectUseTimeCurrentAsDefault' do - def test_select_datetime_uses_time_current_as_default - time = stub(:year => 2004, :month => 6, :day => 15, :hour => 16, :min => 35, :sec => 0) - Time.expects(:current).returns time - expects(:select_date).with(time, anything, anything).returns('') - expects(:select_time).with(time, anything, anything).returns('') - select_datetime - end - - def test_select_time_uses_time_current_as_default - time = stub(:year => 2004, :month => 6, :day => 15, :hour => 16, :min => 35, :sec => 0) - Time.expects(:current).returns time - expects(:select_hour).with(time, anything, anything).returns('') - expects(:select_minute).with(time, anything, anything).returns('') - select_time - end - - def test_select_date_uses_date_current_as_default - date = stub(:year => 2004, :month => 6, :day => 15) - Date.expects(:current).returns date - expects(:select_year).with(date, anything, anything).returns('') - expects(:select_month).with(date, anything, anything).returns('') - expects(:select_day).with(date, anything, anything).returns('') - select_date - end + + def test_select_time_should_work_with_date + assert_nothing_raised { select_time(Date.today) } end def test_date_select @@ -1179,6 +1213,30 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_date_select_with_separator + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} + expected << "</select>\n" + + expected << " / " + + expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} + expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} + expected << "</select>\n" + + expected << " / " + + expected << %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n} + expected << %{<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n} + + expected << "</select>\n" + + assert_dom_equal expected, date_select("post", "written_on", { :date_separator => " / " }) + end + def test_time_select @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) @@ -1188,11 +1246,11 @@ class DateHelperTest < ActionView::TestCase expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} expected << %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n) - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]">\n) - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, time_select("post", "written_on") @@ -1203,11 +1261,11 @@ class DateHelperTest < ActionView::TestCase @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) expected = %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n) - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]">\n) - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, time_select("post", "written_on", :ignore_date => true) @@ -1222,15 +1280,15 @@ class DateHelperTest < ActionView::TestCase expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} expected << %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n) - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]">\n) - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %(<select id="post_written_on_6i" name="post[written_on(6i)]">\n) - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 35}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 35}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, time_select("post", "written_on", :include_seconds => true) @@ -1245,11 +1303,11 @@ class DateHelperTest < ActionView::TestCase expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} expected << %(<select id="post_written_on_4i" name="post[written_on(4i)]" class="selector">\n) - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]" class="selector">\n) - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, time_select("post", "written_on", {}, :class => 'selector') @@ -1268,16 +1326,43 @@ class DateHelperTest < ActionView::TestCase expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} expected << %(<select id="post_written_on_4i" name="post[written_on(4i)]" class="selector">\n) - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]" class="selector">\n) - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, output_buffer end + def test_time_select_with_separator + @post = Post.new + @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) + + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} + expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} + + expected << %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n) + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + + expected << " - " + + expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]">\n) + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + + expected << " - " + + expected << %(<select id="post_written_on_6i" name="post[written_on(6i)]">\n) + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 35}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + + assert_dom_equal expected, time_select("post", "written_on", { :time_separator => " - ", :include_seconds => true }) + end + def test_datetime_select @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) @@ -1306,7 +1391,7 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, datetime_select("post", "updated_at") end - + uses_mocha 'TestDatetimeSelectDefaultsToTimeZoneNowWhenConfigTimeZoneIsSet' do def test_datetime_select_defaults_to_time_zone_now_when_config_time_zone_is_set time = stub(:year => 2004, :month => 6, :day => 15, :hour => 16, :min => 35, :sec => 0) @@ -1360,6 +1445,47 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_datetime_select_with_separators + @post = Post.new + @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) + + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} + expected << "</select>\n" + + expected << " / " + + expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} + expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} + expected << "</select>\n" + + expected << " / " + + expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n} + expected << %{<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n} + expected << "</select>\n" + + expected << " , " + + expected << %(<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n) + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + + expected << " - " + + expected << %(<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n) + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + + expected << " - " + + expected << %(<select id="post_updated_at_6i" name="post[updated_at(6i)]">\n) + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 35}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + + assert_dom_equal expected, datetime_select("post", "updated_at", { :date_separator => " / ", :datetime_separator => " , ", :time_separator => " - ", :include_seconds => true }) + end + def test_date_select_with_zero_value_and_no_start_year expected = %(<select id="date_first_year" name="date[first][year]">\n) (Date.today.year-5).upto(Date.today.year+1) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } @@ -1370,8 +1496,7 @@ class DateHelperTest < ActionView::TestCase expected << "</select>\n" expected << %(<select id="date_first_day" name="date[first][day]">\n) - expected << -%(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" assert_dom_equal expected, select_date(0, :end_year => Date.today.year+1, :prefix => "date[first]") @@ -1388,8 +1513,7 @@ class DateHelperTest < ActionView::TestCase expected << "</select>\n" expected << %(<select id="date_first_day" name="date[first][day]">\n) - expected << -%(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" assert_dom_equal expected, select_date(0, :start_year => 2003, :prefix => "date[first]") @@ -1405,8 +1529,7 @@ class DateHelperTest < ActionView::TestCase expected << "</select>\n" expected << %(<select id="date_first_day" name="date[first][day]">\n) - expected << -%(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" assert_dom_equal expected, select_date(0, :prefix => "date[first]") @@ -1422,8 +1545,7 @@ class DateHelperTest < ActionView::TestCase expected << "</select>\n" expected << %(<select id="date_first_day" name="date[first][day]">\n) - expected << -%(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" assert_dom_equal expected, select_date(nil, :prefix => "date[first]") @@ -1530,15 +1652,15 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_6i" name="post[updated_at(6i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 35}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 35}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :include_seconds => true) @@ -1559,11 +1681,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :discard_year => true) @@ -1582,11 +1704,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :discard_month => true) @@ -1601,11 +1723,11 @@ class DateHelperTest < ActionView::TestCase expected << %{<input type="hidden" id="post_updated_at_3i" name="post[updated_at(3i)]" value="15" />\n} expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :discard_year => true, :discard_month => true) @@ -1628,11 +1750,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :order => [:minute, :day, :hour, :month, :year, :second]) @@ -1653,11 +1775,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :order => [:day, :month]) @@ -1680,11 +1802,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 16}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :default => Time.local(2006, 9, 19, 15, 16, 35)) @@ -1727,11 +1849,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n} - 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 9}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 9}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n} - 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 42}>#{leading_zero_on_single_digits(i)}</option>\n) } + 0.upto(59) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 42}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" assert_dom_equal expected, datetime_select("post", "updated_at", :default => { :month => 10, :minute => 42, :hour => 9 }) @@ -1766,33 +1888,158 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, datetime_select("post", "updated_at", {}, :class => 'selector') end - uses_mocha 'TestInstanceTagDefaultTimeFromOptions' do - def test_instance_tag_default_time_from_options_uses_time_current_as_default_when_hash_passed_as_arg - dummy_instance_tag = ActionView::Helpers::InstanceTag.new(1,2,3) - Time.expects(:current).returns Time.now - dummy_instance_tag.send!(:default_time_from_options, :hour => 2) - end - - def test_instance_tag_default_time_from_options_respects_hash_arg_settings_when_time_falls_in_system_local_dst_spring_gap - with_env_tz('US/Central') do - dummy_instance_tag = ActionView::Helpers::InstanceTag.new(1,2,3) - Time.stubs(:now).returns Time.local(2006, 4, 2, 1) - assert_equal 2, dummy_instance_tag.send!(:default_time_from_options, :hour => 2).hour - end - end - - def test_instance_tag_default_time_from_options_handles_far_future_date - dummy_instance_tag = ActionView::Helpers::InstanceTag.new(1,2,3) - time = dummy_instance_tag.send!(:default_time_from_options, :year => 2050, :month => 2, :day => 10, :hour => 15, :min => 30, :sec => 45) - assert_equal 2050, time.year - end + def test_date_select_should_not_change_passed_options_hash + @post = Post.new + @post.updated_at = Time.local(2008, 7, 16, 23, 30) + + options = { + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + } + date_select(@post, :updated_at, options) + + # note: the literal hash is intentional to show that the actual options hash isn't modified + # don't change this! + assert_equal({ + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + }, options) + end + + def test_datetime_select_should_not_change_passed_options_hash + @post = Post.new + @post.updated_at = Time.local(2008, 7, 16, 23, 30) + + options = { + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + } + datetime_select(@post, :updated_at, options) + + # note: the literal hash is intentional to show that the actual options hash isn't modified + # don't change this! + assert_equal({ + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + }, options) + end + + def test_time_select_should_not_change_passed_options_hash + @post = Post.new + @post.updated_at = Time.local(2008, 7, 16, 23, 30) + + options = { + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + } + time_select(@post, :updated_at, options) + + # note: the literal hash is intentional to show that the actual options hash isn't modified + # don't change this! + assert_equal({ + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + }, options) + end + + def test_select_date_should_not_change_passed_options_hash + options = { + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + } + select_date(Date.today, options) + + # note: the literal hash is intentional to show that the actual options hash isn't modified + # don't change this! + assert_equal({ + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + }, options) + end + + def test_select_datetime_should_not_change_passed_options_hash + options = { + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + } + select_datetime(Time.now, options) + + # note: the literal hash is intentional to show that the actual options hash isn't modified + # don't change this! + assert_equal({ + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + }, options) + end + + def test_select_time_should_not_change_passed_options_hash + options = { + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + } + select_time(Time.now, options) + + # note: the literal hash is intentional to show that the actual options hash isn't modified + # don't change this! + assert_equal({ + :order => [ :year, :month, :day ], + :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, + :discard_type => false, + :include_blank => false, + :ignore_date => false, + :include_seconds => true + }, options) end - + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz yield ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') - end + end end diff --git a/actionpack/test/template/form_country_helper_test.rb b/actionpack/test/template/form_country_helper_test.rb new file mode 100644 index 0000000000..8862e08222 --- /dev/null +++ b/actionpack/test/template/form_country_helper_test.rb @@ -0,0 +1,1549 @@ +require 'abstract_unit' + +class FormCountryHelperTest < ActionView::TestCase + tests ActionView::Helpers::FormCountryHelper + + silence_warnings do + Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin) + end + + def test_country_select + @post = Post.new + @post.origin = "Denmark" + 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 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 selected="selected" 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 + assert_dom_equal(expected_select[0..-2], country_select("post", "origin")) + end + + def test_country_select_with_priority_countries + @post = Post.new + @post.origin = "Denmark" + expected_select = <<-COUNTRIES +<select id="post_origin" name="post[origin]"><option value="New Zealand">New Zealand</option> +<option value="Nicaragua">Nicaragua</option><option value="" disabled="disabled">-------------</option> +<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 selected="selected" 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 + assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) + end + + def test_country_select_with_selected_priority_country + @post = Post.new + @post.origin = "New Zealand" + expected_select = <<-COUNTRIES +<select id="post_origin" name="post[origin]"><option selected="selected" value="New Zealand">New Zealand</option> +<option value="Nicaragua">Nicaragua</option><option value="" disabled="disabled">-------------</option> +<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 selected="selected" 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 + 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 + +end
\ No newline at end of file diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 39649c3622..52e8bf376a 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -6,7 +6,7 @@ silence_warnings do alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast) alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast) alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast) - alias_method :secret?, :secret + alias_method :secret?, :secret def new_record=(boolean) @new_record = boolean @@ -22,6 +22,7 @@ silence_warnings do attr_reader :post_id def save; @id = 1; @post_id = 1 end def new_record?; @id.nil? end + def to_param; @id; end def name @id.nil? ? 'new comment' : "comment ##{@id}" end @@ -30,7 +31,6 @@ end class Comment::Nested < Comment; end - class FormHelperTest < ActionView::TestCase tests ActionView::Helpers::FormHelper @@ -447,6 +447,117 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_nested_collections + form_for('post[]', @post) do |f| + concat f.text_field(:title) + f.fields_for('comment[]', @comment) do |c| + concat c.text_field(:name) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" + + "<input name='post[123][comment][][name]' size='30' type='text' id='post_123_comment__name' value='new comment' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index + form_for('post', @post, :index => 1) do |c| + concat c.text_field(:title) + c.fields_for('comment', @comment, :index => 1) do |r| + concat r.text_field(:name) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />" + + "<input name='post[1][comment][1][name]' size='30' type='text' id='post_1_comment_1_name' value='new comment' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index + form_for(:post, @post, :index => 1) do |f| + f.fields_for(:comment, @post) do |c| + concat c.text_field(:title) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[1][comment][title]' size='30' type='text' id='post_1_comment_title' value='Hello World' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index_on_both + form_for(:post, @post, :index => 1) do |f| + f.fields_for(:comment, @post, :index => 5) do |c| + concat c.text_field(:title) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[1][comment][5][title]' size='30' type='text' id='post_1_comment_5_title' value='Hello World' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_auto_index + form_for("post[]", @post) do |f| + f.fields_for(:comment, @post) do |c| + concat c.text_field(:title) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[123][comment][title]' size='30' type='text' id='post_123_comment_title' value='Hello World' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_auto_index_on_both + form_for("post[]", @post) do |f| + f.fields_for("comment[]", @post) do |c| + concat c.text_field(:title) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[123][comment][123][title]' size='30' type='text' id='post_123_comment_123_title' value='Hello World' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index_and_auto_index + form_for("post[]", @post) do |f| + f.fields_for(:comment, @post, :index => 5) do |c| + concat c.text_field(:title) + end + end + + form_for(:post, @post, :index => 1) do |f| + f.fields_for("comment[]", @post) do |c| + concat c.text_field(:title) + end + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='post[123][comment][5][title]' size='30' type='text' id='post_123_comment_5_title' value='Hello World' />" + + "</form>" + + "<form action='http://www.example.com' method='post'>" + + "<input name='post[1][comment][123][title]' size='30' type='text' id='post_1_comment_123_title' value='Hello World' />" + + "</form>" + + assert_dom_equal expected, output_buffer + end + def test_fields_for fields_for(:post, @post) do |f| concat f.text_field(:title) @@ -831,7 +942,6 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - protected def comments_path(post) "/posts/#{post.id}/comments" diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 9dd43d7b4f..a33eb85b66 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -472,1545 +472,6 @@ uses_mocha "FormOptionsHelperTest" do assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) end - def test_country_select - @post = Post.new - @post.origin = "Denmark" - 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 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 selected="selected" 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 - assert_dom_equal(expected_select[0..-2], country_select("post", "origin")) - end - - def test_country_select_with_priority_countries - @post = Post.new - @post.origin = "Denmark" - expected_select = <<-COUNTRIES -<select id="post_origin" name="post[origin]"><option value="New Zealand">New Zealand</option> -<option value="Nicaragua">Nicaragua</option><option value="" disabled="disabled">-------------</option> -<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 selected="selected" 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 - assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) - end - - def test_country_select_with_selected_priority_country - @post = Post.new - @post.origin = "New Zealand" - expected_select = <<-COUNTRIES -<select id="post_origin" name="post[origin]"><option selected="selected" value="New Zealand">New Zealand</option> -<option value="Nicaragua">Nicaragua</option><option value="" disabled="disabled">-------------</option> -<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 selected="selected" 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 - 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" ) diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 4e4102aec7..9b41ff8179 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -190,6 +190,12 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_label_tag_with_symbol + actual = label_tag :title + expected = %(<label for="title">Title</label>) + assert_dom_equal expected, actual + end + def test_label_tag_with_text actual = label_tag "title", "My Title" expected = %(<label for="title">My Title</label>) diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index b2c4a130c8..d41111127b 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -3,6 +3,12 @@ require 'abstract_unit' class JavaScriptHelperTest < ActionView::TestCase tests ActionView::Helpers::JavaScriptHelper + attr_accessor :template_format, :output_buffer + + def setup + @template = self + end + def test_escape_javascript assert_equal '', escape_javascript(nil) assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb new file mode 100644 index 0000000000..2ee7f43a65 --- /dev/null +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -0,0 +1,54 @@ +require 'abstract_unit' + +class NumberHelperI18nTests < Test::Unit::TestCase + include ActionView::Helpers::NumberHelper + + attr_reader :request + + uses_mocha 'number_helper_i18n_tests' do + def setup + @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' } + @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 } + @human_defaults = { :precision => 1 } + @percentage_defaults = { :delimiter => '' } + @precision_defaults = { :delimiter => '' } + + I18n.backend.store_translations 'en-US', :number => { :format => @number_defaults, + :currency => { :format => @currency_defaults }, :human => @human_defaults } + end + + def test_number_to_currency_translates_currency_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.currency.format', :locale => 'en-US', + :raise => true).returns(@currency_defaults) + number_to_currency(1, :locale => 'en-US') + end + + def test_number_with_precision_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.precision.format', :locale => 'en-US', + :raise => true).returns(@precision_defaults) + number_with_precision(1, :locale => 'en-US') + end + + def test_number_with_delimiter_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + number_with_delimiter(1, :locale => 'en-US') + end + + def test_number_to_percentage_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en-US', + :raise => true).returns(@percentage_defaults) + number_to_percentage(1, :locale => 'en-US') + end + + def test_number_to_human_size_translates_human_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.human.format', :locale => 'en-US', + :raise => true).returns(@human_defaults) + # can't be called with 1 because this directly returns without calling I18n.translate + number_to_human_size(1025, :locale => 'en-US') + end + end +end diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 4a8d09b544..9c9f54936c 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -26,7 +26,8 @@ class NumberHelperTest < ActionView::TestCase assert_equal("£1234567890,50", number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""})) assert_equal("$1,234,567,890.50", number_to_currency("1234567890.50")) assert_equal("1,234,567,890.50 Kč", number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"})) - assert_equal("$x.", number_to_currency("x")) + #assert_equal("$x.", number_to_currency("x")) # fails due to API consolidation + assert_equal("$x", number_to_currency("x")) assert_nil number_to_currency(nil) end @@ -35,7 +36,9 @@ class NumberHelperTest < ActionView::TestCase assert_equal("100%", number_to_percentage(100, {:precision => 0})) assert_equal("302.06%", number_to_percentage(302.0574, {:precision => 2})) assert_equal("100.000%", number_to_percentage("100")) + assert_equal("1000.000%", number_to_percentage("1000")) assert_equal("x%", number_to_percentage("x")) + assert_equal("1.000,000%", number_to_percentage(1000, :delimiter => '.', :separator => ',')) assert_nil number_to_percentage(nil) end @@ -54,21 +57,33 @@ class NumberHelperTest < ActionView::TestCase assert_nil number_with_delimiter(nil) end + def test_number_with_delimiter_with_options_hash + assert_equal '12 345 678', number_with_delimiter(12345678, :delimiter => ' ') + assert_equal '12,345,678-05', number_with_delimiter(12345678.05, :separator => '-') + assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :separator => ',', :delimiter => '.') + assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',') + end + def test_number_with_precision assert_equal("111.235", number_with_precision(111.2346)) - assert_equal("31.83", number_with_precision(31.825, 2)) - assert_equal("111.23", number_with_precision(111.2346, 2)) - assert_equal("111.00", number_with_precision(111, 2)) + assert_equal("31.83", number_with_precision(31.825, :precision => 2)) + assert_equal("111.23", number_with_precision(111.2346, :precision => 2)) + assert_equal("111.00", number_with_precision(111, :precision => 2)) assert_equal("111.235", number_with_precision("111.2346")) - assert_equal("31.83", number_with_precision("31.825", 2)) - assert_equal("112", number_with_precision(111.50, 0)) - assert_equal("1234567892", number_with_precision(1234567891.50, 0)) + assert_equal("31.83", number_with_precision("31.825", :precision => 2)) + assert_equal("112", number_with_precision(111.50, :precision => 0)) + assert_equal("1234567892", number_with_precision(1234567891.50, :precision => 0)) # Return non-numeric params unchanged. assert_equal("x", number_with_precision("x")) assert_nil number_with_precision(nil) end + def test_number_with_precision_with_custom_delimiter_and_separator + assert_equal '31,83', number_with_precision(31.825, :precision => 2, :separator => ',') + assert_equal '1.231,83', number_with_precision(1231.825, :precision => 2, :separator => ',', :delimiter => '.') + end + def test_number_to_human_size assert_equal '0 Bytes', number_to_human_size(0) assert_equal '1 Byte', number_to_human_size(1) @@ -80,18 +95,33 @@ class NumberHelperTest < ActionView::TestCase assert_equal '1.2 MB', number_to_human_size(1234567) assert_equal '1.1 GB', number_to_human_size(1234567890) assert_equal '1.1 TB', number_to_human_size(1234567890123) + assert_equal '1025 TB', number_to_human_size(1025.terabytes) assert_equal '444 KB', number_to_human_size(444.kilobytes) assert_equal '1023 MB', number_to_human_size(1023.megabytes) assert_equal '3 TB', number_to_human_size(3.terabytes) - assert_equal '1.18 MB', number_to_human_size(1234567, 2) - assert_equal '3 Bytes', number_to_human_size(3.14159265, 4) + assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2) + assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4) assert_equal("123 Bytes", number_to_human_size("123")) - assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, 2) - assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4) - assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4) + assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2) + assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4) + assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4) assert_equal '1 Byte', number_to_human_size(1.1) assert_equal '10 Bytes', number_to_human_size(10) - assert_nil number_to_human_size('x') + #assert_nil number_to_human_size('x') # fails due to API consolidation assert_nil number_to_human_size(nil) end + + def test_number_to_human_size_with_options_hash + assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2) + assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4) + assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2) + assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4) + assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4) + end + + def test_number_to_human_size_with_custom_delimiter_and_separator + assert_equal '1,01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2, :separator => ',') + assert_equal '1,01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4, :separator => ',') + assert_equal '1.000,1 TB', number_to_human_size(1000.1.terabytes, :delimiter => '.', :separator => ',') + end end diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 1d9bc5eb9b..abc9f930dd 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -25,10 +25,10 @@ class Author::Nested < Author; end class PrototypeHelperBaseTest < ActionView::TestCase - attr_accessor :template_format + attr_accessor :template_format, :output_buffer def setup - @template = nil + @template = self @controller = Class.new do def url_for(options) if options.is_a?(String) @@ -77,6 +77,8 @@ class PrototypeHelperTest < PrototypeHelperBaseTest link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot" }) assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>), link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) + assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:false, evalScripts:true}); return false;\">Remote outauthor</a>), + link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :type => :synchronous) end def test_link_to_remote_html_options @@ -243,8 +245,12 @@ class PrototypeHelperTest < PrototypeHelperBaseTest end def test_update_page + old_output_buffer = output_buffer + block = Proc.new { |page| page.replace_html('foo', 'bar') } assert_equal create_generator(&block).to_s, update_page(&block) + + assert_equal old_output_buffer, output_buffer end def test_update_page_tag @@ -283,13 +289,13 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest end def test_insert_html_with_string - assert_equal 'new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");', + assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });', @generator.insert_html(:top, 'element', '<p>This is a test</p>') - assert_equal 'new Insertion.Bottom("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");', + assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', @generator.insert_html(:bottom, 'element', '<p>This is a test</p>') - assert_equal 'new Insertion.Before("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");', + assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', @generator.insert_html(:before, 'element', '<p>This is a test</p>') - assert_equal 'new Insertion.After("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");', + assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', @generator.insert_html(:after, 'element', '<p>This is a test</p>') end @@ -362,8 +368,8 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest @generator.replace_html('baz', '<p>This is a test</p>') assert_equal <<-EOS.chomp, @generator.to_s -new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); -new Insertion.Bottom("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); +Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" }); +Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" }); ["foo", "bar"].each(Element.remove); Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); EOS @@ -425,6 +431,8 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); def test_sortable assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});), @generator.sortable('blah', :url => { :action => "order" }) + assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:Sortable.serialize("blah")})}});), + @generator.sortable('blah', :url => { :action => "order" }, :type => :synchronous) end def test_draggable @@ -435,6 +443,8 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); def test_drop_receiving assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});), @generator.drop_receiving('blah', :url => { :action => "order" }) + assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});), + @generator.drop_receiving('blah', :url => { :action => "order" }, :type => :synchronous) end def test_collection_first_and_last diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index cc5b4900dc..f3c8dbcae9 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -19,6 +19,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "Hello world!", @view.render("test/hello_world") end + def test_render_file_at_top_level + assert_equal 'Elastica', @view.render('/shared') + end + def test_render_file_with_full_path template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world.erb') assert_equal "Hello world!", @view.render(:file => template_path) @@ -47,6 +51,24 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "only partial", @view.render(:partial => "test/partial_only") end + def test_render_partial_with_format + assert_equal 'partial html', @view.render(:partial => 'test/partial') + end + + def test_render_partial_at_top_level + # file fixtures/_top_level_partial_only.erb (not fixtures/test) + assert_equal 'top level partial', @view.render(:partial => '/top_level_partial_only') + end + + def test_render_partial_with_format_at_top_level + # file fixtures/_top_level_partial.html.erb (not fixtures/test, with format extension) + assert_equal 'top level partial html', @view.render(:partial => '/top_level_partial') + end + + def test_render_partial_with_locals + assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 }) + end + def test_render_partial_with_errors assert_raise(ActionView::TemplateError) { @view.render(:partial => "test/raise") } end @@ -54,17 +76,29 @@ class ViewRenderTest < Test::Unit::TestCase def test_render_partial_collection assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) end - + def test_render_partial_collection_as - assert_equal "david david davidmary mary mary", + assert_equal "david david davidmary mary mary", @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer) end - + def test_render_partial_collection_without_as - assert_equal "local_inspector,local_inspector_counter,object", + assert_equal "local_inspector,local_inspector_counter,object", @view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ]) end + def test_render_partial_with_empty_collection_should_return_nil + assert_nil @view.render(:partial => "test/customer", :collection => []) + end + + def test_render_partial_with_nil_collection_should_return_nil + assert_nil @view.render(:partial => "test/customer", :collection => nil) + end + + def test_render_partial_with_empty_array_should_return_nil + assert_nil @view.render(:partial => []) + end + # TODO: The reason for this test is unclear, improve documentation def test_render_partial_and_fallback_to_layout assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) @@ -94,38 +128,18 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo) end - class CustomHandler < ActionView::TemplateHandler - def render(template, local_assigns) - [template.source, local_assigns].inspect - end - end - - def test_render_inline_with_custom_type - ActionView::Template.register_template_handler :foo, CustomHandler - assert_equal '["Hello, World!", {}]', @view.render(:inline => "Hello, World!", :type => :foo) - end - - def test_render_inline_with_locals_and_custom_type - ActionView::Template.register_template_handler :foo, CustomHandler - assert_equal '["Hello, <%= name %>!", {:name=>"Josh"}]', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) - end - - class CompilableCustomHandler < ActionView::TemplateHandler - include ActionView::TemplateHandlers::Compilable - - def compile(template) - "@output_buffer = ''\n" + - "@output_buffer << 'source: #{template.source.inspect}'\n" - end + CustomHandler = lambda do |template| + "@output_buffer = ''\n" + + "@output_buffer << 'source: #{template.source.inspect}'\n" end def test_render_inline_with_compilable_custom_type - ActionView::Template.register_template_handler :foo, CompilableCustomHandler + ActionView::Template.register_template_handler :foo, CustomHandler 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 + ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end end diff --git a/actionpack/test/template/sanitize_helper_test.rb b/actionpack/test/template/sanitize_helper_test.rb index e5427d9dc1..f715071bbc 100644 --- a/actionpack/test/template/sanitize_helper_test.rb +++ b/actionpack/test/template/sanitize_helper_test.rb @@ -11,9 +11,9 @@ class SanitizeHelperTest < ActionView::TestCase assert_equal "Dont touch me", strip_links("Dont touch me") assert_equal "<a<a", strip_links("<a<a") assert_equal "on my mind\nall day long", strip_links("<a href='almost'>on my mind</a>\n<A href='almost'>all day long</A>") - assert_equal "0wn3d", strip_links("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>") - assert_equal "Magic", strip_links("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic") - assert_equal "FrrFox", strip_links("<href onlclick='steal()'>FrrFox</a></href>") + assert_equal "0wn3d", strip_links("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>") + assert_equal "Magic", strip_links("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic") + assert_equal "FrrFox", strip_links("<href onlclick='steal()'>FrrFox</a></href>") assert_equal "My mind\nall <b>day</b> long", strip_links("<a href='almost'>My mind</a>\n<A href='almost'>all <b>day</b> long</A>") assert_equal "all <b>day</b> long", strip_links("<<a>a href='hello'>all <b>day</b> long<</A>/a>") end diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 4999525939..a31d532567 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -35,8 +35,8 @@ class TextHelperTest < ActionView::TestCase end def test_truncate - assert_equal "Hello World!", truncate("Hello World!", 12) - assert_equal "Hello Wor...", truncate("Hello World!!", 12) + assert_equal "Hello World!", truncate("Hello World!", :length => 12) + assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12) end def test_truncate_should_use_default_length_of_30 @@ -44,23 +44,29 @@ class TextHelperTest < ActionView::TestCase assert_equal str[0...27] + "...", truncate(str) end + def test_truncate_with_options_hash + assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]") + assert_equal "Hello W...", truncate("Hello World!", :length => 10) + assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10) + end + if RUBY_VERSION < '1.9.0' def test_truncate_multibyte with_kcode 'none' do - assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10) + assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) end with_kcode 'u' do assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...", - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", 10) + truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", :length => 10) end end else def test_truncate_multibyte assert_equal "\354\225\210\353\205\225\355...", - truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10) + truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'), - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), 10) + truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10) end end @@ -88,7 +94,7 @@ class TextHelperTest < ActionView::TestCase assert_equal ' ', highlight(' ', 'blank text is returned verbatim') end - def test_highlighter_with_regexp + def test_highlight_with_regexp assert_equal( "This is a <strong class=\"highlight\">beautiful!</strong> morning", highlight("This is a beautiful! morning", "beautiful!") @@ -105,10 +111,17 @@ class TextHelperTest < ActionView::TestCase ) end - def test_highlighting_multiple_phrases_in_one_pass + def test_highlight_with_multiple_phrases_in_one_pass assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), '<em>\1</em>') end + def test_highlight_with_options_hash + assert_equal( + "This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day", + highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '<b>\1</b>') + ) + end + def test_excerpt assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5)) assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5)) @@ -138,6 +151,16 @@ class TextHelperTest < ActionView::TestCase assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5)) end + def test_excerpt_with_options_hash + assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5)) + assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5)) + assert_equal( + "This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]", + excerpt("This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome temperatures. So what are you gonna do about it?", "very", + :omission => "[...]") + ) + end + if RUBY_VERSION < '1.9' def test_excerpt_with_utf8 with_kcode('u') do @@ -162,6 +185,10 @@ class TextHelperTest < ActionView::TestCase assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15)) end + def test_word_wrap_with_options_hash + assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15)) + end + def test_pluralization assert_equal("1 count", pluralize(1, "count")) assert_equal("2 counts", pluralize(2, "count")) @@ -285,7 +312,13 @@ class TextHelperTest < ActionView::TestCase url = "http://api.rubyonrails.com/Foo.html" email = "fantabulous@shiznadel.ic" - assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, 10) } + assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, :length => 10) } + end + + def test_auto_link_with_options_hash + assert_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com">me@email.com</a>.', + auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.", + :link => :all, :html => { :class => "menu", :target => "_blank" }) end def test_cycle_class diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb new file mode 100644 index 0000000000..7b94221ec0 --- /dev/null +++ b/actionpack/test/template/translation_helper_test.rb @@ -0,0 +1,28 @@ +require 'abstract_unit' + +class TranslationHelperTest < Test::Unit::TestCase + include ActionView::Helpers::TagHelper + include ActionView::Helpers::TranslationHelper + + attr_reader :request + uses_mocha 'translation_helper_test' do + def setup + end + + def test_delegates_to_i18n_setting_the_raise_option + I18n.expects(:translate).with(:foo, 'en-US', :raise => true) + translate :foo, 'en-US' + end + + def test_returns_missing_translation_message_wrapped_into_span + expected = '<span class="translation_missing">en-US, foo</span>' + assert_equal expected, translate(:foo) + end + + def test_delegates_localize_to_i18n + @time = Time.utc(2008, 7, 8, 12, 18, 38) + I18n.expects(:localize).with(@time) + localize @time + end + end +end
\ No newline at end of file diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 91d5c6ffb5..85e967ac1c 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'abstract_unit' RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env) @@ -28,6 +29,16 @@ class UrlHelperTest < ActionView::TestCase assert_equal "http://www.example.com?a=b&c=d", url_for("http://www.example.com?a=b&c=d") end + def test_url_for_with_back + @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'}) + assert_equal 'http://www.example.com/referer', url_for(:back) + end + + def test_url_for_with_back_and_no_referer + @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {}) + assert_equal 'javascript:history.back()', url_for(:back) + end + # todo: missing test cases def test_button_to_with_straight_url assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com") @@ -267,7 +278,11 @@ class UrlHelperTest < ActionView::TestCase end def test_mail_to_with_javascript - 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") + assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript") + end + + def test_mail_to_with_javascript_unicode + assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%3e%c3%ba%6e%69%63%6f%64%65%3c%2f%61%3e%27%29%3b'))</script>", mail_to("unicode@example.com", "Ășnicode", :encode => "javascript") end def test_mail_with_options @@ -291,8 +306,8 @@ class UrlHelperTest < ActionView::TestCase assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain.com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)") 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)") + assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") + assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%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? @@ -419,7 +434,6 @@ class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase end end - class Workshop attr_accessor :id, :new_record |