From 542ddde5d49d9152c544f1f7483852dc8d4fc925 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 23 Sep 2009 23:03:24 -0500 Subject: Move helpers specific to functional tests out of TestProcess into AC::TestCase --- actionpack/test/template/url_helper_test.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 447d520ef1..ce99482078 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -5,8 +5,6 @@ require 'controller/fake_controllers' RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env) class UrlHelperTest < ActionView::TestCase - tests ActionView::Helpers::UrlHelper - def setup super @controller = Class.new do @@ -386,9 +384,7 @@ class UrlHelperController < ActionController::Base def rescue_action(e) raise e end end -class UrlHelperWithControllerTest < ActionView::TestCase - tests ActionView::Helpers::UrlHelper - +class UrlHelperWithControllerTest < ActionController::TestCase def setup super @request = ActionController::TestRequest.new @@ -463,9 +459,7 @@ class TasksController < ActionController::Base end end -class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase - tests ActionView::Helpers::UrlHelper - +class LinkToUnlessCurrentWithControllerTest < ActionController::TestCase def setup super @request = ActionController::TestRequest.new @@ -566,9 +560,7 @@ class SessionsController < ActionController::Base def rescue_action(e) raise e end end -class PolymorphicControllerTest < ActionView::TestCase - tests ActionView::Helpers::UrlHelper - +class PolymorphicControllerTest < ActionController::TestCase def setup super @request = ActionController::TestRequest.new -- cgit v1.2.3 From 0bd6e933c01868db7c7e20d46c972c4e7395b743 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 24 Sep 2009 18:36:40 -0700 Subject: Restore split between require-time and runtime load path mungery. Simplifies vendor requires. --- actionpack/test/template/form_options_helper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 f3cdab05bf..aa40e46aa8 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/vendor/tzinfo' +require 'tzinfo' TZInfo::Timezone.cattr_reader :loaded_zones -- cgit v1.2.3 From 8ef1cd9733cd12fc4e5ea25c149956a33fdffa70 Mon Sep 17 00:00:00 2001 From: Jay Pignata Date: Fri, 4 Sep 2009 12:43:17 -0400 Subject: Enhancing distance_of_time_in_words to prefix year output with over and about depending upon how many months have elapsed Signed-off-by: Michael Koziarski [#3106 state:committed] --- actionpack/test/template/date_helper_test.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 2e4763f446..51a340d907 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -69,13 +69,14 @@ class DateHelperTest < ActionView::TestCase assert_equal "2 months", distance_of_time_in_words(from, to + 59.days + 23.hours + 59.minutes + 30.seconds) assert_equal "12 months", distance_of_time_in_words(from, to + 1.years - 31.seconds) - # 525600..1051199 + # > 525599 assert_equal "about 1 year", distance_of_time_in_words(from, to + 1.years - 30.seconds) - assert_equal "about 1 year", distance_of_time_in_words(from, to + 2.years - 31.seconds) - - # > 1051199 - assert_equal "over 2 years", distance_of_time_in_words(from, to + 2.years + 30.seconds) - assert_equal "over 10 years", distance_of_time_in_words(from, to + 10.years) + assert_equal "about 1 year", distance_of_time_in_words(from, to + 1.years + 6.months - 1.day) + assert_equal "over 1 year", distance_of_time_in_words(from, to + 1.years + 6.months) + assert_equal "about 2 years", distance_of_time_in_words(from, to + 2.years + 30.seconds) + assert_equal "about 5 years", distance_of_time_in_words(from, to + 5.years + 5.months) + assert_equal "over 5 years", distance_of_time_in_words(from, to + 5.years + 6.months) + assert_equal "about 10 years", distance_of_time_in_words(from, to + 10.years) # test to < from assert_equal "about 4 hours", distance_of_time_in_words(from + 4.hours, to) @@ -104,7 +105,7 @@ class DateHelperTest < ActionView::TestCase def test_distance_in_words_with_dates start_date = Date.new 1975, 1, 31 end_date = Date.new 1977, 1, 31 - assert_equal("over 2 years", distance_of_time_in_words(start_date, end_date)) + assert_equal("about 2 years", distance_of_time_in_words(start_date, end_date)) end def test_distance_in_words_with_integers -- cgit v1.2.3 From c9318e9010712aeae33b1dd0e8bed4795ae37caf Mon Sep 17 00:00:00 2001 From: John Trupiano Date: Sat, 26 Sep 2009 15:42:18 -0400 Subject: Introduce :almost keyword for distance_of_time_in_words. Make 1.75 days - 2 days return '2 days'. Signed-off-by: Michael Koziarski [#3266 state:committed] --- actionpack/test/template/date_helper_i18n_test.rb | 19 +++++------ actionpack/test/template/date_helper_test.rb | 39 ++++++++++++++++------- 2 files changed, 37 insertions(+), 21 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index bc011f59b8..b69a449617 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -20,15 +20,16 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase [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] + [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 + 6.months, false] => [:'over_x_years', 3], + [3.years + 10.months, false] => [:'almost_x_years', 4] }.each do |passed, expected| assert_distance_of_time_in_words_translates_key passed, expected diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 51a340d907..9fb2080f77 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -53,13 +53,14 @@ class DateHelperTest < ActionView::TestCase assert_equal "about 2 hours", distance_of_time_in_words(from, to + 89.minutes + 30.seconds) assert_equal "about 24 hours", distance_of_time_in_words(from, to + 23.hours + 59.minutes + 29.seconds) - # 1440..2879 + # 1440..2529 assert_equal "1 day", distance_of_time_in_words(from, to + 23.hours + 59.minutes + 30.seconds) - assert_equal "1 day", distance_of_time_in_words(from, to + 47.hours + 59.minutes + 29.seconds) + assert_equal "1 day", distance_of_time_in_words(from, to + 41.hours + 59.minutes + 29.seconds) - # 2880..43199 - assert_equal "2 days", distance_of_time_in_words(from, to + 47.hours + 59.minutes + 30.seconds) - assert_equal "29 days", distance_of_time_in_words(from, to + 29.days + 23.hours + 59.minutes + 29.seconds) + # 2530..43199 + assert_equal "2 days", distance_of_time_in_words(from, to + 42.hours + 59.minutes + 30.seconds) + assert_equal "3 days", distance_of_time_in_words(from, to + 2.days + 12.hours) + assert_equal "30 days", distance_of_time_in_words(from, to + 29.days + 23.hours + 59.minutes + 29.seconds) # 43200..86399 assert_equal "about 1 month", distance_of_time_in_words(from, to + 29.days + 23.hours + 59.minutes + 30.seconds) @@ -70,13 +71,27 @@ class DateHelperTest < ActionView::TestCase assert_equal "12 months", distance_of_time_in_words(from, to + 1.years - 31.seconds) # > 525599 - assert_equal "about 1 year", distance_of_time_in_words(from, to + 1.years - 30.seconds) - assert_equal "about 1 year", distance_of_time_in_words(from, to + 1.years + 6.months - 1.day) - assert_equal "over 1 year", distance_of_time_in_words(from, to + 1.years + 6.months) - assert_equal "about 2 years", distance_of_time_in_words(from, to + 2.years + 30.seconds) - assert_equal "about 5 years", distance_of_time_in_words(from, to + 5.years + 5.months) - assert_equal "over 5 years", distance_of_time_in_words(from, to + 5.years + 6.months) - assert_equal "about 10 years", distance_of_time_in_words(from, to + 10.years) + assert_equal "about 1 year", distance_of_time_in_words(from, to + 1.years - 30.seconds) + assert_equal "about 1 year", distance_of_time_in_words(from, to + 1.years + 3.months - 1.day) + assert_equal "over 1 year", distance_of_time_in_words(from, to + 1.years + 6.months) + + assert_equal "almost 2 years", distance_of_time_in_words(from, to + 2.years - 3.months + 1.day) + assert_equal "about 2 years", distance_of_time_in_words(from, to + 2.years + 3.months - 1.day) + assert_equal "over 2 years", distance_of_time_in_words(from, to + 2.years + 3.months + 1.day) + assert_equal "over 2 years", distance_of_time_in_words(from, to + 2.years + 9.months - 1.day) + assert_equal "almost 3 years", distance_of_time_in_words(from, to + 2.years + 9.months + 1.day) + + assert_equal "almost 5 years", distance_of_time_in_words(from, to + 5.years - 3.months + 1.day) + assert_equal "about 5 years", distance_of_time_in_words(from, to + 5.years + 3.months - 1.day) + assert_equal "over 5 years", distance_of_time_in_words(from, to + 5.years + 3.months + 1.day) + assert_equal "over 5 years", distance_of_time_in_words(from, to + 5.years + 9.months - 1.day) + assert_equal "almost 6 years", distance_of_time_in_words(from, to + 5.years + 9.months + 1.day) + + assert_equal "almost 10 years", distance_of_time_in_words(from, to + 10.years - 3.months + 1.day) + assert_equal "about 10 years", distance_of_time_in_words(from, to + 10.years + 3.months - 1.day) + assert_equal "over 10 years", distance_of_time_in_words(from, to + 10.years + 3.months + 1.day) + assert_equal "over 10 years", distance_of_time_in_words(from, to + 10.years + 9.months - 1.day) + assert_equal "almost 11 years", distance_of_time_in_words(from, to + 10.years + 9.months + 1.day) # test to < from assert_equal "about 4 hours", distance_of_time_in_words(from + 4.hours, to) -- cgit v1.2.3 From 8ffc2e3b8de38c485fa24820208b40920dad7ae3 Mon Sep 17 00:00:00 2001 From: Erik Ostrom Date: Mon, 28 Sep 2009 13:31:30 -0500 Subject: Ported the new ActionView::TestCase from 2-3-stable to master [#3260 state:resolved] The test case now mimicks the template environment more closely, so it's possible to use render, load helper dependencies. This also fixes assert_select, and similar assertions. Because view tests and helpers generally don't render full templates assert_select looks first in rendered and then in output_buffer to find the rendered output. Additional `master'-only changes: Made the Action Pack Rakefile run the ActionView::TestCase tests, and made ActionView::Rendering#_render_text always return a string. Signed-off-by: Joshua Peek --- actionpack/test/template/active_record_helper_test.rb | 2 +- actionpack/test/template/benchmark_helper_test.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (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 ec3384f15d..c149070f2a 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -185,7 +185,7 @@ class ActiveRecordHelperTest < ActionView::TestCase end def test_form_with_action_option - @response.body = form("post", :action => "sign") + output_buffer << form("post", :action => "sign") assert_select "form[action=sign]" do |form| assert_select "input[type=submit][value=Sign]" end diff --git a/actionpack/test/template/benchmark_helper_test.rb b/actionpack/test/template/benchmark_helper_test.rb index 5d2af7cdd9..ac31fc6503 100644 --- a/actionpack/test/template/benchmark_helper_test.rb +++ b/actionpack/test/template/benchmark_helper_test.rb @@ -4,14 +4,14 @@ require 'action_view/helpers/benchmark_helper' class BenchmarkHelperTest < ActionView::TestCase tests ActionView::Helpers::BenchmarkHelper - def teardown - controller.logger.send(:clear_buffer) + def setup + super + controller.logger = ActiveSupport::BufferedLogger.new(StringIO.new) + controller.logger.auto_flushing = false end - def controller - logger = ActiveSupport::BufferedLogger.new(StringIO.new) - logger.auto_flushing = false - @controller ||= Struct.new(:logger).new(logger) + def teardown + controller.logger.send(:clear_buffer) end def test_without_block -- cgit v1.2.3