From bc94061156e52ec45fceec582e8400250cc022fb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 31 Jan 2009 10:56:16 -0800 Subject: Fix unsorted array comparison --- actionpack/test/template/render_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c226e212b5..c7405d47de 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -11,7 +11,7 @@ module RenderTestCases I18n.backend.store_translations 'da', {} # Ensure original are still the same since we are reindexing view paths - assert_equal ORIGINAL_LOCALES, I18n.available_locales + assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort end def test_render_file -- cgit v1.2.3 From ec8f04584479aff895b0b511a7ba1e9d33f84067 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Sun, 1 Feb 2009 14:44:30 +1300 Subject: Add support for nested object forms to ActiveRecord and the helpers in ActionPack Signed-Off-By: Michael Koziarski [#1202 state:committed] --- actionpack/test/template/form_helper_test.rb | 141 ++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 5 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 9454fd7e91..33a542af7e 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -15,21 +15,31 @@ silence_warnings do def new_record? @new_record end + + attr_accessor :author + def author_attributes=(attributes); end + + attr_accessor :comments + def comments_attributes=(attributes); end end class Comment attr_reader :id attr_reader :post_id + def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end 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}" + @id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}" end end -end -class Comment::Nested < Comment; end + class Author < Comment + attr_accessor :post + def post_attributes=(attributes); end + end +end class FormHelperTest < ActionView::TestCase tests ActionView::Helpers::FormHelper @@ -479,7 +489,7 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - def test_nested_fields_for_with_index + def test_form_for_with_index_and_nested_fields_for form_for(:post, @post, :index => 1) do |f| f.fields_for(:comment, @post) do |c| concat c.text_field(:title) @@ -558,6 +568,127 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_a_new_record_on_a_nested_attributes_one_to_one_association + @post.author = Author.new + + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:author) do |af| + concat af.text_field(:name) + end + end + + expected = '
' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association + @post.author = Author.new(321) + + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:author) do |af| + concat af.text_field(:name) + end + end + + expected = '
' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association + @post.comments = Array.new(2) { |id| Comment.new(id + 1) } + + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + f.fields_for(:comments, comment) do |cf| + concat cf.text_field(:name) + end + end + end + + expected = '
' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_new_records_on_a_nested_attributes_collection_association + @post.comments = [Comment.new, Comment.new] + + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + f.fields_for(:comments, comment) do |cf| + concat cf.text_field(:name) + end + end + end + + expected = '
' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_collection_association + @post.comments = [Comment.new(321), Comment.new] + + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + f.fields_for(:comments, comment) do |cf| + concat cf.text_field(:name) + end + end + end + + expected = '
' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_on_a_nested_attributes_collection_association_yields_only_builder + @post.comments = [Comment.new(321), Comment.new] + yielded_comments = [] + + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:comments) do |cf| + concat cf.text_field(:name) + yielded_comments << cf.object + end + end + + expected = '
' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + assert_equal yielded_comments, @post.comments + end + def test_fields_for fields_for(:post, @post) do |f| concat f.text_field(:title) @@ -974,4 +1105,4 @@ class FormHelperTest < ActionView::TestCase def protect_against_forgery? false end -end +end \ No newline at end of file -- cgit v1.2.3 From 278186534c0ccf285a20497461f40d2e54aa20a0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 3 Feb 2009 18:25:37 -0800 Subject: Bump mocha requirement for Ruby 1.9 compat. Remove uses_mocha. --- .../template/active_record_helper_i18n_test.rb | 64 +- actionpack/test/template/asset_tag_helper_test.rb | 26 +- .../test/template/compiled_templates_test.rb | 134 ++- actionpack/test/template/date_helper_i18n_test.rb | 176 ++- actionpack/test/template/date_helper_test.rb | 66 +- .../test/template/form_options_helper_test.rb | 1198 ++++++++++---------- .../test/template/number_helper_i18n_test.rb | 108 +- actionpack/test/template/test_test.rb | 10 +- .../test/template/translation_helper_test.rb | 36 +- 9 files changed, 899 insertions(+), 919 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index 7e6bf70706..4b6e8ddcca 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -4,43 +4,41 @@ 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' + 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', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved" - I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' - end + I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved" + I18n.stubs(:t).with(:'body', :locale => 'en', :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', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never - error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en') - end + def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message + I18n.expects(:translate).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never + error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en') + end - def test_error_messages_for_given_no_header_option_it_translates_header_message - I18n.expects(:t).with(:'header', :locale => 'en', :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') - end + def test_error_messages_for_given_no_header_option_it_translates_header_message + I18n.expects(:t).with(:'header', :locale => 'en', :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') + end - def test_error_messages_for_given_a_message_option_it_does_not_translate_message - I18n.expects(:t).with(:'body', :locale => 'en', :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') - end + def test_error_messages_for_given_a_message_option_it_does_not_translate_message + I18n.expects(:t).with(:'body', :locale => 'en', :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') + end - def test_error_messages_for_given_no_message_option_it_translates_message - I18n.expects(:t).with(:'body', :locale => 'en', :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') - end - - def test_error_messages_for_given_object_name_it_translates_object_name - I18n.expects(:t).with(:header, :locale => 'en', :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', :object_name => @object_name) - end + def test_error_messages_for_given_no_message_option_it_translates_message + I18n.expects(:t).with(:'body', :locale => 'en', :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') + end + + def test_error_messages_for_given_object_name_it_translates_object_name + I18n.expects(:t).with(:header, :locale => 'en', :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', :object_name => @object_name) end end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 5e2fc20167..32ad87c12d 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -228,20 +228,18 @@ class AssetTagHelperTest < ActionView::TestCase ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - uses_mocha 'test image tag with windows behaviour' do - def test_image_tag_windows_behaviour - old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1" - # This simulates the behaviour of File#exist? on windows when testing a file ending in "." - # If the file "rails.png" exists, windows will return true when asked if "rails.png." exists (notice trailing ".") - # OS X, linux etc will return false in this case. - File.stubs(:exist?).with('template/../fixtures/public/images/rails.png.').returns(true) - assert_equal 'Rails', image_tag('rails.png') - ensure - if old_asset_id - ENV["RAILS_ASSET_ID"] = old_asset_id - else - ENV.delete("RAILS_ASSET_ID") - end + def test_image_tag_windows_behaviour + old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1" + # This simulates the behaviour of File#exist? on windows when testing a file ending in "." + # If the file "rails.png" exists, windows will return true when asked if "rails.png." exists (notice trailing ".") + # OS X, linux etc will return false in this case. + File.stubs(:exist?).with('template/../fixtures/public/images/rails.png.').returns(true) + assert_equal 'Rails', image_tag('rails.png') + ensure + if old_asset_id + ENV["RAILS_ASSET_ID"] = old_asset_id + else + ENV.delete("RAILS_ASSET_ID") end end diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index caea1bd643..a7ed13cf57 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -1,87 +1,85 @@ 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 +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(:file => "test/hello_world.erb") - assert_equal 1, @compiled_templates.instance_methods.size - end + def test_template_gets_compiled + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render(:file => "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(:file => "test/hello_world.erb") - assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"}) - assert_equal 2, @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(:file => "test/hello_world.erb") + assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {: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(:file => "test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).never - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - 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(:file => "test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + end - def test_compiled_template_will_always_be_recompiled_when_template_is_not_cached - ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true) - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } - assert_equal 1, @compiled_templates.instance_methods.size - end + def test_compiled_template_will_always_be_recompiled_when_template_is_not_cached + ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true) + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).times(3) + 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + assert_equal 1, @compiled_templates.instance_methods.size + end - def test_template_changes_are_not_reflected_with_cached_templates - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - end + def test_template_changes_are_not_reflected_with_cached_templates + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do assert_equal "Hello world!", render(:file => "test/hello_world.erb") end + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + end - def test_template_changes_are_reflected_with_uncached_templates - assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do - assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world.erb") - end - assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") + def test_template_changes_are_reflected_with_uncached_templates + assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world.erb") end + assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") + end - private - def render(*args) - render_with_cache(*args) - end + private + def render(*args) + render_with_cache(*args) + end - def render_with_cache(*args) - view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::EagerPath, view_paths.first.class - ActionView::Base.new(view_paths, {}).render(*args) - end + def render_with_cache(*args) + view_paths = ActionController::Base.view_paths + assert_equal ActionView::Template::EagerPath, view_paths.first.class + ActionView::Base.new(view_paths, {}).render(*args) + end - def render_without_cache(*args) - path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH) - view_paths = ActionView::Base.process_view_paths(path) - assert_equal ActionView::Template::Path, view_paths.first.class - ActionView::Base.new(view_paths, {}).render(*args) - end + def render_without_cache(*args) + path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH) + view_paths = ActionView::Base.process_view_paths(path) + assert_equal ActionView::Template::Path, view_paths.first.class + ActionView::Base.new(view_paths, {}).render(*args) + end - def modify_template(template, content) - filename = "#{FIXTURE_LOAD_PATH}/#{template}" - old_content = File.read(filename) - begin - File.open(filename, "wb+") { |f| f.write(content) } - yield - ensure - File.open(filename, "wb+") { |f| f.write(old_content) } - end + def modify_template(template, content) + filename = "#{FIXTURE_LOAD_PATH}/#{template}" + old_content = File.read(filename) + begin + File.open(filename, "wb+") { |f| f.write(content) } + yield + ensure + File.open(filename, "wb+") { |f| f.write(old_content) } end - end + end end diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index fac30da128..bc011f59b8 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -8,66 +8,64 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase @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 + # 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 + def assert_distance_of_time_in_words_translates_key(passed, expected) + diff, include_seconds = *passed + key, count = *expected + to = @from + diff - options = {:locale => 'en', :scope => :'datetime.distance_in_words'} - options[:count] = count if count + options = {:locale => 'en', :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') - end + I18n.expects(:t).with(key, options) + distance_of_time_in_words(@from, to, include_seconds, :locale => 'en') + 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 + 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 @@ -76,49 +74,47 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase include ActionView::Helpers::DateHelper attr_reader :request - uses_mocha 'date_helper_select_tags_i18n_tests' do - def setup - @prompt_defaults = {:year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds'} - - I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES - end + def setup + @prompt_defaults = {:year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds'} - # select_month + I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES + end - def test_select_month_given_use_month_names_option_does_not_translate_monthnames - I18n.expects(:translate).never - select_month(8, :locale => 'en', :use_month_names => Date::MONTHNAMES) - end + # select_month - def test_select_month_translates_monthnames - I18n.expects(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES - select_month(8, :locale => 'en') - end + def test_select_month_given_use_month_names_option_does_not_translate_monthnames + I18n.expects(:translate).never + select_month(8, :locale => 'en', :use_month_names => Date::MONTHNAMES) + end - def test_select_month_given_use_short_month_option_translates_abbr_monthnames - I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date::ABBR_MONTHNAMES - select_month(8, :locale => 'en', :use_short_month => true) - end + def test_select_month_translates_monthnames + I18n.expects(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES + select_month(8, :locale => 'en') + end - def test_date_or_time_select_translates_prompts - @prompt_defaults.each do |key, prompt| - I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt - end + def test_select_month_given_use_short_month_option_translates_abbr_monthnames + I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date::ABBR_MONTHNAMES + select_month(8, :locale => 'en', :use_short_month => true) + end - I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day] - datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true) + def test_date_or_time_select_translates_prompts + @prompt_defaults.each do |key, prompt| + I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt end - # date_or_time_select + I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true) + end - 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') - end + # date_or_time_select - def test_date_or_time_select_given_no_order_options_translates_order - I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day] - datetime_select('post', 'updated_at', :locale => 'en') - end + 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') + end + + def test_date_or_time_select_given_no_order_options_translates_order + I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en') end -end \ No newline at end of file +end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 92cdce2e45..59e921f09b 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1726,40 +1726,38 @@ 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) - time_zone = mock() - time_zone.expects(:now).returns time - Time.zone_default = time_zone - @post = Post.new - - expected = %{\n" - - expected << %{\n" - - expected << %{\n" - - expected << " — " - - expected << %{\n" - expected << " : " - expected << %{\n" - - assert_dom_equal expected, datetime_select("post", "updated_at") - ensure - Time.zone_default = nil - end + 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) + time_zone = mock() + time_zone.expects(:now).returns time + Time.zone_default = time_zone + @post = Post.new + + expected = %{\n" + + expected << %{\n" + + expected << %{\n" + + expected << " — " + + expected << %{\n" + expected << " : " + expected << %{\n" + + assert_dom_equal expected, datetime_select("post", "updated_at") + ensure + Time.zone_default = nil end def test_datetime_select_with_html_options_within_fields_for diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 86b321e6e5..83c27ac042 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -3,42 +3,54 @@ require 'tzinfo' TZInfo::Timezone.cattr_reader :loaded_zones -uses_mocha "FormOptionsHelperTest" do - class FormOptionsHelperTest < ActionView::TestCase - tests ActionView::Helpers::FormOptionsHelper - - silence_warnings do - Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin) - Continent = Struct.new('Continent', :continent_name, :countries) - Country = Struct.new('Country', :country_id, :country_name) - Firm = Struct.new('Firm', :time_zone) - Album = Struct.new('Album', :id, :title, :genre) - end +class FormOptionsHelperTest < ActionView::TestCase + tests ActionView::Helpers::FormOptionsHelper + + silence_warnings do + Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin) + Continent = Struct.new('Continent', :continent_name, :countries) + Country = Struct.new('Country', :country_id, :country_name) + Firm = Struct.new('Firm', :time_zone) + Album = Struct.new('Album', :id, :title, :genre) + end - def setup - @fake_timezones = %w(A B C D E).inject([]) do |zones, id| - tz = TZInfo::Timezone.loaded_zones[id] = stub(:name => id, :to_s => id) - ActiveSupport::TimeZone.stubs(:[]).with(id).returns(tz) - zones << tz - end - ActiveSupport::TimeZone.stubs(:all).returns(@fake_timezones) + def setup + @fake_timezones = %w(A B C D E).inject([]) do |zones, id| + tz = TZInfo::Timezone.loaded_zones[id] = stub(:name => id, :to_s => id) + ActiveSupport::TimeZone.stubs(:[]).with(id).returns(tz) + zones << tz end + ActiveSupport::TimeZone.stubs(:all).returns(@fake_timezones) + end - def test_collection_options - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + def test_collection_options + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] + + assert_dom_equal( + "\n\n", + options_from_collection_for_select(@posts, "author_name", "title") + ) + end - assert_dom_equal( - "\n\n", - options_from_collection_for_select(@posts, "author_name", "title") - ) - end + def test_collection_options_with_preselected_value + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - def test_collection_options_with_preselected_value + assert_dom_equal( + "\n\n", + options_from_collection_for_select(@posts, "author_name", "title", "Babe") + ) + end + + def test_collection_options_with_preselected_value_array @posts = [ Post.new(" went home", "", "To a little house", "shh!"), Post.new("Babe went home", "Babe", "To a little house", "shh!"), @@ -46,683 +58,669 @@ uses_mocha "FormOptionsHelperTest" do ] assert_dom_equal( - "\n\n", - options_from_collection_for_select(@posts, "author_name", "title", "Babe") + "\n\n", + options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ]) ) - end + end - def test_collection_options_with_preselected_value_array - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - - assert_dom_equal( - "\n\n", - options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ]) - ) - end + def test_array_options_for_select + assert_dom_equal( + "\n\n", + options_for_select([ "", "USA", "Sweden" ]) + ) + end - def test_array_options_for_select - assert_dom_equal( - "\n\n", - options_for_select([ "", "USA", "Sweden" ]) - ) - end + def test_array_options_for_select_with_selection + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], "") + ) + end - def test_array_options_for_select_with_selection + def test_array_options_for_select_with_selection_array assert_dom_equal( - "\n\n", - options_for_select([ "Denmark", "", "Sweden" ], "") + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], [ "", "Sweden" ]) ) - end - - def test_array_options_for_select_with_selection_array - assert_dom_equal( - "\n\n", - options_for_select([ "Denmark", "", "Sweden" ], [ "", "Sweden" ]) - ) - end - - def test_array_options_for_string_include_in_other_string_bug_fix - assert_dom_equal( - "\n", - options_for_select([ "ruby", "rubyonrails" ], "rubyonrails") - ) - assert_dom_equal( - "\n", - options_for_select([ "ruby", "rubyonrails" ], "ruby") - ) - assert_dom_equal( - %(\n\n), - options_for_select([ "ruby", "rubyonrails", nil ], "ruby") - ) - end + end - def test_hash_options_for_select + def test_array_options_for_string_include_in_other_string_bug_fix assert_dom_equal( - "\n", - options_for_select("$" => "Dollar", "" => "").split("\n").sort.join("\n") + "\n", + options_for_select([ "ruby", "rubyonrails" ], "rubyonrails") ) assert_dom_equal( - "\n", - options_for_select({ "$" => "Dollar", "" => "" }, "Dollar").split("\n").sort.join("\n") + "\n", + options_for_select([ "ruby", "rubyonrails" ], "ruby") ) assert_dom_equal( - "\n", - options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]).split("\n").sort.join("\n") + %(\n\n), + options_for_select([ "ruby", "rubyonrails", nil ], "ruby") ) - end + end - def test_ducktyped_options_for_select - quack = Struct.new(:first, :last) - assert_dom_equal( - "\n", - options_for_select([quack.new("", ""), quack.new("$", "Dollar")]) - ) - assert_dom_equal( - "\n", - options_for_select([quack.new("", ""), quack.new("$", "Dollar")], "Dollar") - ) - assert_dom_equal( - "\n", - options_for_select([quack.new("", ""), quack.new("$", "Dollar")], ["Dollar", ""]) - ) - end + def test_hash_options_for_select + assert_dom_equal( + "\n", + options_for_select("$" => "Dollar", "" => "").split("\n").sort.join("\n") + ) + assert_dom_equal( + "\n", + options_for_select({ "$" => "Dollar", "" => "" }, "Dollar").split("\n").sort.join("\n") + ) + assert_dom_equal( + "\n", + options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]).split("\n").sort.join("\n") + ) + end - def test_option_groups_from_collection_for_select - @continents = [ - Continent.new("", [Country.new("", ""), Country.new("so", "Somalia")] ), - Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] ) - ] + def test_ducktyped_options_for_select + quack = Struct.new(:first, :last) + assert_dom_equal( + "\n", + options_for_select([quack.new("", ""), quack.new("$", "Dollar")]) + ) + assert_dom_equal( + "\n", + options_for_select([quack.new("", ""), quack.new("$", "Dollar")], "Dollar") + ) + assert_dom_equal( + "\n", + options_for_select([quack.new("", ""), quack.new("$", "Dollar")], ["Dollar", ""]) + ) + end - assert_dom_equal( - "\n\n", - option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk") - ) - end + def test_option_groups_from_collection_for_select + @continents = [ + Continent.new("", [Country.new("", ""), Country.new("so", "Somalia")] ), + Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] ) + ] - def test_grouped_options_for_select_with_array - assert_dom_equal( - "\n\n", - grouped_options_for_select([ - ["North America", - [['United States','US'],"Canada"]], - ["Europe", - [["Great Britain","GB"], "Germany"]] - ]) - ) - end + assert_dom_equal( + "\n\n", + option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk") + ) + end - def test_grouped_options_for_select_with_selected_and_prompt - assert_dom_equal( - "\n", - grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], "Cowboy Hat", "Choose a product...") - ) - end + def test_grouped_options_for_select_with_array + assert_dom_equal( + "\n\n", + grouped_options_for_select([ + ["North America", + [['United States','US'],"Canada"]], + ["Europe", + [["Great Britain","GB"], "Germany"]] + ]) + ) + end - def test_optgroups_with_with_options_with_hash - assert_dom_equal( - "\n\n", - grouped_options_for_select({'North America' => ['United States','Canada'], 'Europe' => ['Denmark','Germany']}) - ) - end + def test_grouped_options_for_select_with_selected_and_prompt + assert_dom_equal( + "\n", + grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], "Cowboy Hat", "Choose a product...") + ) + end - def test_time_zone_options_no_parms - opts = time_zone_options_for_select - assert_dom_equal "\n" + - "\n" + - "\n" + - "\n" + - "", - opts - end + def test_optgroups_with_with_options_with_hash + assert_dom_equal( + "\n\n", + grouped_options_for_select({'North America' => ['United States','Canada'], 'Europe' => ['Denmark','Germany']}) + ) + end - def test_time_zone_options_with_selected - opts = time_zone_options_for_select( "D" ) - assert_dom_equal "\n" + - "\n" + - "\n" + - "\n" + - "", - opts - end + def test_time_zone_options_no_parms + opts = time_zone_options_for_select + assert_dom_equal "\n" + + "\n" + + "\n" + + "\n" + + "", + opts + end - def test_time_zone_options_with_unknown_selected - opts = time_zone_options_for_select( "K" ) - assert_dom_equal "\n" + - "\n" + - "\n" + - "\n" + - "", - opts - end + def test_time_zone_options_with_selected + opts = time_zone_options_for_select( "D" ) + assert_dom_equal "\n" + + "\n" + + "\n" + + "\n" + + "", + opts + end - def test_time_zone_options_with_priority_zones - zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] - opts = time_zone_options_for_select( nil, zones ) - assert_dom_equal "\n" + - "" + - "\n" + - "\n" + - "\n" + - "", - opts - end + def test_time_zone_options_with_unknown_selected + opts = time_zone_options_for_select( "K" ) + assert_dom_equal "\n" + + "\n" + + "\n" + + "\n" + + "", + opts + end - def test_time_zone_options_with_selected_priority_zones - zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] - opts = time_zone_options_for_select( "E", zones ) - assert_dom_equal "\n" + - "" + - "\n" + - "\n" + - "\n" + - "", - opts - end + def test_time_zone_options_with_priority_zones + zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( nil, zones ) + assert_dom_equal "\n" + + "" + + "\n" + + "\n" + + "\n" + + "", + opts + end - def test_time_zone_options_with_unselected_priority_zones - zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] - opts = time_zone_options_for_select( "C", zones ) - assert_dom_equal "\n" + - "" + - "\n" + - "\n" + - "\n" + - "", - opts - end + def test_time_zone_options_with_selected_priority_zones + zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( "E", zones ) + assert_dom_equal "\n" + + "" + + "\n" + + "\n" + + "\n" + + "", + opts + end - def test_select - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest)) - ) - end + def test_time_zone_options_with_unselected_priority_zones + zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( "C", zones ) + assert_dom_equal "\n" + + "" + + "\n" + + "\n" + + "\n" + + "", + opts + end - def test_select_under_fields_for - @post = Post.new - @post.category = "" + def test_select + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest)) + ) + end - fields_for :post, @post do |f| - concat f.select(:category, %w( abe hest)) - end - - assert_dom_equal( - "", - output_buffer - ) - end + def test_select_under_fields_for + @post = Post.new + @post.category = "" - def test_select_under_fields_for_with_index - @post = Post.new - @post.category = "" + fields_for :post, @post do |f| + concat f.select(:category, %w( abe hest)) + end + + assert_dom_equal( + "", + output_buffer + ) + end - fields_for :post, @post, :index => 108 do |f| - concat f.select(:category, %w( abe hest)) - end + def test_select_under_fields_for_with_index + @post = Post.new + @post.category = "" - assert_dom_equal( - "", - output_buffer - ) + fields_for :post, @post, :index => 108 do |f| + concat f.select(:category, %w( abe hest)) end - def test_select_under_fields_for_with_auto_index - @post = Post.new - @post.category = "" - def @post.to_param; 108; end + assert_dom_equal( + "", + output_buffer + ) + end - fields_for "post[]", @post do |f| - concat f.select(:category, %w( abe hest)) - end + def test_select_under_fields_for_with_auto_index + @post = Post.new + @post.category = "" + def @post.to_param; 108; end - assert_dom_equal( - "", - output_buffer - ) + fields_for "post[]", @post do |f| + concat f.select(:category, %w( abe hest)) end - def test_select_with_blank - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest), :include_blank => true) - ) - end + assert_dom_equal( + "", + output_buffer + ) + end - def test_select_with_blank_as_string - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest), :include_blank => 'None') - ) - end + def test_select_with_blank + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest), :include_blank => true) + ) + end - def test_select_with_default_prompt - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest), :prompt => true) - ) - end + def test_select_with_blank_as_string + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest), :include_blank => 'None') + ) + end - def test_select_no_prompt_when_select_has_value - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest), :prompt => true) - ) - end + def test_select_with_default_prompt + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest), :prompt => true) + ) + end - def test_select_with_given_prompt - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest), :prompt => 'The prompt') - ) - end + def test_select_no_prompt_when_select_has_value + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest), :prompt => true) + ) + end - def test_select_with_prompt_and_blank - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest), :prompt => true, :include_blank => true) - ) - end + def test_select_with_given_prompt + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest), :prompt => 'The prompt') + ) + end - def test_select_with_selected_value - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest ), :selected => 'abe') - ) - end + def test_select_with_prompt_and_blank + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest), :prompt => true, :include_blank => true) + ) + end + + def test_select_with_selected_value + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest ), :selected => 'abe') + ) + end + + def test_select_with_index_option + @album = Album.new + @album.id = 1 - def test_select_with_index_option - @album = Album.new - @album.id = 1 - - expected = "" + expected = "" - assert_dom_equal( - expected, - select("album[]", "genre", %w[rap rock country], {}, { :index => nil }) - ) - end + assert_dom_equal( + expected, + select("album[]", "genre", %w[rap rock country], {}, { :index => nil }) + ) + end - def test_select_with_selected_nil - @post = Post.new - @post.category = "" - assert_dom_equal( - "", - select("post", "category", %w( abe hest ), :selected => nil) - ) - end + def test_select_with_selected_nil + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest ), :selected => nil) + ) + end - def test_collection_select - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + def test_collection_select + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - @post = Post.new - @post.author_name = "Babe" + @post = Post.new + @post.author_name = "Babe" - assert_dom_equal( - "", - collection_select("post", "author_name", @posts, "author_name", "author_name") - ) - end + assert_dom_equal( + "", + collection_select("post", "author_name", @posts, "author_name", "author_name") + ) + end - def test_collection_select_under_fields_for - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + def test_collection_select_under_fields_for + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - @post = Post.new - @post.author_name = "Babe" + @post = Post.new + @post.author_name = "Babe" - fields_for :post, @post do |f| - concat f.collection_select(:author_name, @posts, :author_name, :author_name) - end - - assert_dom_equal( - "", - output_buffer - ) + fields_for :post, @post do |f| + concat f.collection_select(:author_name, @posts, :author_name, :author_name) end + + assert_dom_equal( + "", + output_buffer + ) + end - def test_collection_select_under_fields_for_with_index - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - - @post = Post.new - @post.author_name = "Babe" + def test_collection_select_under_fields_for_with_index + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - fields_for :post, @post, :index => 815 do |f| - concat f.collection_select(:author_name, @posts, :author_name, :author_name) - end + @post = Post.new + @post.author_name = "Babe" - assert_dom_equal( - "", - output_buffer - ) + fields_for :post, @post, :index => 815 do |f| + concat f.collection_select(:author_name, @posts, :author_name, :author_name) end - def test_collection_select_under_fields_for_with_auto_index - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + assert_dom_equal( + "", + output_buffer + ) + end - @post = Post.new - @post.author_name = "Babe" - def @post.to_param; 815; end + def test_collection_select_under_fields_for_with_auto_index + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - fields_for "post[]", @post do |f| - concat f.collection_select(:author_name, @posts, :author_name, :author_name) - end + @post = Post.new + @post.author_name = "Babe" + def @post.to_param; 815; end - assert_dom_equal( - "", - output_buffer - ) + fields_for "post[]", @post do |f| + concat f.collection_select(:author_name, @posts, :author_name, :author_name) end - def test_collection_select_with_blank_and_style - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + assert_dom_equal( + "", + output_buffer + ) + end - @post = Post.new - @post.author_name = "Babe" + def test_collection_select_with_blank_and_style + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - assert_dom_equal( - "", - collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") - ) - end + @post = Post.new + @post.author_name = "Babe" - def test_collection_select_with_blank_as_string_and_style - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + assert_dom_equal( + "", + collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") + ) + end - @post = Post.new - @post.author_name = "Babe" + def test_collection_select_with_blank_as_string_and_style + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - assert_dom_equal( - "", - collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px") - ) - end + @post = Post.new + @post.author_name = "Babe" - def test_collection_select_with_multiple_option_appends_array_brackets - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + assert_dom_equal( + "", + collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px") + ) + end - @post = Post.new - @post.author_name = "Babe" + def test_collection_select_with_multiple_option_appends_array_brackets + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - expected = "" + @post = Post.new + @post.author_name = "Babe" - # Should suffix default name with []. - assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, :multiple => true) + expected = "" - # Shouldn't suffix custom name with []. - assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) - end + # Should suffix default name with []. + assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, :multiple => true) - def test_collection_select_with_blank_and_selected - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] + # Shouldn't suffix custom name with []. + assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) + end - @post = Post.new - @post.author_name = "Babe" + def test_collection_select_with_blank_and_selected + @posts = [ + Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] - assert_dom_equal( - %{}, - collection_select("post", "author_name", @posts, "author_name", "author_name", {:include_blank => true, :selected => ""}) - ) - end + @post = Post.new + @post.author_name = "Babe" - def test_time_zone_select - @firm = Firm.new("D") - html = time_zone_select( "firm", "time_zone" ) - assert_dom_equal "", - html + assert_dom_equal( + %{}, + collection_select("post", "author_name", @posts, "author_name", "author_name", {:include_blank => true, :selected => ""}) + ) + end + + def test_time_zone_select + @firm = Firm.new("D") + html = time_zone_select( "firm", "time_zone" ) + assert_dom_equal "", + html + end + + def test_time_zone_select_under_fields_for + @firm = Firm.new("D") + + fields_for :firm, @firm do |f| + concat f.time_zone_select(:time_zone) end + + assert_dom_equal( + "", + output_buffer + ) + end - def test_time_zone_select_under_fields_for - @firm = Firm.new("D") + def test_time_zone_select_under_fields_for_with_index + @firm = Firm.new("D") - fields_for :firm, @firm do |f| - concat f.time_zone_select(:time_zone) - end - - assert_dom_equal( - "", - output_buffer - ) + fields_for :firm, @firm, :index => 305 do |f| + concat f.time_zone_select(:time_zone) end - def test_time_zone_select_under_fields_for_with_index - @firm = Firm.new("D") + assert_dom_equal( + "", + output_buffer + ) + end - fields_for :firm, @firm, :index => 305 do |f| - concat f.time_zone_select(:time_zone) - end + def test_time_zone_select_under_fields_for_with_auto_index + @firm = Firm.new("D") + def @firm.to_param; 305; end - assert_dom_equal( - "", - output_buffer - ) + fields_for "firm[]", @firm do |f| + concat f.time_zone_select(:time_zone) end - def test_time_zone_select_under_fields_for_with_auto_index - @firm = Firm.new("D") - def @firm.to_param; 305; end + assert_dom_equal( + "", + output_buffer + ) + end - fields_for "firm[]", @firm do |f| - concat f.time_zone_select(:time_zone) - end + def test_time_zone_select_with_blank + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, :include_blank => true) + assert_dom_equal "", + html + end - assert_dom_equal( - "", - output_buffer - ) - end + def test_time_zone_select_with_blank_as_string + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, :include_blank => 'No Zone') + assert_dom_equal "", + html + end - def test_time_zone_select_with_blank - @firm = Firm.new("D") - html = time_zone_select("firm", "time_zone", nil, :include_blank => true) - assert_dom_equal "", - html - end + def test_time_zone_select_with_style + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, {}, + "style" => "color: red") + assert_dom_equal "", + html + assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {}, + :style => "color: red") + end - def test_time_zone_select_with_blank_as_string - @firm = Firm.new("D") - html = time_zone_select("firm", "time_zone", nil, :include_blank => 'No Zone') - assert_dom_equal "", - html - end + def test_time_zone_select_with_blank_and_style + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, + { :include_blank => true }, "style" => "color: red") + assert_dom_equal "", + html + assert_dom_equal html, time_zone_select("firm", "time_zone", nil, + { :include_blank => true }, :style => "color: red") + end - def test_time_zone_select_with_style - @firm = Firm.new("D") - html = time_zone_select("firm", "time_zone", nil, {}, - "style" => "color: red") - assert_dom_equal "", - html - assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {}, - :style => "color: red") - end + def test_time_zone_select_with_blank_as_string_and_style + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, + { :include_blank => 'No Zone' }, "style" => "color: red") + assert_dom_equal "", + html + assert_dom_equal html, time_zone_select("firm", "time_zone", nil, + { :include_blank => 'No Zone' }, :style => "color: red") + end - def test_time_zone_select_with_blank_and_style - @firm = Firm.new("D") - html = time_zone_select("firm", "time_zone", nil, - { :include_blank => true }, "style" => "color: red") - assert_dom_equal "", - html - assert_dom_equal html, time_zone_select("firm", "time_zone", nil, - { :include_blank => true }, :style => "color: red") - end + def test_time_zone_select_with_priority_zones + @firm = Firm.new("D") + zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ] + html = time_zone_select("firm", "time_zone", zones ) + assert_dom_equal "", + html + end - def test_time_zone_select_with_blank_as_string_and_style - @firm = Firm.new("D") - html = time_zone_select("firm", "time_zone", nil, - { :include_blank => 'No Zone' }, "style" => "color: red") - assert_dom_equal "", - html - assert_dom_equal html, time_zone_select("firm", "time_zone", nil, - { :include_blank => 'No Zone' }, :style => "color: red") - end + def test_time_zone_select_with_priority_zones_as_regexp + @firm = Firm.new("D") + @fake_timezones.each_with_index do |tz, i| + tz.stubs(:=~).returns(i.zero? || i == 3) + end + + html = time_zone_select("firm", "time_zone", /A|D/) + assert_dom_equal "", + html + end - def test_time_zone_select_with_priority_zones - @firm = Firm.new("D") - zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ] - html = time_zone_select("firm", "time_zone", zones ) + def test_time_zone_select_with_default_time_zone_and_nil_value + @firm = Firm.new() + @firm.time_zone = nil + html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) assert_dom_equal "", html - end - - def test_time_zone_select_with_priority_zones_as_regexp - @firm = Firm.new("D") - @fake_timezones.each_with_index do |tz, i| - tz.stubs(:=~).returns(i.zero? || i == 3) - end + end - html = time_zone_select("firm", "time_zone", /A|D/) + def test_time_zone_select_with_default_time_zone_and_value + @firm = Firm.new('D') + html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) assert_dom_equal "", html - end - - def test_time_zone_select_with_default_time_zone_and_nil_value - @firm = Firm.new() - @firm.time_zone = nil - html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) - assert_dom_equal "", - html - end - - def test_time_zone_select_with_default_time_zone_and_value - @firm = Firm.new('D') - html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) - assert_dom_equal "", - html - end - end + end diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 3fdf991a44..bf5b81292f 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -5,67 +5,65 @@ class NumberHelperI18nTests < Test::Unit::TestCase 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 } - @human_storage_units_format_default = "%n %u" - @human_storage_units_units_byte_other = "Bytes" - @human_storage_units_units_kb_other = "KB" - @percentage_defaults = { :delimiter => '' } - @precision_defaults = { :delimiter => '' } + def setup + @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' } + @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 } + @human_defaults = { :precision => 1 } + @human_storage_units_format_default = "%n %u" + @human_storage_units_units_byte_other = "Bytes" + @human_storage_units_units_kb_other = "KB" + @percentage_defaults = { :delimiter => '' } + @precision_defaults = { :delimiter => '' } - I18n.backend.store_translations 'en', :number => { :format => @number_defaults, - :currency => { :format => @currency_defaults }, :human => @human_defaults } - end + I18n.backend.store_translations 'en', :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', :raise => true).returns(@number_defaults) - I18n.expects(:translate).with(:'number.currency.format', :locale => 'en', - :raise => true).returns(@currency_defaults) - number_to_currency(1, :locale => 'en') - end + def test_number_to_currency_translates_currency_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.currency.format', :locale => 'en', + :raise => true).returns(@currency_defaults) + number_to_currency(1, :locale => 'en') + end - def test_number_with_precision_translates_number_formats - I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) - I18n.expects(:translate).with(:'number.precision.format', :locale => 'en', - :raise => true).returns(@precision_defaults) - number_with_precision(1, :locale => 'en') - end + def test_number_with_precision_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.precision.format', :locale => 'en', + :raise => true).returns(@precision_defaults) + number_with_precision(1, :locale => 'en') + end - def test_number_with_delimiter_translates_number_formats - I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) - number_with_delimiter(1, :locale => 'en') - end + def test_number_with_delimiter_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + number_with_delimiter(1, :locale => 'en') + end - def test_number_to_percentage_translates_number_formats - I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) - I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en', - :raise => true).returns(@percentage_defaults) - number_to_percentage(1, :locale => 'en') - end + def test_number_to_percentage_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en', + :raise => true).returns(@percentage_defaults) + number_to_percentage(1, :locale => 'en') + end - def test_number_to_human_size_translates_human_formats - I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) - I18n.expects(:translate).with(:'number.human.format', :locale => 'en', - :raise => true).returns(@human_defaults) - I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en', - :raise => true).returns(@human_storage_units_format_default) - I18n.expects(:translate).with(:'number.human.storage_units.units.kb', :locale => 'en', :count => 2, - :raise => true).returns(@human_storage_units_units_kb_other) - # 2KB - number_to_human_size(2048, :locale => 'en') + def test_number_to_human_size_translates_human_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.human.format', :locale => 'en', + :raise => true).returns(@human_defaults) + I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en', + :raise => true).returns(@human_storage_units_format_default) + I18n.expects(:translate).with(:'number.human.storage_units.units.kb', :locale => 'en', :count => 2, + :raise => true).returns(@human_storage_units_units_kb_other) + # 2KB + number_to_human_size(2048, :locale => 'en') - I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) - I18n.expects(:translate).with(:'number.human.format', :locale => 'en', - :raise => true).returns(@human_defaults) - I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en', - :raise => true).returns(@human_storage_units_format_default) - I18n.expects(:translate).with(:'number.human.storage_units.units.byte', :locale => 'en', :count => 42, - :raise => true).returns(@human_storage_units_units_byte_other) - # 42 Bytes - number_to_human_size(42, :locale => 'en') - end + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.human.format', :locale => 'en', + :raise => true).returns(@human_defaults) + I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en', + :raise => true).returns(@human_storage_units_format_default) + I18n.expects(:translate).with(:'number.human.storage_units.units.byte', :locale => 'en', :count => 42, + :raise => true).returns(@human_storage_units_units_byte_other) + # 42 Bytes + number_to_human_size(42, :locale => 'en') end end diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb index 660f51b3be..ccd299f46a 100644 --- a/actionpack/test/template/test_test.rb +++ b/actionpack/test/template/test_test.rb @@ -38,12 +38,10 @@ class PeopleHelperTest < ActionView::TestCase assert_equal "http://test.host/people", homepage_url end - uses_mocha "link_to_person" do - def test_link_to_person - person = mock(:name => "David") - expects(:mocha_mock_path).with(person).returns("/people/1") - assert_equal 'David', link_to_person(person) - end + def test_link_to_person + person = mock(:name => "David") + expects(:mocha_mock_path).with(person).returns("/people/1") + assert_equal 'David', link_to_person(person) end end diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index d0d65cb450..6534df6bbd 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -5,24 +5,22 @@ class TranslationHelperTest < Test::Unit::TestCase 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, :locale => 'en', :raise => true) - translate :foo, :locale => 'en' - end - - def test_returns_missing_translation_message_wrapped_into_span - expected = 'en, foo' - assert_equal expected, translate(:foo) - end + def setup + end + + def test_delegates_to_i18n_setting_the_raise_option + I18n.expects(:translate).with(:foo, :locale => 'en', :raise => true) + translate :foo, :locale => 'en' + end - def test_delegates_localize_to_i18n - @time = Time.utc(2008, 7, 8, 12, 18, 38) - I18n.expects(:localize).with(@time) - localize @time - end + def test_returns_missing_translation_message_wrapped_into_span + expected = 'en, foo' + 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 \ No newline at end of file +end -- cgit v1.2.3 From b80fa817d422e6c7ab743f4aa5cb4315b48ec7d5 Mon Sep 17 00:00:00 2001 From: chris finne Date: Tue, 3 Feb 2009 21:55:08 -0800 Subject: Fix a syntax error in current_page?() that was prevent matches against URL's with multiple query parameters [#1868 state:committed] Signed-off-by: David Heinemeier Hansson --- actionpack/test/template/url_helper_test.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 2f6fa134b5..2950b4b60c 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -263,11 +263,23 @@ class UrlHelperTest < ActionView::TestCase assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show") + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1") + @controller.url = "http://www.example.com/weblog/show?order=desc&page=1" + assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog", :order=>'desc', :page=>'1' }) + assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=desc&page=1") + assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=desc&page=1") + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc") @controller.url = "http://www.example.com/weblog/show?order=asc" assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=asc") + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1") + @controller.url = "http://www.example.com/weblog/show?order=desc&page=2" + assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) + assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=desc&page=2") + + @controller.request = RequestMock.new("http://www.example.com/weblog/show") @controller.url = "http://www.example.com/weblog/list" assert_equal "Listing", @@ -319,7 +331,7 @@ class UrlHelperTest < ActionView::TestCase assert_dom_equal "", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") assert_dom_equal "", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") end - + def protect_against_forgery? false end -- cgit v1.2.3 From 6db78e8c02442080d2be93faeeb42be97b09fb53 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 5 Feb 2009 20:37:57 +0100 Subject: Added tests from Andrew Whites fix [#1385 state:committed] --- actionpack/test/template/url_helper_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 2950b4b60c..e7799fb204 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -252,6 +252,27 @@ class UrlHelperTest < ActionView::TestCase assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog", :id => 1) end + def test_current_page_with_simple_url + @controller.request = RequestMock.new("http://www.example.com/weblog/show") + @controller.url = "http://www.example.com/weblog/show" + assert current_page?({ :action => "show", :controller => "weblog" }) + assert current_page?("http://www.example.com/weblog/show") + end + + def test_current_page_ignoring_params + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1") + @controller.url = "http://www.example.com/weblog/show?order=desc&page=1" + assert current_page?({ :action => "show", :controller => "weblog" }) + assert current_page?("http://www.example.com/weblog/show") + end + + def test_current_page_with_params_that_match + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1") + @controller.url = "http://www.example.com/weblog/show?order=desc&page=1" + assert current_page?({ :action => "show", :controller => "weblog", :order => "desc", :page => "1" }) + assert current_page?("http://www.example.com/weblog/show?order=desc&page=1") + end + def test_link_unless_current @controller.request = RequestMock.new("http://www.example.com/weblog/show") @controller.url = "http://www.example.com/weblog/show" -- cgit v1.2.3 From d15d53cf810014b90827015ecd0e601176492fb7 Mon Sep 17 00:00:00 2001 From: Pascal Ehlert Date: Mon, 2 Feb 2009 22:49:28 +0100 Subject: Allowing an object to be passed explicitly to a fields_for with nested_attributes on one-to-one associations Signed-off-by: Michael Koziarski [#1849 state:committed] --- actionpack/test/template/form_helper_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 33a542af7e..b7ea2c0176 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -586,6 +586,15 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_explicitly_passed_object_on_a_nested_attributes_one_to_one_association + form_for(:post, @post) do |f| + f.fields_for(:author, Author.new(123)) do |af| + assert_not_nil af.object + assert_equal 123, af.object.id + end + end + end + def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association @post.author = Author.new(321) -- cgit v1.2.3 From b1c1e3deb7d752292abaff34ba66a3eae030d252 Mon Sep 17 00:00:00 2001 From: Eugene Pimenov Date: Thu, 5 Feb 2009 07:10:03 +0300 Subject: Ruby 1.9 compat: change encoding of action_view/renderable to utf-8, so erb templates can use utf-8 properly [#1881 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/test/template/render_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c7405d47de..2caf4e8fe4 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'abstract_unit' require 'controller/fake_models' @@ -204,6 +205,14 @@ module RenderTestCases assert_equal %(title\n
column
\n
content
\n), @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") end + + if '1.9'.respond_to?(:force_encoding) + def test_render_utf8_template + result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield") + assert_equal "Русский текст\n日本語のテキスト", result + assert_equal Encoding::UTF_8, result.encoding + end + end end class CachedViewRenderTest < Test::Unit::TestCase -- cgit v1.2.3 From 24f2e676f700b8a387c6f4c27acf172658cd7863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 6 Feb 2009 23:23:50 -0600 Subject: Added support to dashed locales in templates localization [#1888 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/render_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 2caf4e8fe4..5586434cb6 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -10,6 +10,7 @@ module RenderTestCases # Reload and register danish language for testing I18n.reload! I18n.backend.store_translations 'da', {} + I18n.backend.store_translations 'pt-BR', {} # Ensure original are still the same since we are reindexing view paths assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort @@ -35,6 +36,14 @@ module RenderTestCases I18n.locale = old_locale end + def test_render_file_with_dashed_locale + old_locale = I18n.locale + I18n.locale = :"pt-BR" + assert_equal "Ola mundo", @view.render(:file => "test/hello_world") + ensure + I18n.locale = old_locale + end + def test_render_file_at_top_level assert_equal 'Elastica', @view.render(:file => '/shared') end -- cgit v1.2.3 From 50f51ff95047858fa6dd889ade3027b7254c6dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 7 Feb 2009 11:37:02 -0600 Subject: Render implicit html template when xhr request now supports localization [#1886 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/render_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 5586434cb6..9db62d9c23 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -44,6 +44,25 @@ module RenderTestCases I18n.locale = old_locale end + def test_render_implicit_html_template_from_xhr_request + old_format = @view.template_format + @view.template_format = :js + assert_equal "Hello HTML!", @view.render(:file => "test/render_implicit_html_template_from_xhr_request") + ensure + @view.template_format = old_format + end + + def test_render_implicit_html_template_from_xhr_request_with_localization + old_locale = I18n.locale + old_format = @view.template_format + I18n.locale = :da + @view.template_format = :js + assert_equal "Hey HTML!\n", @view.render(:file => "test/render_implicit_html_template_from_xhr_request") + ensure + I18n.locale = old_locale + @view.template_format = old_format + end + def test_render_file_at_top_level assert_equal 'Elastica', @view.render(:file => '/shared') end -- cgit v1.2.3 From 893e9eb99504705419ad6edac14d00e71cef5f12 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 9 Feb 2009 14:20:30 -0600 Subject: Improve view rendering performance in development mode and reinstate template recompiling in production [#1909 state:resolved] Signed-off-by: Joshua Peek --- .../test/template/compiled_templates_test.rb | 42 ++++++++++++---------- actionpack/test/template/render_test.rb | 15 +------- 2 files changed, 24 insertions(+), 33 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index a7ed13cf57..2c32fdee0b 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -39,35 +39,29 @@ class CompiledTemplatesTest < Test::Unit::TestCase end def test_template_changes_are_not_reflected_with_cached_templates - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do + with_caching(true) do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + end assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - def test_template_changes_are_reflected_with_uncached_templates - assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do - assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world.erb") + def test_template_changes_are_reflected_without_cached_templates + with_caching(false) do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Goodbye world!", render(:file => "test/hello_world.erb") + sleep(1) # Need to sleep so that the timestamp actually changes + end + assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") end private def render(*args) - render_with_cache(*args) - end - - def render_with_cache(*args) view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::EagerPath, view_paths.first.class - ActionView::Base.new(view_paths, {}).render(*args) - end - - def render_without_cache(*args) - path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH) - view_paths = ActionView::Base.process_view_paths(path) assert_equal ActionView::Template::Path, view_paths.first.class ActionView::Base.new(view_paths, {}).render(*args) end @@ -82,4 +76,14 @@ class CompiledTemplatesTest < Test::Unit::TestCase File.open(filename, "wb+") { |f| f.write(old_content) } end end + + def with_caching(caching_enabled) + old_caching_enabled = ActionView::Base.cache_template_loading + begin + ActionView::Base.cache_template_loading = caching_enabled + yield + ensure + ActionView::Base.cache_template_loading = old_caching_enabled + end + end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 9db62d9c23..34e7e82366 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -243,25 +243,12 @@ module RenderTestCases end end -class CachedViewRenderTest < Test::Unit::TestCase +class CachedRenderTest < Test::Unit::TestCase include RenderTestCases # Ensure view path cache is primed def setup view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::EagerPath, view_paths.first.class - setup_view(view_paths) - end -end - -class LazyViewRenderTest < Test::Unit::TestCase - include RenderTestCases - - # Test the same thing as above, but make sure the view path - # is not eager loaded - def setup - path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH) - view_paths = ActionView::Base.process_view_paths(path) assert_equal ActionView::Template::Path, view_paths.first.class setup_view(view_paths) end -- cgit v1.2.3 From 7527cdf79c640eae5db29a6f3f9b955aa50bc29e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 10 Feb 2009 12:57:12 +0100 Subject: Added partial scoping to TranslationHelper#translate, so if you call translate('.foo') from the people/index.html.erb template, you'll actually be calling I18n.translate(people.index.foo) [DHH] --- actionpack/test/template/translation_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 6534df6bbd..a20f3c394c 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -23,4 +23,10 @@ class TranslationHelperTest < Test::Unit::TestCase I18n.expects(:localize).with(@time) localize @time end + + def test_scoping_by_partial + expects(:template).returns(stub(:path_without_format_and_extension => "people/index")) + I18n.expects(:translate).with("people.index.foo", :locale => 'en', :raise => true) + translate ".foo", :locale => 'en' + end end -- cgit v1.2.3 From 199e750d46c04970b5e7684998d09405648ecbd4 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 10 Feb 2009 12:09:49 -0600 Subject: Fix some edge cases when the same template is called with different local assigns Signed-off-by: Joshua Peek --- .../test/template/compiled_templates_test.rb | 86 ++++++++++++++-------- 1 file changed, 54 insertions(+), 32 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 2c32fdee0b..55fa346fb8 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -10,52 +10,64 @@ class CompiledTemplatesTest < Test::Unit::TestCase end def test_template_gets_compiled - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - assert_equal 1, @compiled_templates.instance_methods.size + with_caching(true) do + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + assert_equal 1, @compiled_templates.instance_methods.size + end 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(:file => "test/hello_world.erb") - assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"}) - assert_equal 2, @compiled_templates.instance_methods.size + with_caching(true) do + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"}) + assert_equal 2, @compiled_templates.instance_methods.size + end 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(:file => "test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).never - assert_equal "Hello world!", render(:file => "test/hello_world.erb") + with_caching(true) do + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + end end def test_compiled_template_will_always_be_recompiled_when_template_is_not_cached - ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true) - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } - assert_equal 1, @compiled_templates.instance_methods.size + with_caching(false) do + ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true) + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).times(3) + 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + assert_equal 1, @compiled_templates.instance_methods.size + end end - def test_template_changes_are_not_reflected_with_cached_templates + def test_template_changes_are_not_reflected_with_cached_template_loading with_caching(true) do - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do + with_reloading(false) do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + end assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - assert_equal "Hello world!", render(:file => "test/hello_world.erb") end end - def test_template_changes_are_reflected_without_cached_templates - with_caching(false) do - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do - assert_equal "Goodbye world!", render(:file => "test/hello_world.erb") - sleep(1) # Need to sleep so that the timestamp actually changes + def test_template_changes_are_reflected_without_cached_template_loading + with_caching(true) do + with_reloading(true) do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Goodbye world!", render(:file => "test/hello_world.erb") + sleep(1) # Need to sleep so that the timestamp actually changes + end + assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - assert_equal "Hello world!", render(:file => "test/hello_world.erb") end end @@ -77,13 +89,23 @@ class CompiledTemplatesTest < Test::Unit::TestCase end end - def with_caching(caching_enabled) - old_caching_enabled = ActionView::Base.cache_template_loading + def with_caching(perform_caching) + old_perform_caching = ActionController::Base.perform_caching + begin + ActionController::Base.perform_caching = perform_caching + yield + ensure + ActionController::Base.perform_caching = old_perform_caching + end + end + + def with_reloading(reload_templates) + old_cache_template_loading = ActionView::Base.cache_template_loading begin - ActionView::Base.cache_template_loading = caching_enabled + ActionView::Base.cache_template_loading = !reload_templates yield ensure - ActionView::Base.cache_template_loading = old_caching_enabled + ActionView::Base.cache_template_loading = old_cache_template_loading end end end -- cgit v1.2.3 From f400209084fabb00e18c3325e1933f4543fce94c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 10 Feb 2009 13:10:46 -0600 Subject: Move checkbox hidden field before the actual checkbox so the actual value doesn't get clobbered [#1863 state:resolved] --- actionpack/test/template/form_helper_test.rb | 72 +++++++++++++--------------- 1 file changed, 34 insertions(+), 38 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index b7ea2c0176..b7e4a933e1 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -170,36 +170,36 @@ class FormHelperTest < ActionView::TestCase def test_check_box assert_dom_equal( - '', + '', check_box("post", "secret") ) @post.secret = 0 assert_dom_equal( - '', + '', check_box("post", "secret") ) assert_dom_equal( - '', + '', check_box("post", "secret" ,{"checked"=>"checked"}) ) @post.secret = true assert_dom_equal( - '', + '', check_box("post", "secret") ) assert_dom_equal( - '', + '', check_box("post", "secret?") ) @post.secret = ['0'] assert_dom_equal( - '', + '', check_box("post", "secret") ) @post.secret = ['1'] assert_dom_equal( - '', + '', check_box("post", "secret") ) end @@ -207,14 +207,14 @@ class FormHelperTest < ActionView::TestCase def test_check_box_with_explicit_checked_and_unchecked_values @post.secret = "on" assert_dom_equal( - '', + '', check_box("post", "secret", {}, "on", "off") ) end def test_checkbox_disabled_still_submits_checked_value assert_dom_equal( - '', + '', check_box("post", "secret", { :disabled => :true }) ) end @@ -289,7 +289,7 @@ class FormHelperTest < ActionView::TestCase text_area("post", "body", "name" => "really!") ) assert_dom_equal( - '', + '', check_box("post", "secret", "name" => "i mean it") ) assert_dom_equal text_field("post", "title", "name" => "dont guess"), @@ -309,7 +309,7 @@ class FormHelperTest < ActionView::TestCase text_area("post", "body", "id" => "really!") ) assert_dom_equal( - '', + '', check_box("post", "secret", "id" => "i mean it") ) assert_dom_equal text_field("post", "title", "id" => "dont guess"), @@ -334,7 +334,7 @@ class FormHelperTest < ActionView::TestCase text_area("post[]", "body") ) assert_dom_equal( - "", + "", check_box("post[]", "secret") ) assert_dom_equal( @@ -360,8 +360,8 @@ class FormHelperTest < ActionView::TestCase "" + "" + "" + - "" + "" + + "" + "" + "" @@ -380,8 +380,8 @@ class FormHelperTest < ActionView::TestCase "
" + "" + "" + - "" + "" + + "" + "" assert_dom_equal expected, output_buffer @@ -398,8 +398,8 @@ class FormHelperTest < ActionView::TestCase "
" + "" + "" + - "" + "" + + "" + "
" assert_dom_equal expected, output_buffer @@ -418,8 +418,8 @@ class FormHelperTest < ActionView::TestCase "" + "" + "" + - "" + "" + + "" + "" assert_dom_equal expected, output_buffer @@ -436,8 +436,8 @@ class FormHelperTest < ActionView::TestCase "
" + "" + "" + - "" + "" + + "" + "
" assert_dom_equal expected, output_buffer @@ -708,8 +708,8 @@ class FormHelperTest < ActionView::TestCase expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -724,8 +724,8 @@ class FormHelperTest < ActionView::TestCase expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -740,8 +740,8 @@ class FormHelperTest < ActionView::TestCase expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -756,8 +756,8 @@ class FormHelperTest < ActionView::TestCase expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -772,8 +772,8 @@ class FormHelperTest < ActionView::TestCase expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -788,8 +788,8 @@ class FormHelperTest < ActionView::TestCase expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -834,8 +834,8 @@ class FormHelperTest < ActionView::TestCase "
" + "" + "" + - "" + "" + + "" + "
" assert_dom_equal expected, output_buffer @@ -883,8 +883,7 @@ class FormHelperTest < ActionView::TestCase "
" + "
" + "
" + - " " + - "
" + + "
" + "
" assert_dom_equal expected, output_buffer @@ -904,8 +903,7 @@ class FormHelperTest < ActionView::TestCase "
" + "
" + "
" + - " " + - "
" + + "
" + "
" assert_dom_equal expected, output_buffer @@ -960,8 +958,7 @@ class FormHelperTest < ActionView::TestCase %(
) + "
" + "
" + - " " + - "
" + + "
" + "
" assert_dom_equal expected, output_buffer @@ -977,8 +974,7 @@ class FormHelperTest < ActionView::TestCase expected = "
" + "
" + - " " + - "
" + "
" assert_dom_equal expected, output_buffer end -- cgit v1.2.3 From 3942cb406e1d5db0ac00e03153809cc8dc4cc4db Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 12 Feb 2009 19:35:14 +0100 Subject: Port fast reloadable templates from rails-dev-boost. --- .../test/template/compiled_templates_test.rb | 44 ++++++++++++++-------- actionpack/test/template/render_test.rb | 29 ++++++++++++-- 2 files changed, 54 insertions(+), 19 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 55fa346fb8..a8f8455a54 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -2,8 +2,21 @@ require 'abstract_unit' require 'controller/fake_models' class CompiledTemplatesTest < Test::Unit::TestCase + def setup @compiled_templates = ActionView::Base::CompiledTemplates + + # first, if we are running the whole test suite with ReloadableTemplates + # try to undef all the methods through ReloadableTemplate's interfaces + unless ActionView::Base.cache_template_loading? + ActionController::Base.view_paths.each do |view_path| + view_path.paths.values.uniq!.each do |reloadable_template| + reloadable_template.undef_my_compiled_methods! + end + end + end + + # just purge anything that's left @compiled_templates.instance_methods.each do |m| @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ end @@ -35,17 +48,6 @@ class CompiledTemplatesTest < Test::Unit::TestCase end end - def test_compiled_template_will_always_be_recompiled_when_template_is_not_cached - with_caching(false) do - ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true) - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } - assert_equal 1, @compiled_templates.instance_methods.size - end - end - def test_template_changes_are_not_reflected_with_cached_template_loading with_caching(true) do with_reloading(false) do @@ -63,9 +65,10 @@ class CompiledTemplatesTest < Test::Unit::TestCase with_reloading(true) do assert_equal "Hello world!", render(:file => "test/hello_world.erb") modify_template "test/hello_world.erb", "Goodbye world!" do + reset_mtime_of('test/hello_world.erb') assert_equal "Goodbye world!", render(:file => "test/hello_world.erb") - sleep(1) # Need to sleep so that the timestamp actually changes end + reset_mtime_of('test/hello_world.erb') assert_equal "Hello world!", render(:file => "test/hello_world.erb") end end @@ -74,10 +77,15 @@ class CompiledTemplatesTest < Test::Unit::TestCase private def render(*args) view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::Path, view_paths.first.class ActionView::Base.new(view_paths, {}).render(*args) end + def reset_mtime_of(template_name) + unless ActionView::Base.cache_template_loading? + ActionController::Base.view_paths.find_template(template_name).previously_last_modified = 10.seconds.ago + end + end + def modify_template(template, content) filename = "#{FIXTURE_LOAD_PATH}/#{template}" old_content = File.read(filename) @@ -100,12 +108,18 @@ class CompiledTemplatesTest < Test::Unit::TestCase end def with_reloading(reload_templates) - old_cache_template_loading = ActionView::Base.cache_template_loading + old_view_paths, old_cache_templates = ActionController::Base.view_paths, ActionView::Base.cache_template_loading begin ActionView::Base.cache_template_loading = !reload_templates + ActionController::Base.view_paths = view_paths_for(reload_templates) yield ensure - ActionView::Base.cache_template_loading = old_cache_template_loading + ActionController::Base.view_paths, ActionView::Base.cache_template_loading = old_view_paths, old_cache_templates end end + + def view_paths_for(reload_templates) + # reloadable paths are cheap to create + reload_templates ? ActionView::PathSet.new(CACHED_VIEW_PATHS.map(&:to_s)) : CACHED_VIEW_PATHS + end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 34e7e82366..107c625e32 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -243,13 +243,34 @@ module RenderTestCases end end +module TemplatesSetupTeardown + def setup_view_paths_for(new_cache_template_loading) + @previous_cache_template_loading, ActionView::Base.cache_template_loading = ActionView::Base.cache_template_loading, new_cache_template_loading + view_paths = new_cache_template_loading ? CACHED_VIEW_PATHS : ActionView::Base.process_view_paths(CACHED_VIEW_PATHS.map(&:to_s)) + assert_equal(new_cache_template_loading ? ActionView::Template::EagerPath : ActionView::ReloadableTemplate::ReloadablePath, view_paths.first.class) + setup_view(view_paths) + end + + def teardown + ActionView::Base.cache_template_loading = @previous_cache_template_loading + end +end + class CachedRenderTest < Test::Unit::TestCase + include TemplatesSetupTeardown include RenderTestCases - # Ensure view path cache is primed def setup - view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::Path, view_paths.first.class - setup_view(view_paths) + setup_view_paths_for(cache_templates = true) end end + +class ReloadableRenderTest < Test::Unit::TestCase + include TemplatesSetupTeardown + include RenderTestCases + + def setup + setup_view_paths_for(cache_templates = false) + end +end + -- cgit v1.2.3 From 5dbc9d40a49f5f0f50c2f3ebe6dda942f0e61562 Mon Sep 17 00:00:00 2001 From: Lance Ivy Date: Sun, 8 Feb 2009 14:23:35 +0100 Subject: Changed API of NestedAttributes to take an array, or hash with index keys, of hashes that have the id on the inside of the attributes hash and updated the FormBuilder to produce such hashes. Also fixed NestedAttributes with composite ids. Signed-off-by: Michael Koziarski Signed-off-by: Eloy Duran [#1892 state:committed] --- actionpack/test/template/form_helper_test.rb | 38 ++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index b7e4a933e1..5cc81b4afb 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -607,6 +607,7 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + + '' + '' + '
' @@ -627,8 +628,10 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + - '' + - '' + + '' + + '' + + '' + + '' + '
' assert_dom_equal expected, output_buffer @@ -648,8 +651,8 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + - '' + - '' + + '' + + '' + '
' assert_dom_equal expected, output_buffer @@ -669,8 +672,9 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + - '' + - '' + + '' + + '' + + '' + '
' assert_dom_equal expected, output_buffer @@ -690,14 +694,32 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + - '' + - '' + + '' + + '' + + '' + '
' assert_dom_equal expected, output_buffer assert_equal yielded_comments, @post.comments end + def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association + @post.comments = [] + + form_for(:post, @post) do |f| + f.fields_for(:comments, Comment.new(321), :child_index => 'abc') do |cf| + concat cf.text_field(:name) + end + end + + expected = '
' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + def test_fields_for fields_for(:post, @post) do |f| concat f.text_field(:title) -- cgit v1.2.3 From f04346d8b999476113d5e5a30661e07899e3ff80 Mon Sep 17 00:00:00 2001 From: Sam Oliver Date: Fri, 2 Jan 2009 15:34:38 +0000 Subject: Stops date select helpers from defaulting the selected date to today if :prompt option has been used Signed-off-by: Michael Koziarski [#561 state:resolved] --- actionpack/test/template/date_helper_test.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 59e921f09b..2e4763f446 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1820,60 +1820,60 @@ class DateHelperTest < ActionView::TestCase def test_datetime_select_with_default_prompt @post = Post.new - @post.updated_at = Time.local(2004, 6, 15, 16, 35) + @post.updated_at = nil expected = %{\n" expected << %{\n" expected << %{\n" expected << " — " expected << %{\n" expected << " : " expected << %{\n" - assert_dom_equal expected, datetime_select("post", "updated_at", :prompt => true) + assert_dom_equal expected, datetime_select("post", "updated_at", :start_year=>1999, :end_year=>2009, :prompt => true) end def test_datetime_select_with_custom_prompt @post = Post.new - @post.updated_at = Time.local(2004, 6, 15, 16, 35) + @post.updated_at = nil expected = %{\n" expected << %{\n" expected << %{\n" expected << " — " expected << %{\n" expected << " : " expected << %{\n" - assert_dom_equal expected, datetime_select("post", "updated_at", :prompt => {:year => 'Choose year', :month => 'Choose month', :day => 'Choose day', :hour => 'Choose hour', :minute => 'Choose minute'}) + assert_dom_equal expected, datetime_select("post", "updated_at", :start_year=>1999, :end_year=>2009, :prompt => {:year => 'Choose year', :month => 'Choose month', :day => 'Choose day', :hour => 'Choose hour', :minute => 'Choose minute'}) end def test_date_select_with_zero_value_and_no_start_year -- cgit v1.2.3 From d206b80a36d400a554f61ddb8a6ad33d6973fb13 Mon Sep 17 00:00:00 2001 From: Tekin Suleyman Date: Sat, 14 Feb 2009 00:14:48 +0000 Subject: DRY up form option helper tests Signed-off-by: Michael Koziarski --- .../test/template/form_options_helper_test.rb | 97 +++++----------------- 1 file changed, 19 insertions(+), 78 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 83c27ac042..2dbd2ecdd4 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -24,42 +24,24 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - assert_dom_equal( "\n\n", - options_from_collection_for_select(@posts, "author_name", "title") + options_from_collection_for_select(dummy_posts, "author_name", "title") ) end def test_collection_options_with_preselected_value - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - assert_dom_equal( "\n\n", - options_from_collection_for_select(@posts, "author_name", "title", "Babe") + options_from_collection_for_select(dummy_posts, "author_name", "title", "Babe") ) end def test_collection_options_with_preselected_value_array - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - assert_dom_equal( "\n\n", - options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ]) + options_from_collection_for_select(dummy_posts, "author_name", "title", [ "Babe", "Cabe" ]) ) end @@ -371,33 +353,21 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_select - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" assert_dom_equal( "", - collection_select("post", "author_name", @posts, "author_name", "author_name") + collection_select("post", "author_name", dummy_posts, "author_name", "author_name") ) end def test_collection_select_under_fields_for - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" fields_for :post, @post do |f| - concat f.collection_select(:author_name, @posts, :author_name, :author_name) + concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name) end assert_dom_equal( @@ -407,17 +377,11 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_select_under_fields_for_with_index - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" fields_for :post, @post, :index => 815 do |f| - concat f.collection_select(:author_name, @posts, :author_name, :author_name) + concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name) end assert_dom_equal( @@ -427,18 +391,12 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_select_under_fields_for_with_auto_index - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" def @post.to_param; 815; end fields_for "post[]", @post do |f| - concat f.collection_select(:author_name, @posts, :author_name, :author_name) + concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name) end assert_dom_equal( @@ -448,69 +406,45 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_select_with_blank_and_style - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" assert_dom_equal( "", - collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") + collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") ) end def test_collection_select_with_blank_as_string_and_style - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" assert_dom_equal( "", - collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px") + collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px") ) end def test_collection_select_with_multiple_option_appends_array_brackets - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" expected = "" # Should suffix default name with []. - assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, :multiple => true) + assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, :multiple => true) # Shouldn't suffix custom name with []. - assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) + assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) end def test_collection_select_with_blank_and_selected - @posts = [ - Post.new(" went home", "", "To a little house", "shh!"), - Post.new("Babe went home", "Babe", "To a little house", "shh!"), - Post.new("Cabe went home", "Cabe", "To a little house", "shh!") - ] - @post = Post.new @post.author_name = "Babe" assert_dom_equal( %{}, - collection_select("post", "author_name", @posts, "author_name", "author_name", {:include_blank => true, :selected => ""}) + collection_select("post", "author_name", dummy_posts, "author_name", "author_name", {:include_blank => true, :selected => ""}) ) end @@ -723,4 +657,11 @@ class FormOptionsHelperTest < ActionView::TestCase html end + private + + def dummy_posts + [ Post.new(" went home", "", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ] + end end -- cgit v1.2.3 From 1525f3816e9b51d93d2e1356d1b90ba49213d325 Mon Sep 17 00:00:00 2001 From: Tekin Suleyman Date: Sat, 14 Feb 2009 00:37:24 +0000 Subject: Enhanced form option helpers to add support for disabled option tags and use of anonymous functions for specifying selected and disabled values from collections. Signed-off-by: Michael Koziarski --- .../test/template/form_options_helper_test.rb | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 2dbd2ecdd4..78db87971b 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -45,6 +45,41 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_collection_options_with_proc_for_selected + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", lambda{|p| p.author_name == 'Babe' }) + ) + end + + def test_collection_options_with_disabled_value + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => "Babe") + ) + end + + def test_collection_options_with_disabled_array + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => [ "Babe", "Cabe" ]) + ) + end + + def test_collection_options_with_preselected_and_disabled_value + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :selected => "Cabe", :disabled => "Babe") + ) + end + + def test_collection_options_with_proc_for_disabled + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| %w(Babe Cabe).include? p.author_name }) + ) + end + def test_array_options_for_select assert_dom_equal( "\n\n", @@ -66,6 +101,27 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_array_options_for_select_with_disabled_value + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], :disabled => "") + ) + end + + def test_array_options_for_select_with_disabled_array + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], :disabled => ["", "Sweden"]) + ) + end + + def test_array_options_for_select_with_selection_and_disabled_value + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], :selected => "Denmark", :disabled => "") + ) + end + def test_array_options_for_string_include_in_other_string_bug_fix assert_dom_equal( "\n", @@ -352,6 +408,24 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_disabled_value + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest ), :disabled => 'hest') + ) + end + + def test_select_with_disabled_array + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest ), :disabled => ['hest', 'abe']) + ) + end + def test_collection_select @post = Post.new @post.author_name = "Babe" @@ -448,6 +522,16 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_collection_select_with_disabled + @post = Post.new + @post.author_name = "Babe" + + assert_dom_equal( + "", + collection_select("post", "author_name", dummy_posts, "author_name", "author_name", :disabled => 'Cabe') + ) + end + def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) -- cgit v1.2.3 From f8ea9f85d4f1e3e6f3b5d895bef6b013aa4b0690 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 19 Feb 2009 20:55:56 -0600 Subject: Fix templates reloading in development when using custom view path [#2012 state:resolved] --- .../test/template/compiled_templates_test.rb | 128 +++++++++++++++++---- 1 file changed, 103 insertions(+), 25 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index a8f8455a54..7d1d7634a8 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -5,18 +5,6 @@ class CompiledTemplatesTest < Test::Unit::TestCase def setup @compiled_templates = ActionView::Base::CompiledTemplates - - # first, if we are running the whole test suite with ReloadableTemplates - # try to undef all the methods through ReloadableTemplate's interfaces - unless ActionView::Base.cache_template_loading? - ActionController::Base.view_paths.each do |view_path| - view_path.paths.values.uniq!.each do |reloadable_template| - reloadable_template.undef_my_compiled_methods! - end - end - end - - # just purge anything that's left @compiled_templates.instance_methods.each do |m| @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ end @@ -65,38 +53,124 @@ class CompiledTemplatesTest < Test::Unit::TestCase with_reloading(true) do assert_equal "Hello world!", render(:file => "test/hello_world.erb") modify_template "test/hello_world.erb", "Goodbye world!" do - reset_mtime_of('test/hello_world.erb') assert_equal "Goodbye world!", render(:file => "test/hello_world.erb") end - reset_mtime_of('test/hello_world.erb') assert_equal "Hello world!", render(:file => "test/hello_world.erb") end end end + def test_template_becomes_missing_if_deleted_without_cached_template_loading + with_reloading(true) do + assert_equal 'Hello world!', render(:file => 'test/hello_world.erb') + delete_template 'test/hello_world.erb' do + assert_raise(ActionView::MissingTemplate) { render(:file => 'test/hello_world.erb') } + end + assert_equal 'Hello world!', render(:file => 'test/hello_world.erb') + end + end + + def test_swapping_template_handler_is_working_without_cached_template_loading + with_reloading(true) do + assert_equal 'Hello world!', render(:file => 'test/hello_world') + delete_template 'test/hello_world.erb' do + rename_template 'test/hello_world_from_rxml.builder', 'test/hello_world.builder' do + assert_equal "\n

Hello

\n\n", render(:file => 'test/hello_world') + end + end + assert_equal 'Hello world!', render(:file => 'test/hello_world') + end + end + + def test_adding_localized_template_will_take_precedence_without_cached_template_loading + with_reloading(true) do + assert_equal 'Hello world!', render(:file => 'test/hello_world') + rename_template 'test/hello_world.da.html.erb', 'test/hello_world.en.html.erb' do + assert_equal 'Hey verden', render(:file => 'test/hello_world') + end + end + end + + def test_deleting_localized_template_will_fall_back_to_non_localized_template_without_cached_template_loading + with_reloading(true) do + rename_template 'test/hello_world.da.html.erb', 'test/hello_world.en.html.erb' do + assert_equal 'Hey verden', render(:file => 'test/hello_world') + delete_template 'test/hello_world.en.html.erb' do + assert_equal 'Hello world!', render(:file => 'test/hello_world') + end + assert_equal 'Hey verden', render(:file => 'test/hello_world') + end + end + end + + def test_parallel_reloadable_view_paths_are_working + with_reloading(true) do + view_paths_copy = new_reloadable_view_paths + assert_equal 'Hello world!', render(:file => 'test/hello_world') + with_view_paths(view_paths_copy, new_reloadable_view_paths) do + assert_equal 'Hello world!', render(:file => 'test/hello_world') + end + modify_template 'test/hello_world.erb', 'Goodbye world!' do + assert_equal 'Goodbye world!', render(:file => 'test/hello_world') + modify_template 'test/hello_world.erb', 'So long, world!' do + with_view_paths(view_paths_copy, new_reloadable_view_paths) do + assert_equal 'So long, world!', render(:file => 'test/hello_world') + end + assert_equal 'So long, world!', render(:file => 'test/hello_world') + end + end + end + end + private def render(*args) - view_paths = ActionController::Base.view_paths + view_paths = @explicit_view_paths || ActionController::Base.view_paths ActionView::Base.new(view_paths, {}).render(*args) end - def reset_mtime_of(template_name) - unless ActionView::Base.cache_template_loading? - ActionController::Base.view_paths.find_template(template_name).previously_last_modified = 10.seconds.ago + def with_view_paths(*args) + args.each do |view_paths| + begin + @explicit_view_paths = view_paths + yield + ensure + @explicit_view_paths = nil + end end end - def modify_template(template, content) - filename = "#{FIXTURE_LOAD_PATH}/#{template}" + def reset_mtime_of(template_name, view_paths_to_use) + view_paths_to_use.find_template(template_name).previously_last_modified = 10.seconds.ago unless ActionView::Base.cache_template_loading? + end + + def modify_template(template, content, view_paths_to_use = ActionController::Base.view_paths) + filename = filename_for(template) old_content = File.read(filename) begin File.open(filename, "wb+") { |f| f.write(content) } + reset_mtime_of(template, view_paths_to_use) yield ensure File.open(filename, "wb+") { |f| f.write(old_content) } + reset_mtime_of(template, view_paths_to_use) end end + def filename_for(template) + File.join(FIXTURE_LOAD_PATH, template) + end + + def rename_template(old_name, new_name) + File.rename(filename_for(old_name), filename_for(new_name)) + yield + ensure + File.rename(filename_for(new_name), filename_for(old_name)) + end + + def delete_template(template, &block) + rename_template(template, File.join(File.dirname(template), "__#{File.basename(template)}"), &block) + end + def with_caching(perform_caching) old_perform_caching = ActionController::Base.perform_caching begin @@ -107,19 +181,23 @@ class CompiledTemplatesTest < Test::Unit::TestCase end end - def with_reloading(reload_templates) - old_view_paths, old_cache_templates = ActionController::Base.view_paths, ActionView::Base.cache_template_loading + def with_reloading(reload_templates, view_paths_owner = ActionController::Base) + old_view_paths, old_cache_templates = view_paths_owner.view_paths, ActionView::Base.cache_template_loading begin ActionView::Base.cache_template_loading = !reload_templates - ActionController::Base.view_paths = view_paths_for(reload_templates) + view_paths_owner.view_paths = view_paths_for(reload_templates) yield ensure - ActionController::Base.view_paths, ActionView::Base.cache_template_loading = old_view_paths, old_cache_templates + view_paths_owner.view_paths, ActionView::Base.cache_template_loading = old_view_paths, old_cache_templates end end + def new_reloadable_view_paths + ActionView::PathSet.new(CACHED_VIEW_PATHS.map(&:to_s)) + end + def view_paths_for(reload_templates) # reloadable paths are cheap to create - reload_templates ? ActionView::PathSet.new(CACHED_VIEW_PATHS.map(&:to_s)) : CACHED_VIEW_PATHS + reload_templates ? new_reloadable_view_paths : CACHED_VIEW_PATHS end end -- cgit v1.2.3 From 85df4841ddb3db3970fa9e798de698cf6f16752a Mon Sep 17 00:00:00 2001 From: thedarkone Date: Tue, 24 Feb 2009 10:41:45 -0600 Subject: Template without a known template handler should only be reachable through its exact path. [#2027 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/render_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 107c625e32..de7fa3de65 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -224,6 +224,16 @@ module RenderTestCases assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + def test_render_ignores_templates_with_malformed_template_handlers + %w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name| + assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") } + end + end + + def test_template_with_malformed_template_handler_is_reachable_trough_its_exact_filename + assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~') + end + def test_render_with_layout assert_equal %(\nHello world!\n), @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") -- cgit v1.2.3 From 3d1d422b8be027417cb640416d154171e75f03d1 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Thu, 26 Feb 2009 12:26:17 +0100 Subject: Pass a custom form builder on to nested fields_for calls. [#2023 status:committed] Signed-off-by: David Heinemeier Hansson --- actionpack/test/template/form_helper_test.rb | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 5cc81b4afb..654eee40a3 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1001,6 +1001,47 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_labelled_builder_with_nested_fields_for_without_options_hash + klass = nil + + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + f.fields_for(:comments, Comment.new) do |nested_fields| + klass = nested_fields.class + '' + end + end + + assert_equal LabelledFormBuilder, klass + end + + def test_form_for_with_labelled_builder_with_nested_fields_for_with_options_hash + klass = nil + + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + f.fields_for(:comments, Comment.new, :index => 'foo') do |nested_fields| + klass = nested_fields.class + '' + end + end + + assert_equal LabelledFormBuilder, klass + end + + class LabelledFormBuilderSubclass < LabelledFormBuilder; end + + def test_form_for_with_labelled_builder_with_nested_fields_for_with_custom_builder + klass = nil + + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + f.fields_for(:comments, Comment.new, :builder => LabelledFormBuilderSubclass) do |nested_fields| + klass = nested_fields.class + '' + end + end + + assert_equal LabelledFormBuilderSubclass, klass + end + def test_form_for_with_html_options_adds_options_to_form_tag form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end expected = "
" -- cgit v1.2.3 From dcd9c7f58e7194c026145273c7695cf968569d33 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Sat, 28 Feb 2009 09:21:56 -0600 Subject: Fix spelling in test name. Signed-off-by: Pratik Naik --- actionpack/test/template/render_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index de7fa3de65..b042eb3d9b 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -230,7 +230,7 @@ module RenderTestCases end end - def test_template_with_malformed_template_handler_is_reachable_trough_its_exact_filename + def test_template_with_malformed_template_handler_is_reachable_through_its_exact_filename assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~') end -- cgit v1.2.3 From 45494580d9405e80ba124d17c8379436883c8c78 Mon Sep 17 00:00:00 2001 From: Dan Barry Date: Sat, 7 Mar 2009 18:55:12 +0000 Subject: =?UTF-8?q?Ensure=20Active=20Record=20error=20related=20view=20hel?= =?UTF-8?q?pers=20escape=20the=20message=20[#1280=20state:resolved]=20[Ing?= =?UTF-8?q?e=20J=C3=B8rgensen,=20Dan=20Barry]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pratik Naik --- .../test/template/active_record_helper_test.rb | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index e46f95d18b..83c028b5f2 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -19,6 +19,30 @@ class ActiveRecordHelperTest < ActionView::TestCase Column = Struct.new("Column", :type, :name, :human_name) end + class DirtyPost + class Errors + def empty? + false + end + + def count + 1 + end + + def full_messages + ["Author name can't be empty"] + end + + def on(field) + "can't be empty" + end + end + + def errors + Errors.new + end + end + def setup_post @post = Post.new def @post.errors @@ -195,10 +219,20 @@ class ActiveRecordHelperTest < ActionView::TestCase assert_equal %(

1 error prohibited this post from being saved

There were problems with the following fields:

  • Author name can't be empty
), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1") end + def test_error_messages_for_escapes_html + @dirty_post = DirtyPost.new + assert_dom_equal %(

1 error prohibited this dirty post from being saved

There were problems with the following fields:

  • Author name can't be <em>empty</em>
), error_messages_for("dirty_post") + end + def test_error_messages_for_handles_nil assert_equal "", error_messages_for("notthere") end + def test_error_message_on_escapes_html + @dirty_post = DirtyPost.new + assert_dom_equal "
can't be <em>empty</em>
", error_message_on(:dirty_post, :author_name) + end + def test_error_message_on_handles_nil assert_equal "", error_message_on("notthere", "notthere") end -- cgit v1.2.3 From 77f7d98e38dddf72890c80b4e4b2e088bb76d111 Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Sat, 7 Mar 2009 13:29:35 -0600 Subject: submit_tag with confirmation and disable_with [#660 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/form_tag_helper_test.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 0c8af60aa4..c713b8da8e 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -266,11 +266,18 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag_with_confirmation assert_dom_equal( - %(), + %(), submit_tag("Save", :confirm => "Are you sure?") ) end - + + def test_submit_tag_with_confirmation_and_with_disable_with + assert_dom_equal( + %(), + submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?") + ) + end + def test_image_submit_tag_with_confirmation assert_dom_equal( %(), -- cgit v1.2.3 From ea8488caef77cb8cf2031d344e74981ab6ea0e57 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 7 Mar 2009 14:05:18 -0600 Subject: Fixed simplified render with nested models [#2042 state:resolved] --- actionpack/test/template/render_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b042eb3d9b..9adf053b09 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -145,6 +145,10 @@ module RenderTestCases assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name end + def test_render_object + assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david")) + end + def test_render_partial_collection assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) end -- cgit v1.2.3 From 9b8cde41bc84466bf60fc4de6af54dbeb11cc0d6 Mon Sep 17 00:00:00 2001 From: Yury Kotlyarov Date: Thu, 5 Mar 2009 15:55:28 +0300 Subject: Remove duplicate test [#2136 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/javascript_helper_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index d41111127b..d2fb24e36e 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -45,11 +45,6 @@ class JavaScriptHelperTest < ActionView::TestCase link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') end - def test_link_to_function_with_href - assert_dom_equal %(Greeting), - link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') - end - def test_button_to_function assert_dom_equal %(), button_to_function("Greeting", "alert('Hello world!')") -- cgit v1.2.3 From 1c36172c13fc51b22167f5e8fc41b1da9f8fcb2a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 8 Mar 2009 13:11:58 -0700 Subject: Ruby 1.9 compat: rename deprecated assert_raises to assert_raise. [#1617 state:resolved] --- actionpack/test/template/url_helper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index e7799fb204..5900709d81 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -220,7 +220,7 @@ class UrlHelperTest < ActionView::TestCase end def test_link_tag_using_post_javascript_and_popup - assert_raises(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") } + assert_raise(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") } end def test_link_tag_using_block_in_erb -- cgit v1.2.3 From 1ab2ff58eddee8ac523624dd097424f9a760ad8b Mon Sep 17 00:00:00 2001 From: rpheath Date: Sun, 8 Mar 2009 23:52:28 -0400 Subject: Fixed number_to_phone to work with 7 digit numbers [#2176 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/number_helper_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 9c9f54936c..29cb60fd73 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -4,6 +4,7 @@ class NumberHelperTest < ActionView::TestCase tests ActionView::Helpers::NumberHelper def test_number_to_phone + assert_equal("555-1234", number_to_phone(5551234)) assert_equal("800-555-1212", number_to_phone(8005551212)) assert_equal("(800) 555-1212", number_to_phone(8005551212, {:area_code => true})) assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "})) -- cgit v1.2.3 From bdfa733d04c5843eadc181f2fd1723db614fc3d0 Mon Sep 17 00:00:00 2001 From: Eugene Pimenov Date: Tue, 10 Mar 2009 16:52:21 +0000 Subject: Ensure auto_link doesnt linkify URLs in the middle of a tag [#1523 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/text_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 564845779f..a370f1458f 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -375,6 +375,12 @@ class TextHelperTest < ActionView::TestCase assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}") end + def test_auto_link_in_tags + link_raw = 'http://www.rubyonrails.org/images/rails.png' + link_result = %Q() + assert_equal link_result, auto_link(link_result) + end + def test_auto_link_at_eol url1 = "http://api.rubyonrails.com/Foo.html" url2 = "http://www.ruby-doc.org/core/Bar.html" -- cgit v1.2.3 From 3d260760f035c5aab11ab218881ed36e3046157b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 00:25:05 -0700 Subject: Introduce flush_output_buffer to append the buffer to the response body then start a new buffer. Useful for pushing custom parts to the response body without disrupting template rendering. --- actionpack/test/template/output_buffer_test.rb | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 actionpack/test/template/output_buffer_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb new file mode 100644 index 0000000000..6d8eab63dc --- /dev/null +++ b/actionpack/test/template/output_buffer_test.rb @@ -0,0 +1,35 @@ +require 'abstract_unit' + +class OutputBufferTest < ActionController::TestCase + class TestController < ActionController::Base + def index + render :text => 'foo' + end + end + + tests TestController + + def test_flush_output_buffer + # Start with the default body parts + get :index + assert_equal ['foo'], @response.body_parts + assert_nil @response.template.output_buffer + + # Nil output buffer is skipped + @response.template.flush_output_buffer + assert_nil @response.template.output_buffer + assert_equal ['foo'], @response.body_parts + + # Empty output buffer is skipped + @response.template.output_buffer = '' + @response.template.flush_output_buffer + assert_equal '', @response.template.output_buffer + assert_equal ['foo'], @response.body_parts + + # Flushing appends the output buffer to the body parts + @response.template.output_buffer = 'bar' + @response.template.flush_output_buffer + assert_equal '', @response.template.output_buffer + assert_equal ['foo', 'bar'], @response.body_parts + end +end -- cgit v1.2.3 From 7c1714cbd0b37d1fc5ca2ac3e08980943454d516 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 02:36:00 -0700 Subject: Body parts: future rendering, threaded future, queued future, open-uri example --- actionpack/test/template/body_parts_test.rb | 142 +++++++++++++++++++++++++ actionpack/test/template/output_buffer_test.rb | 35 ------ 2 files changed, 142 insertions(+), 35 deletions(-) create mode 100644 actionpack/test/template/body_parts_test.rb delete mode 100644 actionpack/test/template/output_buffer_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb new file mode 100644 index 0000000000..d15c8808d9 --- /dev/null +++ b/actionpack/test/template/body_parts_test.rb @@ -0,0 +1,142 @@ +require 'abstract_unit' +require 'action_view/body_parts/queued' +require 'action_view/body_parts/open_uri' + +class OutputBufferTest < ActionController::TestCase + class TestController < ActionController::Base + def index + render :text => 'foo' + end + end + + tests TestController + + def test_flush_output_buffer + # Start with the default body parts + get :index + assert_equal ['foo'], @response.body_parts + assert_nil @response.template.output_buffer + + # Nil output buffer is skipped + @response.template.flush_output_buffer + assert_nil @response.template.output_buffer + assert_equal ['foo'], @response.body_parts + + # Empty output buffer is skipped + @response.template.output_buffer = '' + @response.template.flush_output_buffer + assert_equal '', @response.template.output_buffer + assert_equal ['foo'], @response.body_parts + + # Flushing appends the output buffer to the body parts + @response.template.output_buffer = 'bar' + @response.template.flush_output_buffer + assert_equal '', @response.template.output_buffer + assert_equal ['foo', 'bar'], @response.body_parts + end +end + +class QueuedPartTest < ActionController::TestCase + class SimpleQueued < ActionView::BodyParts::Queued + protected + def submit(job) + job + end + + def redeem(receipt) + receipt.to_s.reverse + end + end + + class TestController < ActionController::Base + def index + queued_render 'foo' + queued_render 'bar' + queued_render 'baz' + @performed_render = true + end + + def queued_render(job) + response.template.punctuate_body! SimpleQueued.new(job) + end + end + + tests TestController + + def test_queued_parts + get :index + assert_equal 'oofrabzab', @response.body + end +end + +class ThreadedPartTest < ActionController::TestCase + class TestController < ActionController::Base + def index + append_thread_id = lambda do |parts| + parts << Thread.current.object_id + parts << '::' + parts << Time.now.to_i + sleep 1 + end + + future_render &append_thread_id + response.body_parts << '-' + + future_render &append_thread_id + response.body_parts << '-' + + future_render do |parts| + parts << ActionView::BodyParts::Threaded.new(true, &append_thread_id) + parts << '-' + parts << ActionView::BodyParts::Threaded.new(true, &append_thread_id) + end + + @performed_render = true + end + + def future_render(&block) + response.template.punctuate_body! ActionView::BodyParts::Threaded.new(true, &block) + end + end + + tests TestController + + def test_concurrent_threaded_parts + get :index + + before = Time.now.to_i + thread_ids = @response.body.split('-').map { |part| part.split('::').first.to_i } + elapsed = Time.now.to_i - before + + assert_equal thread_ids.size, thread_ids.uniq.size + assert elapsed < 1.1 + end +end + +class OpenUriPartTest < ActionController::TestCase + class TestController < ActionController::Base + def index + render_url 'http://localhost/foo' + render_url 'http://localhost/bar' + render_url 'http://localhost/baz' + @performed_render = true + end + + def render_url(url) + url = URI.parse(url) + def url.read; path end + response.template.punctuate_body! ActionView::BodyParts::OpenUri.new(url) + end + end + + tests TestController + + def test_concurrent_open_uri_parts + get :index + + elapsed = Benchmark.ms do + assert_equal '/foo/bar/baz', @response.body + end + assert elapsed < 1.1 + end +end diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb deleted file mode 100644 index 6d8eab63dc..0000000000 --- a/actionpack/test/template/output_buffer_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'abstract_unit' - -class OutputBufferTest < ActionController::TestCase - class TestController < ActionController::Base - def index - render :text => 'foo' - end - end - - tests TestController - - def test_flush_output_buffer - # Start with the default body parts - get :index - assert_equal ['foo'], @response.body_parts - assert_nil @response.template.output_buffer - - # Nil output buffer is skipped - @response.template.flush_output_buffer - assert_nil @response.template.output_buffer - assert_equal ['foo'], @response.body_parts - - # Empty output buffer is skipped - @response.template.output_buffer = '' - @response.template.flush_output_buffer - assert_equal '', @response.template.output_buffer - assert_equal ['foo'], @response.body_parts - - # Flushing appends the output buffer to the body parts - @response.template.output_buffer = 'bar' - @response.template.flush_output_buffer - assert_equal '', @response.template.output_buffer - assert_equal ['foo', 'bar'], @response.body_parts - end -end -- cgit v1.2.3 From 5d76dee329282acc918de50fecde869f1431e2f1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 02:55:24 -0700 Subject: Example using an edge side include body part to fetch queued rendering results --- actionpack/test/template/body_parts_test.rb | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index d15c8808d9..88f09af94f 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -36,28 +36,36 @@ class OutputBufferTest < ActionController::TestCase end end + class QueuedPartTest < ActionController::TestCase - class SimpleQueued < ActionView::BodyParts::Queued + class EdgeSideInclude < ActionView::BodyParts::Queued + QUEUE_REDEMPTION_URL = 'http://queue/jobs/%s' + ESI_INCLUDE_TAG = '' + + def self.redemption_tag(receipt) + ESI_INCLUDE_TAG % QUEUE_REDEMPTION_URL % receipt + end + protected def submit(job) - job + job.reverse end def redeem(receipt) - receipt.to_s.reverse + self.class.redemption_tag(receipt) end end class TestController < ActionController::Base def index - queued_render 'foo' - queued_render 'bar' - queued_render 'baz' + edge_side_include 'foo' + edge_side_include 'bar' + edge_side_include 'baz' @performed_render = true end - def queued_render(job) - response.template.punctuate_body! SimpleQueued.new(job) + def edge_side_include(job) + response.template.punctuate_body! EdgeSideInclude.new(job) end end @@ -65,10 +73,12 @@ class QueuedPartTest < ActionController::TestCase def test_queued_parts get :index - assert_equal 'oofrabzab', @response.body + expected = %(oof rab zab).map { |receipt| EdgeSideInclude.redemption_tag(receipt) } + assert_equal expected, @response.body end end + class ThreadedPartTest < ActionController::TestCase class TestController < ActionController::Base def index @@ -113,7 +123,15 @@ class ThreadedPartTest < ActionController::TestCase end end + class OpenUriPartTest < ActionController::TestCase + class OpenUri < ActionView::BodyParts::Threaded + def initialize(url) + url = URI::Generic === url ? url : URI.parse(url) + super(true) { |parts| parts << url.read } + end + end + class TestController < ActionController::Base def index render_url 'http://localhost/foo' -- cgit v1.2.3 From d54d97b07c1b258f42210b1a3fc2e8c56e434ee9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 03:01:47 -0700 Subject: Fix tests --- actionpack/test/template/body_parts_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 88f09af94f..7418f4a716 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'action_view/body_parts/queued' -require 'action_view/body_parts/open_uri' +require 'action_view/body_parts/threaded' class OutputBufferTest < ActionController::TestCase class TestController < ActionController::Base @@ -73,7 +73,7 @@ class QueuedPartTest < ActionController::TestCase def test_queued_parts get :index - expected = %(oof rab zab).map { |receipt| EdgeSideInclude.redemption_tag(receipt) } + expected = %w(oof rab zab).map { |receipt| EdgeSideInclude.redemption_tag(receipt) }.join assert_equal expected, @response.body end end @@ -125,7 +125,7 @@ end class OpenUriPartTest < ActionController::TestCase - class OpenUri < ActionView::BodyParts::Threaded + class OpenUriPart < ActionView::BodyParts::Threaded def initialize(url) url = URI::Generic === url ? url : URI.parse(url) super(true) { |parts| parts << url.read } @@ -143,7 +143,7 @@ class OpenUriPartTest < ActionController::TestCase def render_url(url) url = URI.parse(url) def url.read; path end - response.template.punctuate_body! ActionView::BodyParts::OpenUri.new(url) + response.template.punctuate_body! OpenUriPart.new(url) end end -- cgit v1.2.3 From b2f98c13a3308e6db618d6f3f9f706cbc19f13fd Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 03:16:14 -0700 Subject: Simplify parts and tests --- actionpack/test/template/body_parts_test.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 7418f4a716..4555a6b015 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -47,7 +47,7 @@ class QueuedPartTest < ActionController::TestCase end protected - def submit(job) + def enqueue(job) job.reverse end @@ -114,12 +114,11 @@ class ThreadedPartTest < ActionController::TestCase def test_concurrent_threaded_parts get :index - before = Time.now.to_i - thread_ids = @response.body.split('-').map { |part| part.split('::').first.to_i } - elapsed = Time.now.to_i - before - - assert_equal thread_ids.size, thread_ids.uniq.size - assert elapsed < 1.1 + elapsed = Benchmark.ms do + thread_ids = @response.body.split('-').map { |part| part.split('::').first.to_i } + assert_equal thread_ids.size, thread_ids.uniq.size + end + assert (elapsed - 1000).abs < 100, elapsed end end @@ -142,7 +141,7 @@ class OpenUriPartTest < ActionController::TestCase def render_url(url) url = URI.parse(url) - def url.read; path end + def url.read; sleep 1; path end response.template.punctuate_body! OpenUriPart.new(url) end end @@ -155,6 +154,6 @@ class OpenUriPartTest < ActionController::TestCase elapsed = Benchmark.ms do assert_equal '/foo/bar/baz', @response.body end - assert elapsed < 1.1 + assert (elapsed - 1000).abs < 100, elapsed end end -- cgit v1.2.3 From 2f998fc81fd3525e4f19ba55937ee423c4b71856 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 03:23:13 -0700 Subject: Extract output buffer test --- actionpack/test/template/body_parts_test.rb | 34 ------------------------- actionpack/test/template/output_buffer_test.rb | 35 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 actionpack/test/template/output_buffer_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 4555a6b015..aece24635c 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -2,40 +2,6 @@ require 'abstract_unit' require 'action_view/body_parts/queued' require 'action_view/body_parts/threaded' -class OutputBufferTest < ActionController::TestCase - class TestController < ActionController::Base - def index - render :text => 'foo' - end - end - - tests TestController - - def test_flush_output_buffer - # Start with the default body parts - get :index - assert_equal ['foo'], @response.body_parts - assert_nil @response.template.output_buffer - - # Nil output buffer is skipped - @response.template.flush_output_buffer - assert_nil @response.template.output_buffer - assert_equal ['foo'], @response.body_parts - - # Empty output buffer is skipped - @response.template.output_buffer = '' - @response.template.flush_output_buffer - assert_equal '', @response.template.output_buffer - assert_equal ['foo'], @response.body_parts - - # Flushing appends the output buffer to the body parts - @response.template.output_buffer = 'bar' - @response.template.flush_output_buffer - assert_equal '', @response.template.output_buffer - assert_equal ['foo', 'bar'], @response.body_parts - end -end - class QueuedPartTest < ActionController::TestCase class EdgeSideInclude < ActionView::BodyParts::Queued diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb new file mode 100644 index 0000000000..6d8eab63dc --- /dev/null +++ b/actionpack/test/template/output_buffer_test.rb @@ -0,0 +1,35 @@ +require 'abstract_unit' + +class OutputBufferTest < ActionController::TestCase + class TestController < ActionController::Base + def index + render :text => 'foo' + end + end + + tests TestController + + def test_flush_output_buffer + # Start with the default body parts + get :index + assert_equal ['foo'], @response.body_parts + assert_nil @response.template.output_buffer + + # Nil output buffer is skipped + @response.template.flush_output_buffer + assert_nil @response.template.output_buffer + assert_equal ['foo'], @response.body_parts + + # Empty output buffer is skipped + @response.template.output_buffer = '' + @response.template.flush_output_buffer + assert_equal '', @response.template.output_buffer + assert_equal ['foo'], @response.body_parts + + # Flushing appends the output buffer to the body parts + @response.template.output_buffer = 'bar' + @response.template.flush_output_buffer + assert_equal '', @response.template.output_buffer + assert_equal ['foo', 'bar'], @response.body_parts + end +end -- cgit v1.2.3 From 4a7b11d5d857a0f5ce6eb8af7a6dfcb94f31fcfa Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 18:49:53 -0700 Subject: Less ceremony --- actionpack/test/template/body_parts_test.rb | 61 ++++++++++++++++------------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index aece24635c..369756cbf5 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -1,37 +1,44 @@ require 'abstract_unit' -require 'action_view/body_parts/queued' -require 'action_view/body_parts/threaded' +require 'action_view/body_parts/concurrent_block' - -class QueuedPartTest < ActionController::TestCase - class EdgeSideInclude < ActionView::BodyParts::Queued - QUEUE_REDEMPTION_URL = 'http://queue/jobs/%s' +class BodyPartTest < ActionController::TestCase + module EdgeSideInclude + QUEUE_REDEMPTION_URL = 'http://render.farm/renderings/%s' ESI_INCLUDE_TAG = '' def self.redemption_tag(receipt) ESI_INCLUDE_TAG % QUEUE_REDEMPTION_URL % receipt end - protected - def enqueue(job) - job.reverse + class BodyPart + def initialize(rendering) + @receipt = enqueue(rendering) end - def redeem(receipt) - self.class.redemption_tag(receipt) + def to_s + EdgeSideInclude.redemption_tag(@receipt) end + + protected + # Pretend we sent this rendering off for processing. + def enqueue(rendering) + rendering.object_id.to_s + end + end end class TestController < ActionController::Base + RENDERINGS = [Object.new, Object.new, Object.new] + def index - edge_side_include 'foo' - edge_side_include 'bar' - edge_side_include 'baz' + RENDERINGS.each do |rendering| + edge_side_include rendering + end @performed_render = true end - def edge_side_include(job) - response.template.punctuate_body! EdgeSideInclude.new(job) + def edge_side_include(rendering) + response.template.punctuate_body! EdgeSideInclude::BodyPart.new(rendering) end end @@ -39,20 +46,20 @@ class QueuedPartTest < ActionController::TestCase def test_queued_parts get :index - expected = %w(oof rab zab).map { |receipt| EdgeSideInclude.redemption_tag(receipt) }.join + expected = TestController::RENDERINGS.map { |rendering| EdgeSideInclude.redemption_tag(rendering.object_id) }.join assert_equal expected, @response.body end end -class ThreadedPartTest < ActionController::TestCase +class ConcurrentBlockPartTest < ActionController::TestCase class TestController < ActionController::Base def index append_thread_id = lambda do |parts| parts << Thread.current.object_id parts << '::' parts << Time.now.to_i - sleep 1 + sleep 0.1 end future_render &append_thread_id @@ -62,16 +69,16 @@ class ThreadedPartTest < ActionController::TestCase response.body_parts << '-' future_render do |parts| - parts << ActionView::BodyParts::Threaded.new(true, &append_thread_id) + parts << ActionView::BodyParts::ConcurrentBlock.new(&append_thread_id) parts << '-' - parts << ActionView::BodyParts::Threaded.new(true, &append_thread_id) + parts << ActionView::BodyParts::ConcurrentBlock.new(&append_thread_id) end @performed_render = true end def future_render(&block) - response.template.punctuate_body! ActionView::BodyParts::Threaded.new(true, &block) + response.template.punctuate_body! ActionView::BodyParts::ConcurrentBlock.new(&block) end end @@ -84,16 +91,16 @@ class ThreadedPartTest < ActionController::TestCase thread_ids = @response.body.split('-').map { |part| part.split('::').first.to_i } assert_equal thread_ids.size, thread_ids.uniq.size end - assert (elapsed - 1000).abs < 100, elapsed + assert (elapsed - 100).abs < 10, elapsed end end class OpenUriPartTest < ActionController::TestCase - class OpenUriPart < ActionView::BodyParts::Threaded + class OpenUriPart < ActionView::BodyParts::ConcurrentBlock def initialize(url) url = URI::Generic === url ? url : URI.parse(url) - super(true) { |parts| parts << url.read } + super() { |body| body << url.read } end end @@ -107,7 +114,7 @@ class OpenUriPartTest < ActionController::TestCase def render_url(url) url = URI.parse(url) - def url.read; sleep 1; path end + def url.read; sleep 0.1; path end response.template.punctuate_body! OpenUriPart.new(url) end end @@ -120,6 +127,6 @@ class OpenUriPartTest < ActionController::TestCase elapsed = Benchmark.ms do assert_equal '/foo/bar/baz', @response.body end - assert (elapsed - 1000).abs < 100, elapsed + assert (elapsed - 100).abs < 10, elapsed end end -- cgit v1.2.3 From 70e3dfb2e9f94396eb6525d13f9adccd3e845c3d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 16 Mar 2009 12:09:34 -0700 Subject: Pare down unit test --- actionpack/test/template/body_parts_test.rb | 42 +++++------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 369756cbf5..209f6ec1ff 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -1,57 +1,27 @@ require 'abstract_unit' require 'action_view/body_parts/concurrent_block' -class BodyPartTest < ActionController::TestCase - module EdgeSideInclude - QUEUE_REDEMPTION_URL = 'http://render.farm/renderings/%s' - ESI_INCLUDE_TAG = '' - - def self.redemption_tag(receipt) - ESI_INCLUDE_TAG % QUEUE_REDEMPTION_URL % receipt - end - - class BodyPart - def initialize(rendering) - @receipt = enqueue(rendering) - end - - def to_s - EdgeSideInclude.redemption_tag(@receipt) - end - - protected - # Pretend we sent this rendering off for processing. - def enqueue(rendering) - rendering.object_id.to_s - end - end - end +class BodyPartsTest < ActionController::TestCase + RENDERINGS = [Object.new, Object.new, Object.new] class TestController < ActionController::Base - RENDERINGS = [Object.new, Object.new, Object.new] - def index RENDERINGS.each do |rendering| - edge_side_include rendering + response.template.punctuate_body! rendering end @performed_render = true end - - def edge_side_include(rendering) - response.template.punctuate_body! EdgeSideInclude::BodyPart.new(rendering) - end end tests TestController - def test_queued_parts + def test_body_parts get :index - expected = TestController::RENDERINGS.map { |rendering| EdgeSideInclude.redemption_tag(rendering.object_id) }.join - assert_equal expected, @response.body + assert_equal RENDERINGS, @response.body_parts + assert_equal RENDERINGS.join, @response.body end end - class ConcurrentBlockPartTest < ActionController::TestCase class TestController < ActionController::Base def index -- cgit v1.2.3 From 0d5b50ee3a6d65471f311980b9b6e49fe4b4a021 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 19 Mar 2009 03:30:01 -0700 Subject: pluginize concurrent block body part --- actionpack/test/template/body_parts_test.rb | 80 ----------------------------- 1 file changed, 80 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 209f6ec1ff..4c82b75cdc 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'action_view/body_parts/concurrent_block' class BodyPartsTest < ActionController::TestCase RENDERINGS = [Object.new, Object.new, Object.new] @@ -21,82 +20,3 @@ class BodyPartsTest < ActionController::TestCase assert_equal RENDERINGS.join, @response.body end end - -class ConcurrentBlockPartTest < ActionController::TestCase - class TestController < ActionController::Base - def index - append_thread_id = lambda do |parts| - parts << Thread.current.object_id - parts << '::' - parts << Time.now.to_i - sleep 0.1 - end - - future_render &append_thread_id - response.body_parts << '-' - - future_render &append_thread_id - response.body_parts << '-' - - future_render do |parts| - parts << ActionView::BodyParts::ConcurrentBlock.new(&append_thread_id) - parts << '-' - parts << ActionView::BodyParts::ConcurrentBlock.new(&append_thread_id) - end - - @performed_render = true - end - - def future_render(&block) - response.template.punctuate_body! ActionView::BodyParts::ConcurrentBlock.new(&block) - end - end - - tests TestController - - def test_concurrent_threaded_parts - get :index - - elapsed = Benchmark.ms do - thread_ids = @response.body.split('-').map { |part| part.split('::').first.to_i } - assert_equal thread_ids.size, thread_ids.uniq.size - end - assert (elapsed - 100).abs < 10, elapsed - end -end - - -class OpenUriPartTest < ActionController::TestCase - class OpenUriPart < ActionView::BodyParts::ConcurrentBlock - def initialize(url) - url = URI::Generic === url ? url : URI.parse(url) - super() { |body| body << url.read } - end - end - - class TestController < ActionController::Base - def index - render_url 'http://localhost/foo' - render_url 'http://localhost/bar' - render_url 'http://localhost/baz' - @performed_render = true - end - - def render_url(url) - url = URI.parse(url) - def url.read; sleep 0.1; path end - response.template.punctuate_body! OpenUriPart.new(url) - end - end - - tests TestController - - def test_concurrent_open_uri_parts - get :index - - elapsed = Benchmark.ms do - assert_equal '/foo/bar/baz', @response.body - end - assert (elapsed - 100).abs < 10, elapsed - end -end -- cgit v1.2.3 From ae9f258e03c9fd5088da12c1c6cd216cc89a01f7 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Tue, 24 Mar 2009 10:48:47 -0500 Subject: Fix template extension parsing. [#2315 state:resolved] [#2284 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/template_test.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 actionpack/test/template/template_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb new file mode 100644 index 0000000000..7caec7ad9f --- /dev/null +++ b/actionpack/test/template/template_test.rb @@ -0,0 +1,32 @@ +require 'abstract_unit' + +class TemplateTest < Test::Unit::TestCase + def test_template_path_parsing + with_options :base_path => nil, :name => 'abc', :locale => nil, :format => 'html', :extension => 'erb' do |t| + t.assert_parses_template_path 'abc.en.html.erb', :locale => 'en' + t.assert_parses_template_path 'abc.en.plain.html.erb', :locale => 'en', :format => 'plain.html' + t.assert_parses_template_path 'abc.html.erb' + t.assert_parses_template_path 'abc.plain.html.erb', :format => 'plain.html' + t.assert_parses_template_path 'abc.erb', :format => nil + t.assert_parses_template_path 'abc.html', :extension => nil + + t.assert_parses_template_path '_abc.html.erb', :name => '_abc' + + t.assert_parses_template_path 'test/abc.html.erb', :base_path => 'test' + t.assert_parses_template_path './test/abc.html.erb', :base_path => './test' + t.assert_parses_template_path '../test/abc.html.erb', :base_path => '../test' + + t.assert_parses_template_path 'abc', :extension => nil, :format => nil, :name => nil + t.assert_parses_template_path 'abc.xxx', :extension => nil, :format => 'xxx', :name => 'abc' + t.assert_parses_template_path 'abc.html.xxx', :extension => nil, :format => 'xxx', :name => 'abc' + end + end + + private + def assert_parses_template_path(path, parse_results) + template = ActionView::Template.new(path, '') + parse_results.each_pair do |k, v| + assert_block(%Q{Expected template to parse #{k.inspect} from "#{path}" as #{v.inspect}, but got #{template.send(k).inspect}}) { v == template.send(k) } + end + end +end -- cgit v1.2.3 From 44423126c6f6133a1d9cf1d0832b527e8711d40f Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Thu, 2 Apr 2009 11:58:29 -0500 Subject: Additional template render test for backup files [#2367 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/render_test.rb | 6 ++++++ actionpack/test/template/template_test.rb | 2 ++ 2 files changed, 8 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 9adf053b09..80fd549fd7 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -255,6 +255,12 @@ module RenderTestCases assert_equal Encoding::UTF_8, result.encoding end end + + def test_render_with_backup_files + result = @view.render :file => "/test/backup_files/item" + assert_equal "The correct item.erb was loaded.\n", result + end + end module TemplatesSetupTeardown diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 7caec7ad9f..5c6523201b 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -19,6 +19,8 @@ class TemplateTest < Test::Unit::TestCase t.assert_parses_template_path 'abc', :extension => nil, :format => nil, :name => nil t.assert_parses_template_path 'abc.xxx', :extension => nil, :format => 'xxx', :name => 'abc' t.assert_parses_template_path 'abc.html.xxx', :extension => nil, :format => 'xxx', :name => 'abc' + + t.assert_parses_template_path 'abc.html.erb.orig', :format => 'orig', :extension => nil end end -- cgit v1.2.3 From 1ab7c37671d7c0cd9d8698bd462916a7e6f95470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 1 Apr 2009 11:24:00 +0200 Subject: Object names with underscore do the wrong lookup in I18n on error_messages_for. Signed-off-by: Michael Koziarski [#2390 state:committed] --- actionpack/test/template/active_record_helper_i18n_test.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index 4b6e8ddcca..9d04c882c8 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -4,9 +4,12 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase include ActionView::Helpers::ActiveRecordHelper attr_reader :request + def setup @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) - @object_name = 'book' + @object_name = 'book_seller' + @object_name_without_underscore = 'book seller' + stubs(:content_tag).returns 'content_tag' I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved" @@ -37,8 +40,8 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase end def test_error_messages_for_given_object_name_it_translates_object_name - I18n.expects(:t).with(:header, :locale => 'en', :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 + I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name_without_underscore).returns "1 error prohibited this #{@object_name_without_underscore} from being saved" + I18n.expects(:t).with(@object_name, :default => @object_name_without_underscore, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name_without_underscore error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name) end end -- cgit v1.2.3