From 45d41f0dadd9fa171f306ff356770c4492726f30 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Thu, 19 Jun 2008 16:25:27 +0200 Subject: integrating I18n into Rails --- .../template/active_record_helper_i18n_test.rb | 47 ++++++++++ actionpack/test/template/date_helper_i18n_test.rb | 99 ++++++++++++++++++++++ .../test/template/form_options_helper_i18n_test.rb | 26 ++++++ .../test/template/number_helper_i18n_test.rb | 27 ++++++ 4 files changed, 199 insertions(+) create mode 100644 actionpack/test/template/active_record_helper_i18n_test.rb create mode 100644 actionpack/test/template/date_helper_i18n_test.rb create mode 100644 actionpack/test/template/form_options_helper_i18n_test.rb create mode 100644 actionpack/test/template/number_helper_i18n_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb new file mode 100644 index 0000000000..057fb9bd1a --- /dev/null +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -0,0 +1,47 @@ +require 'abstract_unit' + +class ActiveRecordHelperI18nTest < Test::Unit::TestCase + include ActionView::Helpers::ActiveRecordHelper + + attr_reader :request + def setup + @request = mock + @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) + stubs(:content_tag).returns 'content_tag' + + I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" + I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + end + + def test_error_messages_for_given_a_locale_it_does_not_check_request_for_locale + request.expects(:locale).never + @object.errors.stubs(:count).returns 0 + error_messages_for(:object => @object, :locale => 'en-US') + end + + def test_error_messages_for_given_no_locale_it_checks_request_for_locale + request.expects(:locale).returns 'en-US' + @object.errors.stubs(:count).returns 0 + error_messages_for(:object => @object) + end + + def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message + I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never + error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') + end + + def test_error_messages_for_given_no_header_message_option_it_translates_header_message + I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' + error_messages_for(:object => @object, :locale => 'en-US') + end + + def test_error_messages_for_given_a_message_option_it_does_not_translate_message + I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never + error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') + end + + def test_error_messages_for_given_no_message_option_it_translates_message + I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + error_messages_for(:object => @object, :locale => 'en-US') + end +end \ No newline at end of file diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb new file mode 100644 index 0000000000..9b7c03a400 --- /dev/null +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -0,0 +1,99 @@ +require 'abstract_unit' + +class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase + include ActionView::Helpers::DateHelper + attr_reader :request + + def setup + @request = mock + @from = Time.mktime(2004, 6, 6, 21, 45, 0) + end + + # distance_of_time_in_words + + def test_distance_of_time_in_words_given_a_locale_it_does_not_check_request_for_locale + request.expects(:locale).never + distance_of_time_in_words @from, @from + 1.second, false, :locale => 'en-US' + end + + def test_distance_of_time_in_words_given_no_locale_it_checks_request_for_locale + request.expects(:locale).returns 'en-US' + distance_of_time_in_words @from, @from + 1.second + end + + def test_distance_of_time_in_words_calls_i18n + { # with include_seconds + [2.seconds, true] => [:'less_than_x_seconds', 5], + [9.seconds, true] => [:'less_than_x_seconds', 10], + [19.seconds, true] => [:'less_than_x_seconds', 20], + [30.seconds, true] => [:'half_a_minute', nil], + [59.seconds, true] => [:'less_than_x_minutes', 1], + [60.seconds, true] => [:'x_minutes', 1], + + # without include_seconds + [29.seconds, false] => [:'less_than_x_minutes', 1], + [60.seconds, false] => [:'x_minutes', 1], + [44.minutes, false] => [:'x_minutes', 44], + [61.minutes, false] => [:'about_x_hours', 1], + [24.hours, false] => [:'x_days', 1], + [30.days, false] => [:'about_x_months', 1], + [60.days, false] => [:'x_months', 2], + [1.year, false] => [:'about_x_years', 1], + [3.years, false] => [:'over_x_years', 3] + + }.each do |passed, expected| + assert_distance_of_time_in_words_translates_key passed, expected + end + end + + def assert_distance_of_time_in_words_translates_key(passed, expected) + diff, include_seconds = *passed + key, count = *expected + to = @from + diff + + options = {:locale => 'en-US', :scope => :'datetime.distance_in_words'} + options[:count] = count if count + + I18n.expects(:t).with(key, options) + distance_of_time_in_words(@from, to, include_seconds, :locale => 'en-US') + end +end + +class DateHelperSelectTagsI18nTests < Test::Unit::TestCase + include ActionView::Helpers::DateHelper + attr_reader :request + + def setup + @request = mock + I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES + end + + # select_month + + def test_select_month_given_use_month_names_option_does_not_translate_monthnames + I18n.expects(:translate).never + select_month(8, :locale => 'en-US', :use_month_names => Date::MONTHNAMES) + end + + def test_select_month_translates_monthnames + I18n.expects(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES + select_month(8, :locale => 'en-US') + end + + def test_select_month_given_use_short_month_option_translates_abbr_monthnames + I18n.expects(:translate).with(:'date.abbr_month_names', 'en-US').returns Date::ABBR_MONTHNAMES + select_month(8, :locale => 'en-US', :use_short_month => true) + end + + # date_or_time_select + + def test_date_or_time_select_given_an_order_options_does_not_translate_order + I18n.expects(:translate).never + datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en-US') + end + + def test_date_or_time_select_given_no_order_options_translates_order + I18n.expects(:translate).with(:'date.order', 'en-US').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en-US') + end +end \ No newline at end of file diff --git a/actionpack/test/template/form_options_helper_i18n_test.rb b/actionpack/test/template/form_options_helper_i18n_test.rb new file mode 100644 index 0000000000..c9fc0768bb --- /dev/null +++ b/actionpack/test/template/form_options_helper_i18n_test.rb @@ -0,0 +1,26 @@ +require 'abstract_unit' + +class FormOptionsHelperI18nTests < Test::Unit::TestCase + include ActionView::Helpers::FormOptionsHelper + attr_reader :request + + def setup + @request = mock + end + + def test_country_options_for_select_given_a_locale_it_does_not_check_request_for_locale + request.expects(:locale).never + country_options_for_select :locale => 'en-US' + end + + def test_country_options_for_select_given_no_locale_it_checks_request_for_locale + request.expects(:locale).returns 'en-US' + country_options_for_select + end + + def test_country_options_for_select_translates_country_names + countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES + I18n.expects(:translate).with(:'countries.names', 'en-US').returns countries + country_options_for_select :locale => 'en-US' + end +end \ No newline at end of file diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb new file mode 100644 index 0000000000..47cb035f56 --- /dev/null +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -0,0 +1,27 @@ +require 'abstract_unit' + +class NumberHelperI18nTests < Test::Unit::TestCase + include ActionView::Helpers::NumberHelper + + attr_reader :request + def setup + @request = mock + @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} + I18n.backend.add_translations 'en-US', :currency => {:format => @defaults} + end + + def test_number_to_currency_given_a_locale_it_does_not_check_request_for_locale + request.expects(:locale).never + number_to_currency(1, :locale => 'en-US') + end + + def test_number_to_currency_given_no_locale_it_checks_request_for_locale + request.expects(:locale).returns 'en-US' + number_to_currency(1) + end + + def test_number_to_currency_translates_currency_formats + I18n.expects(:translate).with(:'currency.format', 'en-US').returns @defaults + number_to_currency(1, :locale => 'en-US') + end +end \ No newline at end of file -- cgit v1.2.3 From b09c6e7444cf05f986e601bcc22cf17ede7b63bd Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Thu, 19 Jun 2008 19:08:14 +0200 Subject: add a generic tranlate view helper --- actionpack/test/template/i18n_helper_test.rb | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 actionpack/test/template/i18n_helper_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/template/i18n_helper_test.rb b/actionpack/test/template/i18n_helper_test.rb new file mode 100644 index 0000000000..598731568c --- /dev/null +++ b/actionpack/test/template/i18n_helper_test.rb @@ -0,0 +1,33 @@ +require 'abstract_unit' +require 'action_view/helpers/i18n_helper' + +class I18nHelperTests < Test::Unit::TestCase + include ActionView::Helpers::I18nHelper + + attr_reader :request + def setup + @request = stub :locale => 'en-US' + I18n.stubs(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' + end + + def test_translate_given_a_locale_argument_it_does_not_check_request_for_locale + request.expects(:locale).never + assert_equal 'Foo Bar', translate(:'foo.bar', :locale => 'en-US') + end + + def test_translate_given_a_locale_option_it_does_not_check_request_for_locale + request.expects(:locale).never + I18n.expects(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' + assert_equal 'Foo Bar', translate(:'foo.bar', :locale => 'en-US') + end + + def test_translate_given_no_locale_it_checks_request_for_locale + request.expects(:locale).returns 'en-US' + assert_equal 'Foo Bar', translate(:'foo.bar') + end + + def test_translate_delegates_to_i18n_translate + I18n.expects(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' + assert_equal 'Foo Bar', translate(:'foo.bar') + end +end \ No newline at end of file -- cgit v1.2.3 From 585c8c17c303fc46fcf014a644a541eae6cb5ffd Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Fri, 20 Jun 2008 09:13:20 +0200 Subject: rename Backend::Simple#add_translations to set_translations because it overwrites existing translations --- actionpack/test/template/number_helper_i18n_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 47cb035f56..d002ad4a2f 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -7,7 +7,7 @@ class NumberHelperI18nTests < Test::Unit::TestCase def setup @request = mock @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} - I18n.backend.add_translations 'en-US', :currency => {:format => @defaults} + I18n.backend.set_translations 'en-US', :currency => {:format => @defaults} end def test_number_to_currency_given_a_locale_it_does_not_check_request_for_locale -- cgit v1.2.3 From c1e2506494107892a0962b8491cd234f77949c08 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sat, 21 Jun 2008 11:27:19 +0200 Subject: Changed process of storing translations from the client libraries to the backend: clients now can pass a block to backend#populate which can contain code to load and register translations. This makes sense for backends that persist their translations (e.g. to db) so the repeated loading and passing of translations throughout the server startup would be wasted resources. --- actionpack/test/template/number_helper_i18n_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index d002ad4a2f..b75af03378 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -7,7 +7,7 @@ class NumberHelperI18nTests < Test::Unit::TestCase def setup @request = mock @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} - I18n.backend.set_translations 'en-US', :currency => {:format => @defaults} + I18n.backend.store_translations 'en-US', :currency => {:format => @defaults} end def test_number_to_currency_given_a_locale_it_does_not_check_request_for_locale -- cgit v1.2.3 From 20d6630c1bb70f09e1f6a135bd3f9d690ad28250 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 22 Jun 2008 11:41:51 +0200 Subject: Replaced country_options_for_select with old, untranslated version and moved country-related helpers to a new FormCountryHelper helper module so that they can easily be moved to a plugin. Updated tests accordingly. --- .../test/template/form_country_helper_test.rb | 772 +++++++++++++++++++++ .../test/template/form_options_helper_i18n_test.rb | 26 - .../test/template/form_options_helper_test.rb | 766 +------------------- 3 files changed, 775 insertions(+), 789 deletions(-) create mode 100644 actionpack/test/template/form_country_helper_test.rb delete mode 100644 actionpack/test/template/form_options_helper_i18n_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_country_helper_test.rb b/actionpack/test/template/form_country_helper_test.rb new file mode 100644 index 0000000000..224b2e21c2 --- /dev/null +++ b/actionpack/test/template/form_country_helper_test.rb @@ -0,0 +1,772 @@ +require 'abstract_unit' + +class FormCountryHelperTest < ActionView::TestCase + tests ActionView::Helpers::FormCountryHelper + + silence_warnings do + Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin) + end + + def test_country_select + @post = Post.new + @post.origin = "Denmark" + expected_select = <<-COUNTRIES + +COUNTRIES + assert_dom_equal(expected_select[0..-2], country_select("post", "origin")) + end + + def test_country_select_with_priority_countries + @post = Post.new + @post.origin = "Denmark" + expected_select = <<-COUNTRIES + +COUNTRIES + assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) + end + + def test_country_select_with_selected_priority_country + @post = Post.new + @post.origin = "New Zealand" + expected_select = <<-COUNTRIES + +COUNTRIES + assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) + end +end \ No newline at end of file diff --git a/actionpack/test/template/form_options_helper_i18n_test.rb b/actionpack/test/template/form_options_helper_i18n_test.rb deleted file mode 100644 index c9fc0768bb..0000000000 --- a/actionpack/test/template/form_options_helper_i18n_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'abstract_unit' - -class FormOptionsHelperI18nTests < Test::Unit::TestCase - include ActionView::Helpers::FormOptionsHelper - attr_reader :request - - def setup - @request = mock - end - - def test_country_options_for_select_given_a_locale_it_does_not_check_request_for_locale - request.expects(:locale).never - country_options_for_select :locale => 'en-US' - end - - def test_country_options_for_select_given_no_locale_it_checks_request_for_locale - request.expects(:locale).returns 'en-US' - country_options_for_select - end - - def test_country_options_for_select_translates_country_names - countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES - I18n.expects(:translate).with(:'countries.names', 'en-US').returns countries - country_options_for_select :locale => 'en-US' - end -end \ No newline at end of file diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 3f89a5e426..5ba81aac02 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -412,769 +412,6 @@ class FormOptionsHelperTest < ActionView::TestCase assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) end - def test_country_select - @post = Post.new - @post.origin = "Denmark" - expected_select = <<-COUNTRIES - -COUNTRIES - assert_dom_equal(expected_select[0..-2], country_select("post", "origin")) - end - - def test_country_select_with_priority_countries - @post = Post.new - @post.origin = "Denmark" - expected_select = <<-COUNTRIES - -COUNTRIES - assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) - end - - def test_country_select_with_selected_priority_country - @post = Post.new - @post.origin = "New Zealand" - expected_select = <<-COUNTRIES - -COUNTRIES - assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) - end - def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) @@ -1327,4 +564,7 @@ COUNTRIES html end + def test_countries_is_deprectated + assert_deprecated(/COUNTRIES/) { ActionView::Helpers::FormOptionsHelper::COUNTRIES.size } + end end -- cgit v1.2.3 From 3533dc68120ed40a4ec44ed9900c9035108cfcf1 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 22 Jun 2008 13:49:38 +0200 Subject: check self.locale instead of request.locale in helpers --- actionpack/test/template/active_record_helper_i18n_test.rb | 6 +++--- actionpack/test/template/date_helper_i18n_test.rb | 8 ++++---- actionpack/test/template/number_helper_i18n_test.rb | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index 057fb9bd1a..3a2197ac93 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -5,22 +5,22 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase attr_reader :request def setup - @request = mock @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) stubs(:content_tag).returns 'content_tag' + stubs(:locale) I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' end def test_error_messages_for_given_a_locale_it_does_not_check_request_for_locale - request.expects(:locale).never + expects(:locale).never @object.errors.stubs(:count).returns 0 error_messages_for(:object => @object, :locale => 'en-US') end def test_error_messages_for_given_no_locale_it_checks_request_for_locale - request.expects(:locale).returns 'en-US' + expects(:locale).returns 'en-US' @object.errors.stubs(:count).returns 0 error_messages_for(:object => @object) end diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index 9b7c03a400..f245ca1fc8 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -5,19 +5,19 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase attr_reader :request def setup - @request = mock + stubs(:locale) @from = Time.mktime(2004, 6, 6, 21, 45, 0) end # distance_of_time_in_words def test_distance_of_time_in_words_given_a_locale_it_does_not_check_request_for_locale - request.expects(:locale).never + expects(:locale).never distance_of_time_in_words @from, @from + 1.second, false, :locale => 'en-US' end def test_distance_of_time_in_words_given_no_locale_it_checks_request_for_locale - request.expects(:locale).returns 'en-US' + expects(:locale).returns 'en-US' distance_of_time_in_words @from, @from + 1.second end @@ -64,7 +64,7 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase attr_reader :request def setup - @request = mock + # stubs(:locale) I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES end diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index b75af03378..5db60ece04 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -5,18 +5,18 @@ class NumberHelperI18nTests < Test::Unit::TestCase attr_reader :request def setup - @request = mock + stubs(:locale) @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} I18n.backend.store_translations 'en-US', :currency => {:format => @defaults} end def test_number_to_currency_given_a_locale_it_does_not_check_request_for_locale - request.expects(:locale).never + expects(:locale).never number_to_currency(1, :locale => 'en-US') end def test_number_to_currency_given_no_locale_it_checks_request_for_locale - request.expects(:locale).returns 'en-US' + expects(:locale).returns 'en-US' number_to_currency(1) end -- cgit v1.2.3 From 2ee9f2a0303cba95b2d8073fc7e22ec75229a8ee Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 23 Jun 2008 14:34:01 +0200 Subject: remove generic translate helpers --- actionpack/test/template/i18n_helper_test.rb | 33 ---------------------------- 1 file changed, 33 deletions(-) delete mode 100644 actionpack/test/template/i18n_helper_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/template/i18n_helper_test.rb b/actionpack/test/template/i18n_helper_test.rb deleted file mode 100644 index 598731568c..0000000000 --- a/actionpack/test/template/i18n_helper_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'abstract_unit' -require 'action_view/helpers/i18n_helper' - -class I18nHelperTests < Test::Unit::TestCase - include ActionView::Helpers::I18nHelper - - attr_reader :request - def setup - @request = stub :locale => 'en-US' - I18n.stubs(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' - end - - def test_translate_given_a_locale_argument_it_does_not_check_request_for_locale - request.expects(:locale).never - assert_equal 'Foo Bar', translate(:'foo.bar', :locale => 'en-US') - end - - def test_translate_given_a_locale_option_it_does_not_check_request_for_locale - request.expects(:locale).never - I18n.expects(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' - assert_equal 'Foo Bar', translate(:'foo.bar', :locale => 'en-US') - end - - def test_translate_given_no_locale_it_checks_request_for_locale - request.expects(:locale).returns 'en-US' - assert_equal 'Foo Bar', translate(:'foo.bar') - end - - def test_translate_delegates_to_i18n_translate - I18n.expects(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' - assert_equal 'Foo Bar', translate(:'foo.bar') - end -end \ No newline at end of file -- cgit v1.2.3 From ac66865ea3d0eb0de8e19fef49293feb9e61281b Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 23 Jun 2008 14:49:02 +0200 Subject: update tests according to removal of self.locale from helpers --- actionpack/test/template/active_record_helper_i18n_test.rb | 13 ------------- actionpack/test/template/date_helper_i18n_test.rb | 12 ------------ actionpack/test/template/number_helper_i18n_test.rb | 11 ----------- 3 files changed, 36 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index 3a2197ac93..d1b92c7e4d 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -7,24 +7,11 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase def setup @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) stubs(:content_tag).returns 'content_tag' - stubs(:locale) I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' end - def test_error_messages_for_given_a_locale_it_does_not_check_request_for_locale - expects(:locale).never - @object.errors.stubs(:count).returns 0 - error_messages_for(:object => @object, :locale => 'en-US') - end - - def test_error_messages_for_given_no_locale_it_checks_request_for_locale - expects(:locale).returns 'en-US' - @object.errors.stubs(:count).returns 0 - error_messages_for(:object => @object) - end - def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index f245ca1fc8..3e1eed61fd 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -5,22 +5,11 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase attr_reader :request def setup - stubs(:locale) @from = Time.mktime(2004, 6, 6, 21, 45, 0) end # distance_of_time_in_words - def test_distance_of_time_in_words_given_a_locale_it_does_not_check_request_for_locale - expects(:locale).never - distance_of_time_in_words @from, @from + 1.second, false, :locale => 'en-US' - end - - def test_distance_of_time_in_words_given_no_locale_it_checks_request_for_locale - expects(:locale).returns 'en-US' - distance_of_time_in_words @from, @from + 1.second - end - def test_distance_of_time_in_words_calls_i18n { # with include_seconds [2.seconds, true] => [:'less_than_x_seconds', 5], @@ -64,7 +53,6 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase attr_reader :request def setup - # stubs(:locale) I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES end diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 5db60ece04..bee9ceaa71 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -5,21 +5,10 @@ class NumberHelperI18nTests < Test::Unit::TestCase attr_reader :request def setup - stubs(:locale) @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} I18n.backend.store_translations 'en-US', :currency => {:format => @defaults} end - def test_number_to_currency_given_a_locale_it_does_not_check_request_for_locale - expects(:locale).never - number_to_currency(1, :locale => 'en-US') - end - - def test_number_to_currency_given_no_locale_it_checks_request_for_locale - expects(:locale).returns 'en-US' - number_to_currency(1) - end - def test_number_to_currency_translates_currency_formats I18n.expects(:translate).with(:'currency.format', 'en-US').returns @defaults number_to_currency(1, :locale => 'en-US') -- cgit v1.2.3 From 77177441d1bd8f62c5b6a990ddee155061df661c Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 23 Jun 2008 14:49:47 +0200 Subject: including rcov shell scripts for reference --- actionpack/test/i18n_coverage | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 actionpack/test/i18n_coverage (limited to 'actionpack/test') diff --git a/actionpack/test/i18n_coverage b/actionpack/test/i18n_coverage new file mode 100755 index 0000000000..57b54e9d47 --- /dev/null +++ b/actionpack/test/i18n_coverage @@ -0,0 +1,9 @@ +rcov -x abstract_unit.rb \ +-i action_view/helpers/number_helper.rb,action_view/helpers/date_helper.rb,action_view/helpers/active_record_helper.rb \ +template/number_helper_i18n_test.rb \ +template/date_helper_i18n_test.rb \ +template/active_record_helper_i18n_test.rb \ + +# template/number_helper_test.rb \ +# template/date_helper_test.rb \ +# template/active_record_helper_test.rb \ No newline at end of file -- cgit v1.2.3 From 66c2508ebbca06e551255a76cc47a1608f091992 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Fri, 27 Jun 2008 15:00:55 +0200 Subject: Make sure mocha is available --- .../template/active_record_helper_i18n_test.rb | 48 ++++---- actionpack/test/template/date_helper_i18n_test.rb | 134 +++++++++++---------- .../test/template/number_helper_i18n_test.rb | 16 +-- 3 files changed, 103 insertions(+), 95 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index d1b92c7e4d..d78b0e4c0c 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -4,31 +4,33 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase include ActionView::Helpers::ActiveRecordHelper attr_reader :request - def setup - @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) - stubs(:content_tag).returns 'content_tag' - - I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" - I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' - end + uses_mocha 'active_record_helper_i18n_test' do + def setup + @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) + stubs(:content_tag).returns 'content_tag' - def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message - I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never - error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') - end + I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" + I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + end - def test_error_messages_for_given_no_header_message_option_it_translates_header_message - I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' - error_messages_for(:object => @object, :locale => 'en-US') - end - - def test_error_messages_for_given_a_message_option_it_does_not_translate_message - I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never - error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') - end + def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message + I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never + error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') + end + + def test_error_messages_for_given_no_header_message_option_it_translates_header_message + I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' + error_messages_for(:object => @object, :locale => 'en-US') + end + + def test_error_messages_for_given_a_message_option_it_does_not_translate_message + I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never + error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') + end - def test_error_messages_for_given_no_message_option_it_translates_message - I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' - error_messages_for(:object => @object, :locale => 'en-US') + def test_error_messages_for_given_no_message_option_it_translates_message + I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + error_messages_for(:object => @object, :locale => 'en-US') + end end end \ No newline at end of file diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index 3e1eed61fd..aeb06c55ea 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -8,43 +8,45 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase @from = Time.mktime(2004, 6, 6, 21, 45, 0) end - # distance_of_time_in_words + 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 + 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 - end - - def assert_distance_of_time_in_words_translates_key(passed, expected) - diff, include_seconds = *passed - key, count = *expected - to = @from + diff - options = {:locale => 'en-US', :scope => :'datetime.distance_in_words'} - options[:count] = count if count - - I18n.expects(:t).with(key, options) - distance_of_time_in_words(@from, to, include_seconds, :locale => 'en-US') + def assert_distance_of_time_in_words_translates_key(passed, expected) + diff, include_seconds = *passed + key, count = *expected + to = @from + diff + + options = {:locale => 'en-US', :scope => :'datetime.distance_in_words'} + options[:count] = count if count + + I18n.expects(:t).with(key, options) + distance_of_time_in_words(@from, to, include_seconds, :locale => 'en-US') + end end end @@ -52,36 +54,38 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase include ActionView::Helpers::DateHelper attr_reader :request - def setup - I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES - end - - # select_month - - def test_select_month_given_use_month_names_option_does_not_translate_monthnames - I18n.expects(:translate).never - select_month(8, :locale => 'en-US', :use_month_names => Date::MONTHNAMES) - end - - def test_select_month_translates_monthnames - I18n.expects(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES - select_month(8, :locale => 'en-US') - end - - def test_select_month_given_use_short_month_option_translates_abbr_monthnames - I18n.expects(:translate).with(:'date.abbr_month_names', 'en-US').returns Date::ABBR_MONTHNAMES - select_month(8, :locale => 'en-US', :use_short_month => true) - end - - # date_or_time_select - - def test_date_or_time_select_given_an_order_options_does_not_translate_order - I18n.expects(:translate).never - datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en-US') - end - - def test_date_or_time_select_given_no_order_options_translates_order - I18n.expects(:translate).with(:'date.order', 'en-US').returns [:year, :month, :day] - datetime_select('post', 'updated_at', :locale => 'en-US') + uses_mocha 'date_helper_select_tags_i18n_tests' do + def setup + I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES + end + + # select_month + + def test_select_month_given_use_month_names_option_does_not_translate_monthnames + I18n.expects(:translate).never + select_month(8, :locale => 'en-US', :use_month_names => Date::MONTHNAMES) + end + + def test_select_month_translates_monthnames + I18n.expects(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES + select_month(8, :locale => 'en-US') + end + + def test_select_month_given_use_short_month_option_translates_abbr_monthnames + I18n.expects(:translate).with(:'date.abbr_month_names', 'en-US').returns Date::ABBR_MONTHNAMES + select_month(8, :locale => 'en-US', :use_short_month => true) + end + + # date_or_time_select + + def test_date_or_time_select_given_an_order_options_does_not_translate_order + I18n.expects(:translate).never + datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en-US') + end + + def test_date_or_time_select_given_no_order_options_translates_order + I18n.expects(:translate).with(:'date.order', 'en-US').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en-US') + end end end \ No newline at end of file diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index bee9ceaa71..be40ddbc88 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -4,13 +4,15 @@ class NumberHelperI18nTests < Test::Unit::TestCase include ActionView::Helpers::NumberHelper attr_reader :request - def setup - @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} - I18n.backend.store_translations 'en-US', :currency => {:format => @defaults} - end + uses_mocha 'number_helper_i18n_tests' do + def setup + @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} + I18n.backend.store_translations 'en-US', :currency => {:format => @defaults} + end - def test_number_to_currency_translates_currency_formats - I18n.expects(:translate).with(:'currency.format', 'en-US').returns @defaults - number_to_currency(1, :locale => 'en-US') + def test_number_to_currency_translates_currency_formats + I18n.expects(:translate).with(:'currency.format', 'en-US').returns @defaults + number_to_currency(1, :locale => 'en-US') + end end end \ No newline at end of file -- cgit v1.2.3 From c9ed2c9bd24b9f4cdfcb692151f87ba900469e71 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 6 Jul 2008 19:00:55 +0200 Subject: add a translation helper --- .../test/template/translation_helper_test.rb | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 actionpack/test/template/translation_helper_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb new file mode 100644 index 0000000000..e97bcdb731 --- /dev/null +++ b/actionpack/test/template/translation_helper_test.rb @@ -0,0 +1,42 @@ +require 'abstract_unit' + +class TranslationHelperTest < Test::Unit::TestCase + include ActionView::Helpers::TagHelper + include ActionView::Helpers::TranslationHelper + + attr_reader :request + uses_mocha 'translation_helper_test' do + def setup + end + + def test_delegates_to_i18n_setting_the_raise_option + I18n.expects(:translate).with(:foo, 'en-US', :raise => true) + translate :foo, 'en-US' + end + + def test_returns_missing_translation_message_wrapped_into_span + expected = 'en-US, foo' + assert_equal expected, translate(:foo) + end + + # def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message + # I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never + # error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') + # end + # + # def test_error_messages_for_given_no_header_message_option_it_translates_header_message + # I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' + # error_messages_for(:object => @object, :locale => 'en-US') + # end + # + # def test_error_messages_for_given_a_message_option_it_does_not_translate_message + # I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never + # error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') + # end + # + # def test_error_messages_for_given_no_message_option_it_translates_message + # I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + # error_messages_for(:object => @object, :locale => 'en-US') + # end + end +end \ No newline at end of file -- cgit v1.2.3 From 84816ae981a8598e5e401eb1b9b805de840fefc9 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 6 Jul 2008 21:20:02 +0200 Subject: align with changes in i18n --- actionpack/test/template/date_helper_i18n_test.rb | 8 ++++---- actionpack/test/template/number_helper_i18n_test.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index aeb06c55ea..aca3593921 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -56,7 +56,7 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase uses_mocha 'date_helper_select_tags_i18n_tests' do def setup - I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES + I18n.stubs(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES end # select_month @@ -67,12 +67,12 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase end def test_select_month_translates_monthnames - I18n.expects(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES + I18n.expects(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES select_month(8, :locale => 'en-US') end def test_select_month_given_use_short_month_option_translates_abbr_monthnames - I18n.expects(:translate).with(:'date.abbr_month_names', 'en-US').returns Date::ABBR_MONTHNAMES + I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en-US').returns Date::ABBR_MONTHNAMES select_month(8, :locale => 'en-US', :use_short_month => true) end @@ -84,7 +84,7 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase end def test_date_or_time_select_given_no_order_options_translates_order - I18n.expects(:translate).with(:'date.order', 'en-US').returns [:year, :month, :day] + I18n.expects(:translate).with(:'date.order', :locale => 'en-US').returns [:year, :month, :day] datetime_select('post', 'updated_at', :locale => 'en-US') end end diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index be40ddbc88..50c20c3627 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -11,7 +11,7 @@ class NumberHelperI18nTests < Test::Unit::TestCase end def test_number_to_currency_translates_currency_formats - I18n.expects(:translate).with(:'currency.format', 'en-US').returns @defaults + I18n.expects(:translate).with(:'currency.format', :locale => 'en-US').returns @defaults number_to_currency(1, :locale => 'en-US') end end -- cgit v1.2.3 From 2949918b4cea26435d1f0a076fe884c8113b40fa Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Tue, 8 Jul 2008 11:53:19 +0200 Subject: Make sure object name is translated in #error_messages_for --- actionpack/test/template/active_record_helper_i18n_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index d78b0e4c0c..d35e79b94a 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -7,6 +7,7 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase uses_mocha 'active_record_helper_i18n_test' do def setup @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) + @object_name = 'book' stubs(:content_tag).returns 'content_tag' I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" @@ -20,17 +21,26 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase def test_error_messages_for_given_no_header_message_option_it_translates_header_message I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' + I18n.expects(:t).with('', :default => '').once error_messages_for(:object => @object, :locale => 'en-US') end def test_error_messages_for_given_a_message_option_it_does_not_translate_message I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never + I18n.expects(:t).with('', :default => '').once error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') end def test_error_messages_for_given_no_message_option_it_translates_message I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + I18n.expects(:t).with('', :default => '').once error_messages_for(:object => @object, :locale => 'en-US') end + + def test_error_messages_for_given_object_name_it_translates_object_name + I18n.expects(:t).with(:header_message, :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => @object_name).returns "1 error prohibited this #{@object_name} from being saved" + I18n.expects(:t).with(@object_name, :default => @object_name).once.returns @object_name + error_messages_for(:object => @object, :locale => 'en-US', :object_name => @object_name) + end end end \ No newline at end of file -- cgit v1.2.3 From cf5d6ab9a849d19ac683180cc7b603ca94b13ed7 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Tue, 8 Jul 2008 12:37:49 +0200 Subject: Added localize helper method --- actionpack/test/template/translation_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index e97bcdb731..2263d48a65 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -39,4 +39,10 @@ class TranslationHelperTest < Test::Unit::TestCase # error_messages_for(:object => @object, :locale => 'en-US') # end end + + def test_delegates_localize_to_i18n + @time = Time.utc(2008, 7, 8, 12, 18, 38) + assert_equal "Tue, 08 Jul 2008 12:18:38 +0100", localize(@time) + assert_equal "08 Jul 12:18", localize(@time, :format => :short) + end end \ No newline at end of file -- cgit v1.2.3 From dc77359c16abc0f693e3847e677c0cad62d0df50 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Tue, 8 Jul 2008 17:41:18 +0200 Subject: Removed unnecessary or condition in #error_messages_for --- actionpack/test/template/active_record_helper_i18n_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index d35e79b94a..feec64aa30 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -21,19 +21,19 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase def test_error_messages_for_given_no_header_message_option_it_translates_header_message I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' - I18n.expects(:t).with('', :default => '').once + I18n.expects(:t).with('', :default => '').once.returns '' error_messages_for(:object => @object, :locale => 'en-US') end def test_error_messages_for_given_a_message_option_it_does_not_translate_message I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never - I18n.expects(:t).with('', :default => '').once + I18n.expects(:t).with('', :default => '').once.returns '' error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') end def test_error_messages_for_given_no_message_option_it_translates_message I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' - I18n.expects(:t).with('', :default => '').once + I18n.expects(:t).with('', :default => '').once.returns '' error_messages_for(:object => @object, :locale => 'en-US') end -- cgit v1.2.3 From 4d76bad387036d96a955eae7c260a9633e915d11 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 15 Jul 2008 10:40:33 -0700 Subject: Ruby 1.9 compat: account for different String#hash --- actionpack/test/template/asset_tag_helper_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 020e112fd0..3cfc8fa4ed 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -335,8 +335,9 @@ class AssetTagHelperTest < ActionView::TestCase ActionController::Base.asset_host = 'http://a%d.example.com' ActionController::Base.perform_caching = true + hash = '/javascripts/cache/money.js'.hash % 4 assert_dom_equal( - %(), + %(), javascript_include_tag(:all, :cache => "cache/money") ) -- cgit v1.2.3 From 24a8ae4e08fcd15a8c3792990d1d0981d004d339 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Tue, 15 Jul 2008 20:39:36 +0200 Subject: Try to get more useful errors out of the test_line_offset failures --- actionpack/test/controller/render_test.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index a857810b78..9a94db4b00 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -101,12 +101,7 @@ class TestController < ActionController::Base end def render_line_offset - begin - render :inline => '<% raise %>', :locals => {:foo => 'bar'} - rescue RuntimeError => exc - end - line = exc.backtrace.first - render :text => line + render :inline => '<% raise %>', :locals => {:foo => 'bar'} end def heading @@ -238,10 +233,15 @@ class RenderTest < Test::Unit::TestCase end def test_line_offset - get :render_line_offset - line = @response.body - assert(line =~ %r{:(\d+):}) - assert_equal "1", $1 + begin + get :render_line_offset + flunk "the action should have raised an exception" + rescue RuntimeError => exc + line = exc.backtrace.first + assert(line =~ %r{:(\d+):}) + assert_equal "1", $1, + "The line offset is wrong, perhaps the wrong exception has been raised, exception was: #{exc.inspect}" + end end def test_render_with_forward_slash -- cgit v1.2.3 From aca246ab25497bb6787d2e18680e9f73ad13d223 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 14:41:38 -0500 Subject: Get buffer for fragment cache from template's @output_buffer --- actionpack/test/controller/caching_test.rb | 43 +--------------------- actionpack/test/template/javascript_helper_test.rb | 2 + actionpack/test/template/prototype_helper_test.rb | 2 +- 3 files changed, 5 insertions(+), 42 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index c30f7be700..8f53ecd178 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -555,7 +555,7 @@ class FragmentCachingTest < Test::Unit::TestCase fragment_computed = false buffer = 'generated till now -> ' - @controller.fragment_for(Proc.new { fragment_computed = true }, 'expensive') { buffer } + @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } assert fragment_computed assert_equal 'generated till now -> ', buffer @@ -566,50 +566,11 @@ class FragmentCachingTest < Test::Unit::TestCase fragment_computed = false buffer = 'generated till now -> ' - @controller.fragment_for(Proc.new { fragment_computed = true }, 'expensive') { buffer} + @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } assert !fragment_computed assert_equal 'generated till now -> fragment content', buffer end - - def test_cache_erb_fragment - @store.write('views/expensive', 'fragment content') - @controller.response.template.output_buffer = 'generated till now -> ' - - assert_equal( 'generated till now -> fragment content', - ActionView::TemplateHandlers::ERB.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) - end - - def test_cache_rxml_fragment - @store.write('views/expensive', 'fragment content') - xml = 'generated till now -> ' - class << xml; def target!; to_s; end; end - - assert_equal( 'generated till now -> fragment content', - ActionView::TemplateHandlers::Builder.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) - end - - def test_cache_rjs_fragment - @store.write('views/expensive', 'fragment content') - page = 'generated till now -> ' - - assert_equal( 'generated till now -> fragment content', - ActionView::TemplateHandlers::RJS.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) - end - - def test_cache_rjs_fragment_debug_mode_does_not_interfere - @store.write('views/expensive', 'fragment content') - page = 'generated till now -> ' - - begin - debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, true - assert_equal( 'generated till now -> fragment content', - ActionView::TemplateHandlers::RJS.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) - assert ActionView::Base.debug_rjs - ensure - ActionView::Base.debug_rjs = debug_mode - end - end end diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index b2c4a130c8..36dfeba5ed 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -3,6 +3,8 @@ require 'abstract_unit' class JavaScriptHelperTest < ActionView::TestCase tests ActionView::Helpers::JavaScriptHelper + attr_accessor :output_buffer + def test_escape_javascript assert_equal '', escape_javascript(nil) assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 1d9bc5eb9b..5528430d80 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -25,7 +25,7 @@ class Author::Nested < Author; end class PrototypeHelperBaseTest < ActionView::TestCase - attr_accessor :template_format + attr_accessor :template_format, :output_buffer def setup @template = nil -- cgit v1.2.3 From 8691e255402b27eae594530001227fc05416a00c Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 16 Jul 2008 03:28:44 +0200 Subject: reverting changes to form_options_helper for merge --- .../test/template/form_options_helper_test.rb | 766 ++++++++++++++++++++- 1 file changed, 763 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 5ba81aac02..3f89a5e426 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -412,6 +412,769 @@ class FormOptionsHelperTest < ActionView::TestCase assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) end + def test_country_select + @post = Post.new + @post.origin = "Denmark" + expected_select = <<-COUNTRIES + +COUNTRIES + assert_dom_equal(expected_select[0..-2], country_select("post", "origin")) + end + + def test_country_select_with_priority_countries + @post = Post.new + @post.origin = "Denmark" + expected_select = <<-COUNTRIES + +COUNTRIES + assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) + end + + def test_country_select_with_selected_priority_country + @post = Post.new + @post.origin = "New Zealand" + expected_select = <<-COUNTRIES + +COUNTRIES + assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) + end + def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) @@ -564,7 +1327,4 @@ class FormOptionsHelperTest < ActionView::TestCase html end - def test_countries_is_deprectated - assert_deprecated(/COUNTRIES/) { ActionView::Helpers::FormOptionsHelper::COUNTRIES.size } - end end -- cgit v1.2.3 From ecc054352512cac8c0895c78c5f3d043046dcfec Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 15 Jul 2008 18:42:22 -0700 Subject: JavaScriptGenerator should only sets output_buffer for the duration of the update block --- actionpack/test/template/javascript_helper_test.rb | 6 +++++- actionpack/test/template/prototype_helper_test.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 36dfeba5ed..d41111127b 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -3,7 +3,11 @@ require 'abstract_unit' class JavaScriptHelperTest < ActionView::TestCase tests ActionView::Helpers::JavaScriptHelper - attr_accessor :output_buffer + attr_accessor :template_format, :output_buffer + + def setup + @template = self + end def test_escape_javascript assert_equal '', escape_javascript(nil) diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 5528430d80..92cc85703b 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -28,7 +28,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase attr_accessor :template_format, :output_buffer def setup - @template = nil + @template = self @controller = Class.new do def url_for(options) if options.is_a?(String) @@ -243,8 +243,12 @@ class PrototypeHelperTest < PrototypeHelperBaseTest end def test_update_page + old_output_buffer = output_buffer + block = Proc.new { |page| page.replace_html('foo', 'bar') } assert_equal create_generator(&block).to_s, update_page(&block) + + assert_equal old_output_buffer, output_buffer end def test_update_page_tag -- cgit v1.2.3 From 8b306bf24c53f698cd83f7d616f2478a6efa5797 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 20:52:29 -0500 Subject: Improved test coverage for fragment cache helper --- actionpack/test/controller/caching_test.rb | 62 +++++++++++++++++----- .../formatted_fragment_cached.html.erb | 3 ++ .../formatted_fragment_cached.js.rjs | 6 +++ .../formatted_fragment_cached.xml.builder | 5 ++ 4 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb create mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs create mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 8f53ecd178..47a0fcf99d 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -148,7 +148,6 @@ class PageCachingTest < Test::Unit::TestCase end end - class ActionCachingTestController < ActionController::Base caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour caches_action :show, :cache_path => 'http://test.host/custom/show' @@ -489,54 +488,54 @@ class FragmentCachingTest < Test::Unit::TestCase def test_fragment_cache_key assert_equal 'views/what a key', @controller.fragment_cache_key('what a key') - assert_equal( "views/test.host/fragment_caching_test/some_action", - @controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action')) + assert_equal "views/test.host/fragment_caching_test/some_action", + @controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action') end - def test_read_fragment__with_caching_enabled + def test_read_fragment_with_caching_enabled @store.write('views/name', 'value') assert_equal 'value', @controller.read_fragment('name') end - def test_read_fragment__with_caching_disabled + def test_read_fragment_with_caching_disabled ActionController::Base.perform_caching = false @store.write('views/name', 'value') assert_nil @controller.read_fragment('name') end - def test_fragment_exist__with_caching_enabled + def test_fragment_exist_with_caching_enabled @store.write('views/name', 'value') assert @controller.fragment_exist?('name') assert !@controller.fragment_exist?('other_name') end - def test_fragment_exist__with_caching_disabled + def test_fragment_exist_with_caching_disabled ActionController::Base.perform_caching = false @store.write('views/name', 'value') assert !@controller.fragment_exist?('name') assert !@controller.fragment_exist?('other_name') end - def test_write_fragment__with_caching_enabled + def test_write_fragment_with_caching_enabled assert_nil @store.read('views/name') assert_equal 'value', @controller.write_fragment('name', 'value') assert_equal 'value', @store.read('views/name') end - def test_write_fragment__with_caching_disabled + def test_write_fragment_with_caching_disabled assert_nil @store.read('views/name') ActionController::Base.perform_caching = false assert_equal nil, @controller.write_fragment('name', 'value') assert_nil @store.read('views/name') end - def test_expire_fragment__with_simple_key + def test_expire_fragment_with_simple_key @store.write('views/name', 'value') @controller.expire_fragment 'name' assert_nil @store.read('views/name') end - def test_expire_fragment__with__regexp + def test_expire_fragment_with_regexp @store.write('views/name', 'value') @store.write('views/another_name', 'another_value') @store.write('views/primalgrasp', 'will not expire ;-)') @@ -548,7 +547,7 @@ class FragmentCachingTest < Test::Unit::TestCase assert_equal 'will not expire ;-)', @store.read('views/primalgrasp') end - def test_fragment_for__with_disabled_caching + def test_fragment_for_with_disabled_caching ActionController::Base.perform_caching = false @store.write('views/expensive', 'fragment content') @@ -573,7 +572,6 @@ class FragmentCachingTest < Test::Unit::TestCase end end - class FunctionalCachingController < ActionController::Base def fragment_cached end @@ -590,6 +588,13 @@ class FunctionalCachingController < ActionController::Base end end + def formatted_fragment_cached + respond_to do |format| + format.html + format.xml + format.js + end + end def rescue_action(e) raise e @@ -639,4 +644,35 @@ CACHED assert_match /Fragment caching in a partial/, @response.body assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial') end + + def test_html_formatted_fragment_caching + get :formatted_fragment_cached, :format => "html" + assert_response :success + expected_body = "\n

ERB

\n" + + assert_equal expected_body, @response.body + + assert_equal "

ERB

", @store.read('views/test.host/functional_caching/formatted_fragment_cached') + end + + def test_xml_formatted_fragment_caching + get :formatted_fragment_cached, :format => "xml" + assert_response :success + expected_body = "\n

Builder

\n\n" + + assert_equal expected_body, @response.body + + assert_equal "

Builder

\n", @store.read('views/test.host/functional_caching/formatted_fragment_cached') + end + + def test_js_formatted_fragment_caching + get :formatted_fragment_cached, :format => "js" + assert_response :success + expected_body = %(title = "Hey";\n$("element_1").visualEffect("highlight");\n) + + %($("element_2").visualEffect("highlight");\nfooter = "Bye";) + assert_equal expected_body, @response.body + + assert_equal ['$("element_1").visualEffect("highlight");', '$("element_2").visualEffect("highlight");'], + @store.read('views/test.host/functional_caching/formatted_fragment_cached') + end end diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb new file mode 100644 index 0000000000..d7f43ad95e --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb @@ -0,0 +1,3 @@ + +<% cache do %>

ERB

<% end %> + \ No newline at end of file diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs new file mode 100644 index 0000000000..057f15e62f --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs @@ -0,0 +1,6 @@ +page.assign 'title', 'Hey' +cache do + page['element_1'].visual_effect :highlight + page['element_2'].visual_effect :highlight +end +page.assign 'footer', 'Bye' diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder new file mode 100644 index 0000000000..efdcc28e0f --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder @@ -0,0 +1,5 @@ +xml.body do + cache do + xml.p "Builder" + end +end -- cgit v1.2.3 From 0f8206104e5dfca1024d1f6bc12a8783c00527e2 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 03:18:09 +0100 Subject: RackRequest#content_type should return Mime::Type --- actionpack/test/controller/rack_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 486fe49737..67ccf1b127 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -166,6 +166,18 @@ class RackRequestParamsParsingTest < BaseRackTest end end +class RackRequestContentTypeTest < BaseRackTest + def test_html_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::HTML.to_s + assert @request.content_type.verify_request? + end + + def test_xml_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::XML.to_s + assert !@request.content_type.verify_request? + end +end + class RackRequestNeedsRewoundTest < BaseRackTest def test_body_should_be_rewound data = 'foo' -- cgit v1.2.3 From 89eec91e670ae267cd88b2b3555bfefe527f0eaa Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 03:31:45 +0100 Subject: Add tests for CgiRequest#content_type --- actionpack/test/controller/cgi_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index bf3b8b788e..7367036dec 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -168,6 +168,18 @@ class CgiRequestParamsParsingTest < BaseCgiTest end end +class CgiRequestContentTypeTest < BaseCgiTest + def test_html_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::HTML.to_s + assert @request.content_type.verify_request? + end + + def test_xml_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::XML.to_s + assert !@request.content_type.verify_request? + end +end + class CgiRequestNeedsRewoundTest < BaseCgiTest def test_body_should_be_rewound data = 'foo' -- cgit v1.2.3 From 3343eb428c502006c40368231a154d8f82be97eb Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 04:09:01 +0100 Subject: Tests for rack response content type --- actionpack/test/controller/rack_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 67ccf1b127..0636a85013 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -246,3 +246,24 @@ class RackResponseTest < BaseRackTest assert_equal ["Hello, World!"], parts end end + +class RackResponseHeadersTest < BaseRackTest + def setup + super + @response = ActionController::RackResponse.new(@request) + @output = StringIO.new('') + @headers = proc { @response.out(@output)[1] } + end + + def test_content_type + [204, 304].each do |c| + @response.headers['Status'] = c + assert !@headers.call.has_key?("Content-Type") + end + + [200, 302, 404, 500].each do |c| + @response.headers['Status'] = c + assert @headers.call.has_key?("Content-Type") + end + end +end -- cgit v1.2.3 From 5cc3ea6969f047a782fa8ac44530baeef597edb3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 04:17:28 +0100 Subject: RackResponse should not contain Status header --- actionpack/test/controller/rack_test.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 0636a85013..1cef1e0f58 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -252,18 +252,28 @@ class RackResponseHeadersTest < BaseRackTest super @response = ActionController::RackResponse.new(@request) @output = StringIO.new('') - @headers = proc { @response.out(@output)[1] } + @response.headers['Status'] = 200 end def test_content_type [204, 304].each do |c| @response.headers['Status'] = c - assert !@headers.call.has_key?("Content-Type") + assert !response_headers.has_key?("Content-Type") end [200, 302, 404, 500].each do |c| @response.headers['Status'] = c - assert @headers.call.has_key?("Content-Type") + assert response_headers.has_key?("Content-Type") end end + + def test_status + assert !response_headers.has_key?('Status') + end + + private + + def response_headers + @response.out(@output)[1] + end end -- cgit v1.2.3 From 83e29b9773ac113ceacb1e36c2f333d692de2573 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 22:51:16 -0500 Subject: Removed config.action_view.cache_template_loading, use config.cache_classes instead --- actionpack/test/abstract_unit.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 0d2e0f273a..520379fe82 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -22,7 +22,6 @@ ActiveSupport::Deprecation.debug = true ActionController::Base.logger = nil ActionController::Routing::Routes.reload rescue nil -ActionView::Base.cache_template_loading = true FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') ActionController::Base.view_paths = FIXTURE_LOAD_PATH -- cgit v1.2.3 From 1d002f6bcbd4e4f5cc421ee4da5be18839ccc4cb Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 05:01:29 +0100 Subject: Make RackRequest#request_method respect _method --- actionpack/test/controller/cgi_test.rb | 33 +++++++++++++++++++++++++++++++++ actionpack/test/controller/rack_test.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 7367036dec..9120458d24 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -53,6 +53,14 @@ class BaseCgiTest < Test::Unit::TestCase end def default_test; end + + private + + def set_content_data(data) + @request.env['CONTENT_LENGTH'] = data.length + @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + @request.env['RAW_POST_DATA'] = data + end end class CgiRequestTest < BaseCgiTest @@ -180,6 +188,31 @@ class CgiRequestContentTypeTest < BaseCgiTest end end +class CgiRequestMethodTest < BaseCgiTest + def test_get + assert_equal :get, @request.request_method + end + + def test_post + @request.env['REQUEST_METHOD'] = 'POST' + assert_equal :post, @request.request_method + end + + def test_put + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=put' + + assert_equal :put, @request.request_method + end + + def test_delete + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=delete' + + assert_equal :delete, @request.request_method + end +end + class CgiRequestNeedsRewoundTest < BaseCgiTest def test_body_should_be_rewound data = 'foo' diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 1cef1e0f58..99edb2c901 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -51,6 +51,14 @@ class BaseRackTest < Test::Unit::TestCase end def default_test; end + + private + + def set_content_data(data) + @request.env['CONTENT_LENGTH'] = data.length + @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + @request.env['RAW_POST_DATA'] = data + end end class RackRequestTest < BaseRackTest @@ -178,6 +186,31 @@ class RackRequestContentTypeTest < BaseRackTest end end +class RackRequestMethodTest < BaseRackTest + def test_get + assert_equal :get, @request.request_method + end + + def test_post + @request.env['REQUEST_METHOD'] = 'POST' + assert_equal :post, @request.request_method + end + + def test_put + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=put' + + assert_equal :put, @request.request_method + end + + def test_delete + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=delete' + + assert_equal :delete, @request.request_method + end +end + class RackRequestNeedsRewoundTest < BaseRackTest def test_body_should_be_rewound data = 'foo' -- cgit v1.2.3 From 2a7aca8ec34ebfe0e30dd5e8696918b083ef56f5 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 05:07:34 +0100 Subject: Improve rack/cgi tests --- actionpack/test/controller/cgi_test.rb | 9 +++------ actionpack/test/controller/rack_test.rb | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 9120458d24..8ca70f8595 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -57,6 +57,7 @@ class BaseCgiTest < Test::Unit::TestCase private def set_content_data(data) + @request.env['REQUEST_METHOD'] = 'POST' @request.env['CONTENT_LENGTH'] = data.length @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' @request.env['RAW_POST_DATA'] = data @@ -163,10 +164,8 @@ end class CgiRequestParamsParsingTest < BaseCgiTest def test_doesnt_break_when_content_type_has_charset - data = 'flamenco=love' - @request.env['CONTENT_LENGTH'] = data.length - @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' - @request.env['RAW_POST_DATA'] = data + set_content_data 'flamenco=love' + assert_equal({"flamenco"=> "love"}, @request.request_parameters) end @@ -199,14 +198,12 @@ class CgiRequestMethodTest < BaseCgiTest end def test_put - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=put' assert_equal :put, @request.request_method end def test_delete - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=delete' assert_equal :delete, @request.request_method diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 99edb2c901..ab8bbc3bf9 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -55,6 +55,7 @@ class BaseRackTest < Test::Unit::TestCase private def set_content_data(data) + @request.env['REQUEST_METHOD'] = 'POST' @request.env['CONTENT_LENGTH'] = data.length @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' @request.env['RAW_POST_DATA'] = data @@ -161,10 +162,8 @@ end class RackRequestParamsParsingTest < BaseRackTest def test_doesnt_break_when_content_type_has_charset - data = 'flamenco=love' - @request.env['CONTENT_LENGTH'] = data.length - @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' - @request.env['RAW_POST_DATA'] = data + set_content_data 'flamenco=love' + assert_equal({"flamenco"=> "love"}, @request.request_parameters) end @@ -197,14 +196,12 @@ class RackRequestMethodTest < BaseRackTest end def test_put - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=put' assert_equal :put, @request.request_method end def test_delete - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=delete' assert_equal :delete, @request.request_method -- cgit v1.2.3 From c64d749abdf31a2be322b1787165024067abbda7 Mon Sep 17 00:00:00 2001 From: Stefan Kaes Date: Wed, 16 Jul 2008 08:26:23 -0500 Subject: Fixed template recompile logic [#630 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/abstract_unit.rb | 1 + .../test/template/compiled_templates_test.rb | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 actionpack/test/template/compiled_templates_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 520379fe82..9db4cddd6a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -23,6 +23,7 @@ ActionController::Base.logger = nil ActionController::Routing::Routes.reload rescue nil FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') +ActionView::PathSet::Path.eager_load_templates! ActionController::Base.view_paths = FIXTURE_LOAD_PATH # Wrap tests that use Mocha and skip if unavailable. diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb new file mode 100644 index 0000000000..4b34827f91 --- /dev/null +++ b/actionpack/test/template/compiled_templates_test.rb @@ -0,0 +1,41 @@ +require 'abstract_unit' +require 'controller/fake_models' + +uses_mocha 'TestTemplateRecompilation' do + class CompiledTemplatesTest < Test::Unit::TestCase + def setup + @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + @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!", @view.render("test/hello_world.erb") + assert_equal 1, @compiled_templates.instance_methods.size + end + + def test_template_gets_recompiled_when_using_different_keys_in_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", @view.render("test/hello_world.erb", {:foo => "bar"}) + assert_equal 2, @compiled_templates.instance_methods.size + end + + def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", @view.render("test/hello_world.erb") + end + + def test_compiled_template_will_always_be_recompiled_when_rendered_if_template_is_outside_cache + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).times(3) + 3.times { assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + end + end +end -- cgit v1.2.3 From 90c930f45c5c6766306929241462ffff8f67b86e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 18:51:40 +0100 Subject: Allow Dispatcher exceptions to be handled in application.rb using rescue_from --- actionpack/test/controller/rescue_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 27fcc5e04c..da076d2090 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -62,6 +62,11 @@ class RescueController < ActionController::Base render :text => exception.message end + # This is a Dispatcher exception and should be in ApplicationController. + rescue_from ActionController::RoutingError do + render :text => 'no way' + end + def raises render :text => 'already rendered' raise "don't panic!" @@ -378,6 +383,10 @@ class RescueTest < Test::Unit::TestCase assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body end + def test_rescue_dispatcher_exceptions + RescueController.process_with_exception(@request, @response, ActionController::RoutingError.new("Route not found")) + assert_equal "no way", @response.body + end protected def with_all_requests_local(local = true) -- cgit v1.2.3 From 428b77debdab27c0bd73ec87bda8914d6acdfd3e Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 16 Jul 2008 11:07:08 -0700 Subject: fixing another timezone dependent test --- .../test/template/translation_helper_test.rb | 30 ++++------------------ 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 2263d48a65..7b94221ec0 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -18,31 +18,11 @@ class TranslationHelperTest < Test::Unit::TestCase expected = 'en-US, foo' assert_equal expected, translate(:foo) end - - # def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message - # I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never - # error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') - # end - # - # def test_error_messages_for_given_no_header_message_option_it_translates_header_message - # I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' - # error_messages_for(:object => @object, :locale => 'en-US') - # end - # - # def test_error_messages_for_given_a_message_option_it_does_not_translate_message - # I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never - # error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') - # end - # - # def test_error_messages_for_given_no_message_option_it_translates_message - # I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' - # error_messages_for(:object => @object, :locale => 'en-US') - # end - end - def test_delegates_localize_to_i18n - @time = Time.utc(2008, 7, 8, 12, 18, 38) - assert_equal "Tue, 08 Jul 2008 12:18:38 +0100", localize(@time) - assert_equal "08 Jul 12:18", localize(@time, :format => :short) + def test_delegates_localize_to_i18n + @time = Time.utc(2008, 7, 8, 12, 18, 38) + I18n.expects(:localize).with(@time) + localize @time + end end end \ No newline at end of file -- cgit v1.2.3 From 842917dea0cfdf70f158a312cc1f77f769791d8c Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 16 Jul 2008 11:30:57 -0700 Subject: moving country helpers from form_options_helper to form_country_helper again --- .../test/template/form_country_helper_test.rb | 777 ++++++++++ .../test/template/form_options_helper_test.rb | 1539 -------------------- 2 files changed, 777 insertions(+), 1539 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_country_helper_test.rb b/actionpack/test/template/form_country_helper_test.rb index 224b2e21c2..8862e08222 100644 --- a/actionpack/test/template/form_country_helper_test.rb +++ b/actionpack/test/template/form_country_helper_test.rb @@ -769,4 +769,781 @@ COUNTRIES COUNTRIES assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) end + + def test_country_select_under_fields_for + @post = Post.new + @post.origin = "Australia" + expected_select = <<-COUNTRIES + +COUNTRIES + + fields_for :post, @post do |f| + concat f.country_select("origin") + end + + assert_dom_equal(expected_select[0..-2], output_buffer) + end + + def test_country_select_under_fields_for_with_index + @post = Post.new + @post.origin = "United States" + expected_select = <<-COUNTRIES + +COUNTRIES + + fields_for :post, @post, :index => 325 do |f| + concat f.country_select("origin") + end + + assert_dom_equal(expected_select[0..-2], output_buffer) + end + + def test_country_select_under_fields_for_with_auto_index + @post = Post.new + @post.origin = "Iraq" + def @post.to_param; 325; end + + expected_select = <<-COUNTRIES + +COUNTRIES + + fields_for "post[]", @post do |f| + concat f.country_select("origin") + end + + assert_dom_equal(expected_select[0..-2], output_buffer) + end + end \ No newline at end of file diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 9dd43d7b4f..a33eb85b66 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -472,1545 +472,6 @@ uses_mocha "FormOptionsHelperTest" do assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true) end - def test_country_select - @post = Post.new - @post.origin = "Denmark" - expected_select = <<-COUNTRIES - - COUNTRIES - assert_dom_equal(expected_select[0..-2], country_select("post", "origin")) - end - - def test_country_select_with_priority_countries - @post = Post.new - @post.origin = "Denmark" - expected_select = <<-COUNTRIES - - COUNTRIES - assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) - end - - def test_country_select_with_selected_priority_country - @post = Post.new - @post.origin = "New Zealand" - expected_select = <<-COUNTRIES - - COUNTRIES - assert_dom_equal(expected_select[0..-2], country_select("post", "origin", ["New Zealand", "Nicaragua"])) - end - - def test_country_select_under_fields_for - @post = Post.new - @post.origin = "Australia" - expected_select = <<-COUNTRIES - - COUNTRIES - - fields_for :post, @post do |f| - concat f.country_select("origin") - end - - assert_dom_equal(expected_select[0..-2], output_buffer) - end - - def test_country_select_under_fields_for_with_index - @post = Post.new - @post.origin = "United States" - expected_select = <<-COUNTRIES - - COUNTRIES - - fields_for :post, @post, :index => 325 do |f| - concat f.country_select("origin") - end - - assert_dom_equal(expected_select[0..-2], output_buffer) - end - - def test_country_select_under_fields_for_with_auto_index - @post = Post.new - @post.origin = "Iraq" - def @post.to_param; 325; end - - expected_select = <<-COUNTRIES - - COUNTRIES - - fields_for "post[]", @post do |f| - concat f.country_select("origin") - end - - assert_dom_equal(expected_select[0..-2], output_buffer) - end - def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) -- cgit v1.2.3 From f7fdbae770275ccbc277c42287b9783cb00fa9fa Mon Sep 17 00:00:00 2001 From: Ripta Pasay Date: Sat, 12 Jul 2008 18:54:24 -0400 Subject: Use fully-qualified controller name when logging. [#600 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/controller/base_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 34c0200fe8..d49cc2a9aa 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -7,6 +7,7 @@ module Submodule end class ContainedNonEmptyController < ActionController::Base def public_action + render :nothing => true end hide_action :hidden_action @@ -105,6 +106,18 @@ end class PerformActionTest < Test::Unit::TestCase + class MockLogger + attr_reader :logged + + def initialize + @logged = [] + end + + def method_missing(method, *args) + @logged << args.first + end + end + def use_controller(controller_class) @controller = controller_class.new @@ -142,6 +155,13 @@ class PerformActionTest < Test::Unit::TestCase get :another_hidden_action assert_response 404 end + + def test_namespaced_action_should_log_module_name + use_controller Submodule::ContainedNonEmptyController + @controller.logger = MockLogger.new + get :public_action + assert_match /Processing\sSubmodule::ContainedNonEmptyController#public_action/, @controller.logger.logged[1] + end end class DefaultUrlOptionsTest < Test::Unit::TestCase -- cgit v1.2.3 From 99930d499e424f4560b371412e05d10476216ece Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 17 Jul 2008 18:19:09 +0100 Subject: Fix symbol cookie test --- actionpack/test/controller/cookie_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index b45fbb17d3..5a6fb49861 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -60,7 +60,7 @@ class CookieTest < Test::Unit::TestCase end def test_setting_cookie_for_fourteen_days_with_symbols - get :authenticate_for_fourteen_days + get :authenticate_for_fourteen_days_with_symbols assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"] end -- cgit v1.2.3 From 7359597004a63277851acbc87f0267d3d63e17eb Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 17 Jul 2008 16:03:48 -0500 Subject: Wrap AssetTagHelper's computed public path cache in a threadsafe store --- actionpack/test/template/asset_tag_helper_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 3cfc8fa4ed..0e7f9a94b7 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -39,8 +39,7 @@ class AssetTagHelperTest < ActionView::TestCase @controller.request = @request ActionView::Helpers::AssetTagHelper::reset_javascript_include_default - - ActionView::Base.computed_public_paths.clear + COMPUTED_PUBLIC_PATHS.clear end def teardown @@ -161,7 +160,7 @@ class AssetTagHelperTest < ActionView::TestCase ENV["RAILS_ASSET_ID"] = "" JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } - ActionView::Base.computed_public_paths.clear + COMPUTED_PUBLIC_PATHS.clear ENV["RAILS_ASSET_ID"] = "1" assert_dom_equal(%(\n\n\n\n), javascript_include_tag(:defaults)) -- cgit v1.2.3 From 1e0f94a77c717dd06a86edda97de5a4c4ad919a8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 17 Jul 2008 14:45:14 -0700 Subject: Introduce simple internationalization support --- actionpack/test/i18n_coverage | 9 --------- 1 file changed, 9 deletions(-) delete mode 100755 actionpack/test/i18n_coverage (limited to 'actionpack/test') diff --git a/actionpack/test/i18n_coverage b/actionpack/test/i18n_coverage deleted file mode 100755 index 57b54e9d47..0000000000 --- a/actionpack/test/i18n_coverage +++ /dev/null @@ -1,9 +0,0 @@ -rcov -x abstract_unit.rb \ --i action_view/helpers/number_helper.rb,action_view/helpers/date_helper.rb,action_view/helpers/active_record_helper.rb \ -template/number_helper_i18n_test.rb \ -template/date_helper_i18n_test.rb \ -template/active_record_helper_i18n_test.rb \ - -# template/number_helper_test.rb \ -# template/date_helper_test.rb \ -# template/active_record_helper_test.rb \ No newline at end of file -- cgit v1.2.3 From 57a2780f14447152ece1b1301fc6c25b2ec43da5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 16 Jul 2008 04:32:15 -0700 Subject: etag! and last_modified! conditional GET helpers --- actionpack/test/controller/render_test.rb | 152 +++++++++++++++++++----------- 1 file changed, 99 insertions(+), 53 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 9a94db4b00..041c54c7fd 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -8,14 +8,18 @@ module Fun end end - -# FIXME: crashes Ruby 1.9 class TestController < ActionController::Base layout :determine_layout def hello_world end + def conditional_hello + etag! [:foo, 123] + last_modified! Time.now.utc.beginning_of_day + render :action => 'hello_world' unless performed? + end + def render_hello_world render :template => "test/hello_world" end @@ -408,6 +412,72 @@ class RenderTest < Test::Unit::TestCase assert_equal "Goodbye, Local David", @response.body end + def test_should_render_formatted_template + get :formatted_html_erb + assert_equal 'formatted html erb', @response.body + end + + def test_should_render_formatted_xml_erb_template + get :formatted_xml_erb, :format => :xml + assert_equal 'passed formatted xml erb', @response.body + end + + def test_should_render_formatted_html_erb_template + get :formatted_xml_erb + assert_equal 'passed formatted html erb', @response.body + end + + def test_should_render_formatted_html_erb_template_with_faulty_accepts_header + @request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*" + get :formatted_xml_erb + assert_equal 'passed formatted html erb', @response.body + end + + def test_should_render_html_formatted_partial + get :partial + assert_equal 'partial html', @response.body + end + + def test_should_render_html_partial_with_dot + get :partial_dot_html + assert_equal 'partial html', @response.body + end + + def test_should_render_html_formatted_partial_with_rjs + xhr :get, :partial_as_rjs + assert_equal %(Element.replace("foo", "partial html");), @response.body + end + + def test_should_render_html_formatted_partial_with_rjs_and_js_format + xhr :get, :respond_to_partial_as_rjs + assert_equal %(Element.replace("foo", "partial html");), @response.body + end + + def test_should_render_js_partial + xhr :get, :partial, :format => 'js' + assert_equal 'partial js', @response.body + end + + def test_should_render_with_alternate_default_render + xhr :get, :render_alternate_default + assert_equal %(Element.replace("foo", "partial html");), @response.body + end + + def test_should_render_xml_but_keep_custom_content_type + get :render_xml_with_custom_content_type + assert_equal "application/atomsvc+xml", @response.content_type + end +end + +class EtagRenderTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = TestController.new + + @request.host = "www.nextangle.com" + end + def test_render_200_should_set_etag get :render_hello_world_from_variable assert_equal etag_for("hello david"), @response.headers['ETag'] @@ -460,64 +530,40 @@ class RenderTest < Test::Unit::TestCase assert_equal etag_for("\n\n

Hello

\n

This is grand!

\n\n
\n"), @response.headers['ETag'] end - def test_should_render_formatted_template - get :formatted_html_erb - assert_equal 'formatted html erb', @response.body - end - - def test_should_render_formatted_xml_erb_template - get :formatted_xml_erb, :format => :xml - assert_equal 'passed formatted xml erb', @response.body - end - - def test_should_render_formatted_html_erb_template - get :formatted_xml_erb - assert_equal 'passed formatted html erb', @response.body - end - - def test_should_render_formatted_html_erb_template_with_faulty_accepts_header - @request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*" - get :formatted_xml_erb - assert_equal 'passed formatted html erb', @response.body - end - - def test_should_render_html_formatted_partial - get :partial - assert_equal 'partial html', @response.body - end - - def test_should_render_html_partial_with_dot - get :partial_dot_html - assert_equal 'partial html', @response.body - end + protected + def etag_for(text) + %("#{Digest::MD5.hexdigest(text)}") + end +end - def test_should_render_html_formatted_partial_with_rjs - xhr :get, :partial_as_rjs - assert_equal %(Element.replace("foo", "partial html");), @response.body - end +class LastModifiedRenderTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = TestController.new - def test_should_render_html_formatted_partial_with_rjs_and_js_format - xhr :get, :respond_to_partial_as_rjs - assert_equal %(Element.replace("foo", "partial html");), @response.body + @request.host = "www.nextangle.com" + @last_modified = Time.now.utc.beginning_of_day.httpdate end - def test_should_render_js_partial - xhr :get, :partial, :format => 'js' - assert_equal 'partial js', @response.body + def test_responds_with_last_modified + get :conditional_hello + assert_equal @last_modified, @response.headers['Last-Modified'] end - def test_should_render_with_alternate_default_render - xhr :get, :render_alternate_default - assert_equal %(Element.replace("foo", "partial html");), @response.body + def test_request_not_modified + @request.headers["HTTP_IF_MODIFIED_SINCE"] = @last_modified + get :conditional_hello + assert_equal "304 Not Modified", @response.headers['Status'] + assert @response.body.blank?, @response.body + assert_equal @last_modified, @response.headers['Last-Modified'] end - def test_should_render_xml_but_keep_custom_content_type - get :render_xml_with_custom_content_type - assert_equal "application/atomsvc+xml", @response.content_type + def test_request_modified + @request.headers["HTTP_IF_MODIFIED_SINCE"] = 'Thu, 16 Jul 2008 00:00:00 GMT' + get :conditional_hello + assert_equal "200 OK", @response.headers['Status'] + assert !@response.body.blank? + assert_equal @last_modified, @response.headers['Last-Modified'] end - - protected - def etag_for(text) - %("#{Digest::MD5.hexdigest(text)}") - end end -- cgit v1.2.3 From d2ccb852d4e1f6f1b01e43f32213053ae3bef408 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 18 Jul 2008 16:00:20 -0500 Subject: Removed lagacy TemplateHandler#render API. Left in a legacy TemplateHandler and Compilable stub so plugins will not have to change anything. --- actionpack/test/controller/layout_test.rb | 12 ++---------- actionpack/test/template/render_test.rb | 30 +++++------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 92b6aa4f2f..72c01a9102 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -31,16 +31,8 @@ end class MultipleExtensions < LayoutTest end -class MabView < ActionView::TemplateHandler - def initialize(view) - end - - def render(template, local_assigns) - template.source - end -end - -ActionView::Template::register_template_handler :mab, MabView +ActionView::Template::register_template_handler :mab, + lambda { |template| template.source.inspect } class LayoutAutoDiscoveryTest < Test::Unit::TestCase def setup diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index cc5b4900dc..b1af043099 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -94,38 +94,18 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo) end - class CustomHandler < ActionView::TemplateHandler - def render(template, local_assigns) - [template.source, local_assigns].inspect - end - end - - def test_render_inline_with_custom_type - ActionView::Template.register_template_handler :foo, CustomHandler - assert_equal '["Hello, World!", {}]', @view.render(:inline => "Hello, World!", :type => :foo) - end - - def test_render_inline_with_locals_and_custom_type - ActionView::Template.register_template_handler :foo, CustomHandler - assert_equal '["Hello, <%= name %>!", {:name=>"Josh"}]', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) - end - - class CompilableCustomHandler < ActionView::TemplateHandler - include ActionView::TemplateHandlers::Compilable - - def compile(template) - "@output_buffer = ''\n" + - "@output_buffer << 'source: #{template.source.inspect}'\n" - end + CustomHandler = lambda do |template| + "@output_buffer = ''\n" + + "@output_buffer << 'source: #{template.source.inspect}'\n" end def test_render_inline_with_compilable_custom_type - ActionView::Template.register_template_handler :foo, CompilableCustomHandler + ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo) end def test_render_inline_with_locals_and_compilable_custom_type - ActionView::Template.register_template_handler :foo, CompilableCustomHandler + ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end end -- cgit v1.2.3 From c3d1fda555c4bd5f8821d830c685ae5d0e7e52d0 Mon Sep 17 00:00:00 2001 From: Tom Ward Date: Fri, 18 Jul 2008 20:14:12 -0500 Subject: Set the response content type to that of found template if not explicitly set elsewhere [#444 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/render_test.rb | 15 ++++++++++----- .../test/fixtures/test/implicit_content_type.atom.builder | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 actionpack/test/fixtures/test/implicit_content_type.atom.builder (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 041c54c7fd..76832f5713 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -197,11 +197,11 @@ class TestController < ActionController::Base def render_alternate_default # For this test, the method "default_render" is overridden: - @alternate_default_render = lambda { - render :update do |page| - page.replace :foo, :partial => 'partial' - end - } + @alternate_default_render = lambda do + render :update do |page| + page.replace :foo, :partial => 'partial' + end + end end def rescue_action(e) raise end @@ -467,6 +467,11 @@ class RenderTest < Test::Unit::TestCase get :render_xml_with_custom_content_type assert_equal "application/atomsvc+xml", @response.content_type end + + def test_should_use_implicit_content_type + get :implicit_content_type, :format => 'atom' + assert_equal Mime::ATOM, @response.content_type + end end class EtagRenderTest < Test::Unit::TestCase diff --git a/actionpack/test/fixtures/test/implicit_content_type.atom.builder b/actionpack/test/fixtures/test/implicit_content_type.atom.builder new file mode 100644 index 0000000000..2fcb32d247 --- /dev/null +++ b/actionpack/test/fixtures/test/implicit_content_type.atom.builder @@ -0,0 +1,2 @@ +xml.atom do +end -- cgit v1.2.3 From d39485078ec56e25a96e97d44b53498d8a1c7426 Mon Sep 17 00:00:00 2001 From: Tom Ward Date: Fri, 18 Jul 2008 20:19:03 -0500 Subject: Raise ArgumentError if an invalid method is specified as part of a route's conditions. Also raise an error if HEAD is specified as the method, as rails routes all HEAD requests through the equivalent GET, though doesn't return the response body [#182 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/resources_test.rb | 20 ++++++++++++++++++++ actionpack/test/controller/routing_test.rb | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 0f7924649a..e153b0cc98 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -516,6 +516,26 @@ class ResourcesTest < Test::Unit::TestCase end end + def test_should_not_allow_invalid_head_method_for_member_routes + with_routing do |set| + set.draw do |map| + assert_raises(ArgumentError) do + map.resources :messages, :member => {:something => :head} + end + end + end + end + + def test_should_not_allow_invalid_http_methods_for_member_routes + with_routing do |set| + set.draw do |map| + assert_raises(ArgumentError) do + map.resources :messages, :member => {:something => :invalid} + end + end + end + end + def test_resource_action_separator with_routing do |set| set.draw do |map| diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index c5ccb71582..079189d7b3 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1801,6 +1801,22 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end end + def test_route_requirements_with_invalid_http_method_is_invalid + assert_raises ArgumentError do + set.draw do |map| + map.connect 'valid/route', :controller => 'pages', :action => 'show', :conditions => {:method => :invalid} + end + end + end + + def test_route_requirements_with_head_method_condition_is_invalid + assert_raises ArgumentError do + set.draw do |map| + map.connect 'valid/route', :controller => 'pages', :action => 'show', :conditions => {:method => :head} + end + end + end + def test_non_path_route_requirements_match_all set.draw do |map| map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/ -- cgit v1.2.3 From c98692abcfd3576ee5fcde3910330d1eb39a18a5 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Sat, 19 Jul 2008 13:06:43 -0500 Subject: Removed handling of string parameter in link_to to have all URL generation done by url_for Signed-off-by: Joshua Peek --- actionpack/test/template/url_helper_test.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 91d5c6ffb5..867503fb29 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -28,6 +28,16 @@ class UrlHelperTest < ActionView::TestCase assert_equal "http://www.example.com?a=b&c=d", url_for("http://www.example.com?a=b&c=d") end + def test_url_for_with_back + @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'}) + assert_equal 'http://www.example.com/referer', url_for(:back) + end + + def test_url_for_with_back_and_no_referer + @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {}) + assert_equal 'javascript:history.back()', url_for(:back) + end + # todo: missing test cases def test_button_to_with_straight_url assert_dom_equal "
", button_to("Hello", "http://www.example.com") @@ -419,7 +429,6 @@ class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase end end - class Workshop attr_accessor :id, :new_record -- cgit v1.2.3 From 1b4b1aa725a4f44c3473ae99b36d7cededba2bea Mon Sep 17 00:00:00 2001 From: Kevin Glowacz Date: Sat, 19 Jul 2008 15:08:53 -0500 Subject: Fixed index and auto index for nested fields_for [#327 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/form_helper_test.rb | 116 ++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 39649c3622..52e8bf376a 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -6,7 +6,7 @@ silence_warnings do alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast) alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast) alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast) - alias_method :secret?, :secret + alias_method :secret?, :secret def new_record=(boolean) @new_record = boolean @@ -22,6 +22,7 @@ silence_warnings do attr_reader :post_id def save; @id = 1; @post_id = 1 end def new_record?; @id.nil? end + def to_param; @id; end def name @id.nil? ? 'new comment' : "comment ##{@id}" end @@ -30,7 +31,6 @@ end class Comment::Nested < Comment; end - class FormHelperTest < ActionView::TestCase tests ActionView::Helpers::FormHelper @@ -447,6 +447,117 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_nested_collections + form_for('post[]', @post) do |f| + concat f.text_field(:title) + f.fields_for('comment[]', @comment) do |c| + concat c.text_field(:name) + end + end + + expected = "
" + + "" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index + form_for('post', @post, :index => 1) do |c| + concat c.text_field(:title) + c.fields_for('comment', @comment, :index => 1) do |r| + concat r.text_field(:name) + end + end + + expected = "
" + + "" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index + form_for(:post, @post, :index => 1) do |f| + f.fields_for(:comment, @post) do |c| + concat c.text_field(:title) + end + end + + expected = "
" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index_on_both + form_for(:post, @post, :index => 1) do |f| + f.fields_for(:comment, @post, :index => 5) do |c| + concat c.text_field(:title) + end + end + + expected = "
" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_auto_index + form_for("post[]", @post) do |f| + f.fields_for(:comment, @post) do |c| + concat c.text_field(:title) + end + end + + expected = "
" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_auto_index_on_both + form_for("post[]", @post) do |f| + f.fields_for("comment[]", @post) do |c| + concat c.text_field(:title) + end + end + + expected = "
" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_index_and_auto_index + form_for("post[]", @post) do |f| + f.fields_for(:comment, @post, :index => 5) do |c| + concat c.text_field(:title) + end + end + + form_for(:post, @post, :index => 1) do |f| + f.fields_for("comment[]", @post) do |c| + concat c.text_field(:title) + end + end + + expected = "
" + + "" + + "
" + + "
" + + "" + + "
" + + assert_dom_equal expected, output_buffer + end + def test_fields_for fields_for(:post, @post) do |f| concat f.text_field(:title) @@ -831,7 +942,6 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - protected def comments_path(post) "/posts/#{post.id}/comments" -- cgit v1.2.3 From ff9f6fcc75526d9fd89be834982dec8624c909c5 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Mon, 21 Jul 2008 12:57:15 -0500 Subject: Refactor DateHelper and improve test coverage [#665 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/date_helper_test.rb | 144 ++++++++++++++++++--------- 1 file changed, 96 insertions(+), 48 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 8b4e94c67f..d8c07e731b 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -17,7 +17,7 @@ class DateHelperTest < ActionView::TestCase end end end - + def assert_distance_of_time_in_words(from, to=nil) to ||= from @@ -86,13 +86,13 @@ class DateHelperTest < ActionView::TestCase from = Time.mktime(2004, 6, 6, 21, 45, 0) assert_distance_of_time_in_words(from) end - + def test_distance_in_words_with_time_zones from = Time.mktime(2004, 6, 6, 21, 45, 0) assert_distance_of_time_in_words(from.in_time_zone('Alaska')) assert_distance_of_time_in_words(from.in_time_zone('Hawaii')) end - + def test_distance_in_words_with_different_time_zones from = Time.mktime(2004, 6, 6, 21, 45, 0) assert_distance_of_time_in_words( @@ -100,13 +100,13 @@ class DateHelperTest < ActionView::TestCase from.in_time_zone('Hawaii') ) end - + def test_distance_in_words_with_dates start_date = Date.new 1975, 1, 31 end_date = Date.new 1977, 1, 31 assert_equal("over 2 years", distance_of_time_in_words(start_date, end_date)) end - + def test_distance_in_words_with_integers assert_equal "less than a minute", distance_of_time_in_words(59) assert_equal "about 1 hour", distance_of_time_in_words(60*60) @@ -757,6 +757,26 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]"}, :class => "selector") end + def test_select_date_with_separator + expected = %(\n" + + expected << " / " + + expected << %(\n" + + expected << " / " + + expected << %(\n" + + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :start_year => 2003, :end_year => 2005, :prefix => "date[first]"}) + end + def test_select_datetime expected = %(\n) + expected << %(\n\n\n) + expected << "\n" + + expected << "/" + + expected << %(\n" + + expected << "/" + + expected << %(\n" + + expected << "—" + + expected << %(\n" + + expected << ":" + + expected << %(\n" + + assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), { :datetime_separator => "—", :date_separator => "/", :time_separator => ":", :start_year => 2003, :end_year => 2005, :prefix => "date[first]"}, :class => 'selector') + end + def test_select_time expected = %(\n} expected << %(\n" expected << " : " expected << %(\n" assert_dom_equal expected, time_select("post", "written_on") @@ -1203,11 +1255,11 @@ class DateHelperTest < ActionView::TestCase @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) expected = %(\n" expected << " : " expected << %(\n" assert_dom_equal expected, time_select("post", "written_on", :ignore_date => true) @@ -1222,15 +1274,15 @@ class DateHelperTest < ActionView::TestCase expected << %{\n} expected << %(\n" expected << " : " expected << %(\n" expected << " : " expected << %(\n" assert_dom_equal expected, time_select("post", "written_on", :include_seconds => true) @@ -1245,11 +1297,11 @@ class DateHelperTest < ActionView::TestCase expected << %{\n} expected << %(\n" expected << " : " expected << %(\n" assert_dom_equal expected, time_select("post", "written_on", {}, :class => 'selector') @@ -1268,11 +1320,11 @@ class DateHelperTest < ActionView::TestCase expected << %{\n} expected << %(\n" expected << " : " expected << %(\n" assert_dom_equal expected, output_buffer @@ -1306,7 +1358,7 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, datetime_select("post", "updated_at") end - + uses_mocha 'TestDatetimeSelectDefaultsToTimeZoneNowWhenConfigTimeZoneIsSet' do def test_datetime_select_defaults_to_time_zone_now_when_config_time_zone_is_set time = stub(:year => 2004, :month => 6, :day => 15, :hour => 16, :min => 35, :sec => 0) @@ -1370,8 +1422,7 @@ class DateHelperTest < ActionView::TestCase expected << "\n" expected << %(\n" assert_dom_equal expected, select_date(0, :end_year => Date.today.year+1, :prefix => "date[first]") @@ -1388,8 +1439,7 @@ class DateHelperTest < ActionView::TestCase expected << "\n" expected << %(\n" assert_dom_equal expected, select_date(0, :start_year => 2003, :prefix => "date[first]") @@ -1405,8 +1455,7 @@ class DateHelperTest < ActionView::TestCase expected << "\n" expected << %(\n" assert_dom_equal expected, select_date(0, :prefix => "date[first]") @@ -1422,8 +1471,7 @@ class DateHelperTest < ActionView::TestCase expected << "\n" expected << %(\n" assert_dom_equal expected, select_date(nil, :prefix => "date[first]") @@ -1530,15 +1578,15 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :include_seconds => true) @@ -1559,11 +1607,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :discard_year => true) @@ -1582,11 +1630,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :discard_month => true) @@ -1601,11 +1649,11 @@ class DateHelperTest < ActionView::TestCase expected << %{\n} expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :discard_year => true, :discard_month => true) @@ -1628,11 +1676,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :order => [:minute, :day, :hour, :month, :year, :second]) @@ -1653,11 +1701,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :order => [:day, :month]) @@ -1680,11 +1728,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :default => Time.local(2006, 9, 19, 15, 16, 35)) @@ -1727,11 +1775,11 @@ class DateHelperTest < ActionView::TestCase expected << " — " expected << %{\n" expected << " : " expected << %{\n" assert_dom_equal expected, datetime_select("post", "updated_at", :default => { :month => 10, :minute => 42, :hour => 9 }) @@ -1780,19 +1828,19 @@ class DateHelperTest < ActionView::TestCase assert_equal 2, dummy_instance_tag.send!(:default_time_from_options, :hour => 2).hour end end - + def test_instance_tag_default_time_from_options_handles_far_future_date dummy_instance_tag = ActionView::Helpers::InstanceTag.new(1,2,3) time = dummy_instance_tag.send!(:default_time_from_options, :year => 2050, :month => 2, :day => 10, :hour => 15, :min => 30, :sec => 45) assert_equal 2050, time.year end end - + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz yield ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') - end + end end -- cgit v1.2.3 From 0f43de644ea48c1ad11d4bc73307af066bb52870 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Mon, 21 Jul 2008 13:05:27 -0500 Subject: Refactored NumberHelper API to accept arguments as an options hash [#666 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/number_helper_test.rb | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 4a8d09b544..bff349a754 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -54,9 +54,16 @@ class NumberHelperTest < ActionView::TestCase assert_nil number_with_delimiter(nil) end + def test_number_with_delimiter_with_options_hash + assert_equal '12 345 678', number_with_delimiter(12345678, :delimiter => ' ') + assert_equal '12,345,678-05', number_with_delimiter(12345678.05, :separator => '-') + assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :separator => ',', :delimiter => '.') + assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',') + end + def test_number_with_precision assert_equal("111.235", number_with_precision(111.2346)) - assert_equal("31.83", number_with_precision(31.825, 2)) + assert_equal("31.83", number_with_precision(31.825, 2)) assert_equal("111.23", number_with_precision(111.2346, 2)) assert_equal("111.00", number_with_precision(111, 2)) assert_equal("111.235", number_with_precision("111.2346")) @@ -69,6 +76,17 @@ class NumberHelperTest < ActionView::TestCase assert_nil number_with_precision(nil) end + def test_number_with_precision_with_options_hash + assert_equal '111.235', number_with_precision(111.2346) + assert_equal '31.83', number_with_precision(31.825, :precision => 2) + assert_equal '111.23', number_with_precision(111.2346, :precision => 2) + assert_equal '111.00', number_with_precision(111, :precision => 2) + assert_equal '111.235', number_with_precision("111.2346") + assert_equal '31.83', number_with_precision("31.825", :precision => 2) + assert_equal '112', number_with_precision(111.50, :precision => 0) + assert_equal '1234567892', number_with_precision(1234567891.50, :precision => 0) + end + def test_number_to_human_size assert_equal '0 Bytes', number_to_human_size(0) assert_equal '1 Byte', number_to_human_size(1) @@ -94,4 +112,12 @@ class NumberHelperTest < ActionView::TestCase assert_nil number_to_human_size('x') assert_nil number_to_human_size(nil) end + + def test_number_to_human_size_with_options_hash + assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2) + assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4) + assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2) + assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4) + assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4) + end end -- cgit v1.2.3 From bc5896e708bf8070835bebe61de03b701fa5e6f7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Jul 2008 10:27:32 -0500 Subject: Memoize ActionView::Base pick_template and find_partial_path for rendering duration --- .../test/template/compiled_templates_test.rb | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 4b34827f91..52996c7fcb 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -4,7 +4,6 @@ require 'controller/fake_models' uses_mocha 'TestTemplateRecompilation' do class CompiledTemplatesTest < Test::Unit::TestCase def setup - @view = ActionView::Base.new(ActionController::Base.view_paths, {}) @compiled_templates = ActionView::Base::CompiledTemplates @compiled_templates.instance_methods.each do |m| @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ @@ -13,29 +12,33 @@ uses_mocha 'TestTemplateRecompilation' do def test_template_gets_compiled assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb") assert_equal 1, @compiled_templates.instance_methods.size end def test_template_gets_recompiled_when_using_different_keys_in_local_assigns assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", @view.render("test/hello_world.erb") - assert_equal "Hello world!", @view.render("test/hello_world.erb", {:foo => "bar"}) + assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"}) assert_equal 2, @compiled_templates.instance_methods.size end def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb") ActionView::Template.any_instance.expects(:compile!).never - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb") end - def test_compiled_template_will_always_be_recompiled_when_rendered_if_template_is_outside_cache + def test_compiled_template_will_be_recompiled_when_rendered_if_template_is_outside_cache assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + assert_equal 1, @compiled_templates.instance_methods.size end + + private + def render(*args) + ActionView::Base.new(ActionController::Base.view_paths, {}).render(*args) + end end end -- cgit v1.2.3 From 2681685450631238511cfc3c2f0fa044c1f8033a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Jul 2008 11:12:16 -0500 Subject: Extract ActiveSupport::TypedArray class to ensure an array is all of the same type [#673 state:resolved] --- actionpack/test/controller/view_paths_test.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index 85fa58a45b..b859a92cbd 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -54,10 +54,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths @controller.append_view_path(FIXTURE_LOAD_PATH) - assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths - - @controller.append_view_path([FIXTURE_LOAD_PATH]) - assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths end def test_controller_prepends_view_path_correctly @@ -68,10 +65,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths @controller.prepend_view_path(FIXTURE_LOAD_PATH) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths - - @controller.prepend_view_path([FIXTURE_LOAD_PATH]) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths end def test_template_appends_view_path_correctly -- cgit v1.2.3 From 55adaa2efc08c892bf7be55d79ac571848068256 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 23 Jul 2008 13:47:30 -0500 Subject: Fixed bc5896e, and added test case for the caching bug it originally introduced. --- actionpack/test/template/compiled_templates_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 52996c7fcb..e005aa0f03 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -30,9 +30,12 @@ uses_mocha 'TestTemplateRecompilation' do assert_equal "Hello world!", render("test/hello_world.erb") end - def test_compiled_template_will_be_recompiled_when_rendered_if_template_is_outside_cache + def test_compiled_template_will_always_be_recompiled_when_eager_loaded_templates_is_off + ActionView::PathSet::Path.expects(:eager_load_templates?).times(4).returns(false) assert_equal 0, @compiled_templates.instance_methods.size assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).times(3) + 3.times { assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } assert_equal 1, @compiled_templates.instance_methods.size end -- cgit v1.2.3 From a87462afcb6c642e59bfcd2e11e3351e2b718c38 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 24 Jul 2008 13:41:51 -0500 Subject: AbstractRequest.relative_url_root is no longer automatically configured by a HTTP header. It can now be set in your configuration environment with config.action_controller.relative_url_root --- actionpack/test/controller/redirect_test.rb | 109 +++++++++++----------- actionpack/test/controller/request_test.rb | 100 ++++++-------------- actionpack/test/controller/routing_test.rb | 10 +- actionpack/test/controller/url_rewriter_test.rb | 55 ++++++----- actionpack/test/template/asset_tag_helper_test.rb | 45 ++++----- 5 files changed, 134 insertions(+), 185 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 28da5c6163..2f8bf7b6ee 100755 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -9,11 +9,11 @@ class Workshop def initialize(id, new_record) @id, @new_record = id, new_record end - + def new_record? @new_record end - + def to_s id.to_s end @@ -24,32 +24,32 @@ class RedirectController < ActionController::Base redirect_to :action => "hello_world" end - def redirect_with_status + def redirect_with_status redirect_to({:action => "hello_world", :status => 301}) - end + end def redirect_with_status_hash redirect_to({:action => "hello_world"}, {:status => 301}) - end + end - def url_redirect_with_status + def url_redirect_with_status redirect_to("http://www.example.com", :status => :moved_permanently) - end - - def url_redirect_with_status_hash + end + + def url_redirect_with_status_hash redirect_to("http://www.example.com", {:status => 301}) - end + end - def relative_url_redirect_with_status + def relative_url_redirect_with_status redirect_to("/things/stuff", :status => :found) - end - + end + def relative_url_redirect_with_status_hash redirect_to("/things/stuff", {:status => 301}) - end - - def redirect_to_back_with_status - redirect_to :back, :status => 307 + end + + def redirect_to_back_with_status + redirect_to :back, :status => 307 end def host_redirect @@ -90,9 +90,9 @@ class RedirectController < ActionController::Base end def rescue_errors(e) raise e end - + def rescue_action(e) raise end - + protected def dashbord_url(id, message) url_for :action => "dashboard", :params => { "id" => id, "message" => message } @@ -118,48 +118,48 @@ class RedirectTest < Test::Unit::TestCase assert_equal "http://test.host/redirect/hello_world", redirect_to_url end - def test_redirect_with_status - get :redirect_with_status - assert_response 301 - assert_equal "http://test.host/redirect/hello_world", redirect_to_url - end + def test_redirect_with_status + get :redirect_with_status + assert_response 301 + assert_equal "http://test.host/redirect/hello_world", redirect_to_url + end - def test_redirect_with_status_hash + def test_redirect_with_status_hash get :redirect_with_status_hash - assert_response 301 - assert_equal "http://test.host/redirect/hello_world", redirect_to_url + assert_response 301 + assert_equal "http://test.host/redirect/hello_world", redirect_to_url + end + + def test_url_redirect_with_status + get :url_redirect_with_status + assert_response 301 + assert_equal "http://www.example.com", redirect_to_url end - - def test_url_redirect_with_status - get :url_redirect_with_status - assert_response 301 - assert_equal "http://www.example.com", redirect_to_url - end def test_url_redirect_with_status_hash get :url_redirect_with_status_hash - assert_response 301 - assert_equal "http://www.example.com", redirect_to_url - end + assert_response 301 + assert_equal "http://www.example.com", redirect_to_url + end - - def test_relative_url_redirect_with_status - get :relative_url_redirect_with_status + + def test_relative_url_redirect_with_status + get :relative_url_redirect_with_status assert_response 302 - assert_equal "http://test.host/things/stuff", redirect_to_url - end - + assert_equal "http://test.host/things/stuff", redirect_to_url + end + def test_relative_url_redirect_with_status_hash get :relative_url_redirect_with_status_hash - assert_response 301 - assert_equal "http://test.host/things/stuff", redirect_to_url - end - - def test_redirect_to_back_with_status - @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" - get :redirect_to_back_with_status - assert_response 307 - assert_equal "http://www.example.com/coming/from", redirect_to_url + assert_response 301 + assert_equal "http://test.host/things/stuff", redirect_to_url + end + + def test_redirect_to_back_with_status + @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" + get :redirect_to_back_with_status + assert_response 307 + assert_equal "http://www.example.com/coming/from", redirect_to_url end def test_simple_redirect_using_options @@ -204,20 +204,20 @@ class RedirectTest < Test::Unit::TestCase assert_response :redirect assert_equal "http://www.example.com/coming/from", redirect_to_url end - + def test_redirect_to_back_with_no_referer assert_raises(ActionController::RedirectBackError) { @request.env["HTTP_REFERER"] = nil get :redirect_to_back } end - + def test_redirect_to_record ActionController::Routing::Routes.draw do |map| map.resources :workshops map.connect ':controller/:action/:id' end - + get :redirect_to_existing_record assert_equal "http://test.host/workshops/5", redirect_to_url assert_redirected_to Workshop.new(5, false) @@ -237,7 +237,6 @@ class RedirectTest < Test::Unit::TestCase get :redirect_to_nil end end - end module ModuleTest diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 932c0e21a1..7db5264840 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -3,9 +3,14 @@ require 'action_controller/integration' class RequestTest < Test::Unit::TestCase def setup + ActionController::Base.relative_url_root = nil @request = ActionController::TestRequest.new end + def teardown + ActionController::Base.relative_url_root = nil + end + def test_remote_ip assert_equal '0.0.0.0', @request.remote_ip @@ -38,7 +43,7 @@ class RequestTest < Test::Unit::TestCase @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1,3.4.5.6' assert_equal '3.4.5.6', @request.remote_ip - + @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.1, 3.4.5.6' assert_equal '3.4.5.6', @request.remote_ip @@ -120,155 +125,105 @@ class RequestTest < Test::Unit::TestCase assert_equal ":8080", @request.port_string end - def test_relative_url_root - @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" - @request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3' - assert_equal '', @request.relative_url_root, "relative_url_root should be disabled on lighttpd" - - @request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text' - - @request.env['SCRIPT_NAME'] = nil - assert_equal "", @request.relative_url_root - - @request.env['SCRIPT_NAME'] = "/dispatch.cgi" - assert_equal "", @request.relative_url_root - - @request.env['SCRIPT_NAME'] = "/myapp.rb" - assert_equal "", @request.relative_url_root - - @request.relative_url_root = nil - @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" - assert_equal "/hieraki", @request.relative_url_root - - @request.relative_url_root = nil - @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi" - assert_equal "/collaboration/hieraki", @request.relative_url_root - - # apache/scgi case - @request.relative_url_root = nil - @request.env['SCRIPT_NAME'] = "/collaboration/hieraki" - assert_equal "/collaboration/hieraki", @request.relative_url_root - - @request.relative_url_root = nil - @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" - @request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3' - @request.env['RAILS_RELATIVE_URL_ROOT'] = "/hieraki" - assert_equal "/hieraki", @request.relative_url_root - - # @env overrides path guess - @request.relative_url_root = nil - @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" - @request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text' - @request.env['RAILS_RELATIVE_URL_ROOT'] = "/real_url" - assert_equal "/real_url", @request.relative_url_root - end - def test_request_uri @request.env['SERVER_SOFTWARE'] = 'Apache 42.342.3432' - @request.relative_url_root = nil @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1" assert_equal "/path/of/some/uri?mapped=1", @request.request_uri assert_equal "/path/of/some/uri", @request.path - @request.relative_url_root = nil @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri" assert_equal "/path/of/some/uri", @request.request_uri assert_equal "/path/of/some/uri", @request.path - @request.relative_url_root = nil @request.set_REQUEST_URI "/path/of/some/uri" assert_equal "/path/of/some/uri", @request.request_uri assert_equal "/path/of/some/uri", @request.path - @request.relative_url_root = nil @request.set_REQUEST_URI "/" assert_equal "/", @request.request_uri assert_equal "/", @request.path - @request.relative_url_root = nil @request.set_REQUEST_URI "/?m=b" assert_equal "/?m=b", @request.request_uri assert_equal "/", @request.path - @request.relative_url_root = nil @request.set_REQUEST_URI "/" @request.env['SCRIPT_NAME'] = "/dispatch.cgi" assert_equal "/", @request.request_uri assert_equal "/", @request.path - @request.relative_url_root = nil + ActionController::Base.relative_url_root = "/hieraki" @request.set_REQUEST_URI "/hieraki/" @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" assert_equal "/hieraki/", @request.request_uri assert_equal "/", @request.path + ActionController::Base.relative_url_root = nil - @request.relative_url_root = nil + ActionController::Base.relative_url_root = "/collaboration/hieraki" @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2" @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi" assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri assert_equal "/books/edit/2", @request.path + ActionController::Base.relative_url_root = nil # The following tests are for when REQUEST_URI is not supplied (as in IIS) - @request.relative_url_root = nil @request.set_REQUEST_URI nil @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1" @request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb" assert_equal "/path/of/some/uri?mapped=1", @request.request_uri assert_equal "/path/of/some/uri", @request.path + ActionController::Base.relative_url_root = '/path' @request.set_REQUEST_URI nil - @request.relative_url_root = nil @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1" @request.env['SCRIPT_NAME'] = "/path/dispatch.rb" assert_equal "/path/of/some/uri?mapped=1", @request.request_uri assert_equal "/of/some/uri", @request.path + ActionController::Base.relative_url_root = nil @request.set_REQUEST_URI nil - @request.relative_url_root = nil @request.env['PATH_INFO'] = "/path/of/some/uri" @request.env['SCRIPT_NAME'] = nil assert_equal "/path/of/some/uri", @request.request_uri assert_equal "/path/of/some/uri", @request.path @request.set_REQUEST_URI nil - @request.relative_url_root = nil @request.env['PATH_INFO'] = "/" assert_equal "/", @request.request_uri assert_equal "/", @request.path @request.set_REQUEST_URI nil - @request.relative_url_root = nil @request.env['PATH_INFO'] = "/?m=b" assert_equal "/?m=b", @request.request_uri assert_equal "/", @request.path @request.set_REQUEST_URI nil - @request.relative_url_root = nil @request.env['PATH_INFO'] = "/" @request.env['SCRIPT_NAME'] = "/dispatch.cgi" assert_equal "/", @request.request_uri assert_equal "/", @request.path + ActionController::Base.relative_url_root = '/hieraki' @request.set_REQUEST_URI nil - @request.relative_url_root = nil @request.env['PATH_INFO'] = "/hieraki/" @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" assert_equal "/hieraki/", @request.request_uri assert_equal "/", @request.path + ActionController::Base.relative_url_root = nil @request.set_REQUEST_URI '/hieraki/dispatch.cgi' - @request.relative_url_root = '/hieraki' + ActionController::Base.relative_url_root = '/hieraki' assert_equal "/dispatch.cgi", @request.path - @request.relative_url_root = nil + ActionController::Base.relative_url_root = nil @request.set_REQUEST_URI '/hieraki/dispatch.cgi' - @request.relative_url_root = '/foo' + ActionController::Base.relative_url_root = '/foo' assert_equal "/hieraki/dispatch.cgi", @request.path - @request.relative_url_root = nil + ActionController::Base.relative_url_root = nil # This test ensures that Rails uses REQUEST_URI over PATH_INFO - @request.relative_url_root = nil + ActionController::Base.relative_url_root = nil @request.env['REQUEST_URI'] = "/some/path" @request.env['PATH_INFO'] = "/another/path" @request.env['SCRIPT_NAME'] = "/dispatch.cgi" @@ -276,13 +231,12 @@ class RequestTest < Test::Unit::TestCase assert_equal "/some/path", @request.path end - def test_host_with_default_port @request.host = "rubyonrails.org" @request.port = 80 assert_equal "rubyonrails.org", @request.host_with_port end - + def test_host_with_non_default_port @request.host = "rubyonrails.org" @request.port = 81 @@ -415,15 +369,15 @@ class RequestTest < Test::Unit::TestCase @request.env["CONTENT_TYPE"] = "application/xml; charset=UTF-8" assert_equal Mime::XML, @request.content_type end - + def test_user_agent assert_not_nil @request.user_agent end - + def test_parameters @request.instance_eval { @request_parameters = { "foo" => 1 } } @request.instance_eval { @query_parameters = { "bar" => 2 } } - + assert_equal({"foo" => 1, "bar" => 2}, @request.parameters) assert_equal({"foo" => 1}, @request.request_parameters) assert_equal({"bar" => 2}, @request.query_parameters) @@ -774,19 +728,19 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase file = params['file'] foo = params['foo'] - + if RUBY_VERSION > '1.9' assert_kind_of File, file else assert_kind_of Tempfile, file end - + assert_equal 'file.txt', file.original_filename assert_equal "text/plain", file.content_type - + assert_equal 'bar', foo end - + def test_large_text_file params = process('large_text_file') assert_equal %w(file foo), params.keys.sort diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 079189d7b3..84996fd6b1 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -731,15 +731,10 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def request @request ||= MockRequest.new(:host => "named.route.test", :method => :get) end - - def relative_url_root=(value) - request.relative_url_root=value - end end class MockRequest - attr_accessor :path, :path_parameters, :host, :subdomains, :domain, - :method, :relative_url_root + attr_accessor :path, :path_parameters, :host, :subdomains, :domain, :method def initialize(values={}) values.each { |key, value| send("#{key}=", value) } @@ -920,10 +915,11 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_basic_named_route_with_relative_url_root rs.add_named_route :home, '', :controller => 'content', :action => 'list' x = setup_for_named_route - x.relative_url_root="/foo" + ActionController::Base.relative_url_root = "/foo" assert_equal("http://named.route.test/foo/", x.send(:home_url)) assert_equal "/foo/", x.send(:home_path) + ActionController::Base.relative_url_root = nil end def test_named_route_with_option diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index a9974db5d5..64e9a085ca 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -7,7 +7,7 @@ class UrlRewriterTests < Test::Unit::TestCase @request = ActionController::TestRequest.new @params = {} @rewriter = ActionController::UrlRewriter.new(@request, @params) - end + end def test_port assert_equal('http://test.host:1271/c/a/i', @@ -24,7 +24,7 @@ class UrlRewriterTests < Test::Unit::TestCase @rewriter.rewrite(:protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i') ) end - + def test_user_name_and_password assert_equal( 'http://david:secret@test.host/c/a/i', @@ -38,12 +38,12 @@ class UrlRewriterTests < Test::Unit::TestCase @rewriter.rewrite(:user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i') ) end - - def test_anchor - assert_equal( - 'http://test.host/c/a/i#anchor', - @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor') - ) + + def test_anchor + assert_equal( + 'http://test.host/c/a/i#anchor', + @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor') + ) end def test_overwrite_params @@ -55,12 +55,12 @@ class UrlRewriterTests < Test::Unit::TestCase u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'}) assert_match %r(/hi/hi/2$), u end - + def test_overwrite_removes_original @params[:controller] = 'search' @params[:action] = 'list' @params[:list_page] = 1 - + assert_equal '/search/list?list_page=2', @rewriter.rewrite(:only_path => true, :overwrite_params => {"list_page" => 2}) u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2}) assert_equal 'http://test.host/search/list?list_page=2', u @@ -86,19 +86,19 @@ class UrlRewriterTests < Test::Unit::TestCase end class UrlWriterTests < Test::Unit::TestCase - + class W include ActionController::UrlWriter end - + def teardown W.default_url_options.clear end - + def add_host! W.default_url_options[:host] = 'www.basecamphq.com' end - + def test_exception_is_thrown_without_host assert_raises RuntimeError do W.new.url_for :controller => 'c', :action => 'a', :id => 'i' @@ -110,35 +110,35 @@ class UrlWriterTests < Test::Unit::TestCase W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor') ) end - + def test_default_host add_host! assert_equal('http://www.basecamphq.com/c/a/i', W.new.url_for(:controller => 'c', :action => 'a', :id => 'i') ) end - + def test_host_may_be_overridden add_host! assert_equal('http://37signals.basecamphq.com/c/a/i', W.new.url_for(:host => '37signals.basecamphq.com', :controller => 'c', :action => 'a', :id => 'i') ) end - + def test_port add_host! assert_equal('http://www.basecamphq.com:3000/c/a/i', W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :port => 3000) ) end - + def test_protocol add_host! assert_equal('https://www.basecamphq.com/c/a/i', W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') ) end - + def test_protocol_with_and_without_separator add_host! assert_equal('https://www.basecamphq.com/c/a/i', @@ -184,15 +184,15 @@ class UrlWriterTests < Test::Unit::TestCase end def test_relative_url_root_is_respected - orig_relative_url_root = ActionController::AbstractRequest.relative_url_root - ActionController::AbstractRequest.relative_url_root = '/subdir' + orig_relative_url_root = ActionController::Base.relative_url_root + ActionController::Base.relative_url_root = '/subdir' add_host! assert_equal('https://www.basecamphq.com/subdir/c/a/i', W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') ) ensure - ActionController::AbstractRequest.relative_url_root = orig_relative_url_root + ActionController::Base.relative_url_root = orig_relative_url_root end def test_named_routes @@ -217,8 +217,8 @@ class UrlWriterTests < Test::Unit::TestCase end def test_relative_url_root_is_respected_for_named_routes - orig_relative_url_root = ActionController::AbstractRequest.relative_url_root - ActionController::AbstractRequest.relative_url_root = '/subdir' + orig_relative_url_root = ActionController::Base.relative_url_root + ActionController::Base.relative_url_root = '/subdir' ActionController::Routing::Routes.draw do |map| map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index' @@ -231,7 +231,7 @@ class UrlWriterTests < Test::Unit::TestCase controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again') ensure ActionController::Routing::Routes.load! - ActionController::AbstractRequest.relative_url_root = orig_relative_url_root + ActionController::Base.relative_url_root = orig_relative_url_root end def test_only_path @@ -239,14 +239,14 @@ class UrlWriterTests < Test::Unit::TestCase map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index' map.connect ':controller/:action/:id' end - + # We need to create a new class in order to install the new named route. kls = Class.new { include ActionController::UrlWriter } controller = kls.new assert controller.respond_to?(:home_url) assert_equal '/brave/new/world', controller.send(:url_for, :controller => 'brave', :action => 'new', :id => 'world', :only_path => true) - + assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true)) assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama')) ensure @@ -306,5 +306,4 @@ class UrlWriterTests < Test::Unit::TestCase def extract_params(url) url.split('?', 2).last.split('&') end - end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 0e7f9a94b7..8410e82c3c 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -30,7 +30,6 @@ class AssetTagHelperTest < ActionView::TestCase end.new @request = Class.new do - def relative_url_root() "" end def protocol() 'http://' end def ssl?() false end def host_with_port() 'localhost' end @@ -118,7 +117,7 @@ class AssetTagHelperTest < ActionView::TestCase %(image_path("xml")) => %(/images/xml), %(image_path("xml.png")) => %(/images/xml.png), %(image_path("dir/xml.png")) => %(/images/dir/xml.png), - %(image_path("/dir/xml.png")) => %(/dir/xml.png) + %(image_path("/dir/xml.png")) => %(/dir/xml.png) } PathToImageToTag = { @@ -173,7 +172,7 @@ class AssetTagHelperTest < ActionView::TestCase ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2' assert_dom_equal %(\n\n\n\n\n\n\n), javascript_include_tag(:defaults) end - + def test_custom_javascript_expansions ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"] assert_dom_equal %(\n\n\n\n), javascript_include_tag('first', :monkey, 'last') @@ -216,7 +215,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_image_path ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - + def test_path_to_image_alias_for_image_path PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -224,7 +223,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_image_tag ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - + def test_timebased_asset_id expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s assert_equal %(Rails), image_tag("rails.png") @@ -233,7 +232,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_should_skip_asset_id_on_complete_url assert_equal %(Rails), image_tag("http://www.example.com/rails.png") end - + def test_should_use_preset_asset_id ENV["RAILS_ASSET_ID"] = "4500" assert_equal %(Rails), image_tag("rails.png") @@ -255,14 +254,14 @@ class AssetTagHelperTest < ActionView::TestCase ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' ActionController::Base.perform_caching = true - + assert_dom_equal( %(), javascript_include_tag(:all, :cache => true) ) assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) - + assert_dom_equal( %(), javascript_include_tag(:all, :cache => "money") @@ -344,7 +343,7 @@ class AssetTagHelperTest < ActionView::TestCase ensure FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) end - + def test_caching_javascript_include_tag_with_all_and_recursive_puts_defaults_at_the_start_of_the_file ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' @@ -390,7 +389,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_caching_javascript_include_tag_when_caching_off ENV["RAILS_ASSET_ID"] = "" ActionController::Base.perform_caching = false - + assert_dom_equal( %(\n\n\n\n\n\n\n), javascript_include_tag(:all, :cache => true) @@ -402,7 +401,7 @@ class AssetTagHelperTest < ActionView::TestCase ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) - + assert_dom_equal( %(\n\n\n\n\n\n\n), javascript_include_tag(:all, :cache => "money") @@ -420,7 +419,7 @@ class AssetTagHelperTest < ActionView::TestCase ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' ActionController::Base.perform_caching = true - + assert_dom_equal( %(), stylesheet_link_tag(:all, :cache => true) @@ -459,7 +458,7 @@ class AssetTagHelperTest < ActionView::TestCase def test_caching_stylesheet_include_tag_when_caching_off ENV["RAILS_ASSET_ID"] = "" ActionController::Base.perform_caching = false - + assert_dom_equal( %(\n\n), stylesheet_link_tag(:all, :cache => true) @@ -471,7 +470,7 @@ class AssetTagHelperTest < ActionView::TestCase ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) - + assert_dom_equal( %(\n\n), stylesheet_link_tag(:all, :cache => "money") @@ -490,6 +489,8 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase tests ActionView::Helpers::AssetTagHelper def setup + ActionController::Base.relative_url_root = "/collaboration/hieraki" + @controller = Class.new do attr_accessor :request @@ -497,22 +498,22 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase "http://www.example.com/collaboration/hieraki" end end.new - - @request = Class.new do - def relative_url_root - "/collaboration/hieraki" - end + @request = Class.new do def protocol 'gopher://' end end.new - + @controller.request = @request - + ActionView::Helpers::AssetTagHelper::reset_javascript_include_default end + def teardown + ActionController::Base.relative_url_root = nil + end + def test_should_compute_proper_path assert_dom_equal(%(), auto_discovery_link_tag) assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr")) @@ -521,7 +522,7 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) end - + def test_should_ignore_relative_root_path_on_complete_url assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png")) end -- cgit v1.2.3 From f7abf0c9db61621b3f27061debd7983075cdca61 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Sun, 27 Jul 2008 16:34:20 -0500 Subject: error_message_on takes an options hash instead of ordered parameters [#704 state:resolved] Signed-off-by: Joshua Peek --- .../test/template/active_record_helper_test.rb | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index dfc30e651a..e46f95d18b 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -10,17 +10,17 @@ class ActiveRecordHelperTest < ActionView::TestCase alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast) alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast) end - + User = Struct.new("User", :email) User.class_eval do alias_method :email_before_type_cast, :email unless respond_to?(:email_before_type_cast) end - + Column = Struct.new("Column", :type, :name, :human_name) end def setup_post - @post = Post.new + @post = Post.new def @post.errors Class.new { def on(field) @@ -33,12 +33,12 @@ class ActiveRecordHelperTest < ActionView::TestCase false end end - def empty?() false end - def count() 1 end + def empty?() false end + def count() 1 end def full_messages() [ "Author name can't be empty" ] end }.new end - + def @post.new_record?() true end def @post.to_param() nil end @@ -58,16 +58,16 @@ class ActiveRecordHelperTest < ActionView::TestCase end def setup_user - @user = User.new + @user = User.new def @user.errors Class.new { def on(field) field == "email" end - def empty?() false end - def count() 1 end + def empty?() false end + def count() 1 end def full_messages() [ "User email can't be empty" ] end }.new end - + def @user.new_record?() true end def @user.to_param() nil end @@ -81,7 +81,7 @@ class ActiveRecordHelperTest < ActionView::TestCase @user.email = "" end - + def protect_against_forgery? @protect_against_forgery ? true : false end @@ -92,7 +92,7 @@ class ActiveRecordHelperTest < ActionView::TestCase setup_user @response = ActionController::TestResponse.new - + @controller = Object.new def @controller.url_for(options) options = options.symbolize_keys @@ -111,7 +111,7 @@ class ActiveRecordHelperTest < ActionView::TestCase assert_dom_equal( %(
), text_area("post", "body") - ) + ) end def test_text_field_with_errors @@ -140,7 +140,7 @@ class ActiveRecordHelperTest < ActionView::TestCase form("post") ) end - + def test_form_with_protect_against_forgery @protect_against_forgery = true @request_forgery_protection_token = 'authenticity_token' @@ -150,7 +150,7 @@ class ActiveRecordHelperTest < ActionView::TestCase form("post") ) end - + def test_form_with_method_option assert_dom_equal( %(


\n


), @@ -211,9 +211,9 @@ class ActiveRecordHelperTest < ActionView::TestCase other_post = @post assert_dom_equal "
can't be empty
", error_message_on(other_post, :author_name) end - - def test_error_message_on_should_use_options - assert_dom_equal "
beforecan't be emptyafter
", error_message_on(:post, :author_name, "before", "after", "differentError") + + def test_error_message_on_with_options_hash + assert_dom_equal "
beforecan't be emptyafter
", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') end def test_error_messages_for_many_objects @@ -224,10 +224,10 @@ class ActiveRecordHelperTest < ActionView::TestCase # add the default to put post back in the title assert_dom_equal %(

2 errors prohibited this post from being saved

There were problems with the following fields:

  • User email can't be empty
  • Author name can't be empty
), error_messages_for("user", "post", :object_name => "post") - + # symbols work as well assert_dom_equal %(

2 errors prohibited this post from being saved

There were problems with the following fields:

  • User email can't be empty
  • Author name can't be empty
), error_messages_for(:user, :post, :object_name => :post) - + # any default works too assert_dom_equal %(

2 errors prohibited this monkey from being saved

There were problems with the following fields:

  • User email can't be empty
  • Author name can't be empty
), error_messages_for(:user, :post, :object_name => "monkey") @@ -242,7 +242,7 @@ class ActiveRecordHelperTest < ActionView::TestCase message = "Please fix the following fields and resubmit:" assert_dom_equal %(

#{header_message}

#{message}

  • User email can't be empty
  • Author name can't be empty
), error_messages_for(:user, :post, :header_message => header_message, :message => message) end - + def test_error_messages_for_non_instance_variable actual_user = @user actual_post = @post @@ -251,14 +251,14 @@ class ActiveRecordHelperTest < ActionView::TestCase #explicitly set object assert_dom_equal %(

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", :object => actual_post) - + #multiple objects assert_dom_equal %(

2 errors prohibited this user from being saved

There were problems with the following fields:

  • User email can't be empty
  • Author name can't be empty
), error_messages_for("user", "post", :object => [actual_user, actual_post]) - + #nil object assert_equal '', error_messages_for('user', :object => nil) end - + def test_form_with_string_multipart assert_dom_equal( %(


\n


), -- cgit v1.2.3 From 10d9fe4bf3110c1d5de0c6b509fe0cbb9d5eda1d Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Sun, 27 Jul 2008 16:49:19 -0500 Subject: Refactored TextHelper#truncate, highlight, excerpt, word_wrap and auto_link to accept options hash [#705 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/text_helper_test.rb | 51 +++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 4999525939..a31d532567 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -35,8 +35,8 @@ class TextHelperTest < ActionView::TestCase end def test_truncate - assert_equal "Hello World!", truncate("Hello World!", 12) - assert_equal "Hello Wor...", truncate("Hello World!!", 12) + assert_equal "Hello World!", truncate("Hello World!", :length => 12) + assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12) end def test_truncate_should_use_default_length_of_30 @@ -44,23 +44,29 @@ class TextHelperTest < ActionView::TestCase assert_equal str[0...27] + "...", truncate(str) end + def test_truncate_with_options_hash + assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]") + assert_equal "Hello W...", truncate("Hello World!", :length => 10) + assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10) + end + if RUBY_VERSION < '1.9.0' def test_truncate_multibyte with_kcode 'none' do - assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10) + assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) end with_kcode 'u' do assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...", - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", 10) + truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", :length => 10) end end else def test_truncate_multibyte assert_equal "\354\225\210\353\205\225\355...", - truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10) + truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'), - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), 10) + truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10) end end @@ -88,7 +94,7 @@ class TextHelperTest < ActionView::TestCase assert_equal ' ', highlight(' ', 'blank text is returned verbatim') end - def test_highlighter_with_regexp + def test_highlight_with_regexp assert_equal( "This is a beautiful! morning", highlight("This is a beautiful! morning", "beautiful!") @@ -105,10 +111,17 @@ class TextHelperTest < ActionView::TestCase ) end - def test_highlighting_multiple_phrases_in_one_pass + def test_highlight_with_multiple_phrases_in_one_pass assert_equal %(wow em), highlight('wow em', %w(wow em), '\1') end + def test_highlight_with_options_hash + assert_equal( + "This is a beautiful morning, but also a beautiful day", + highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '\1') + ) + end + def test_excerpt assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5)) assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5)) @@ -138,6 +151,16 @@ class TextHelperTest < ActionView::TestCase assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5)) end + def test_excerpt_with_options_hash + assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5)) + assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5)) + assert_equal( + "This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]", + excerpt("This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome temperatures. So what are you gonna do about it?", "very", + :omission => "[...]") + ) + end + if RUBY_VERSION < '1.9' def test_excerpt_with_utf8 with_kcode('u') do @@ -162,6 +185,10 @@ class TextHelperTest < ActionView::TestCase assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15)) end + def test_word_wrap_with_options_hash + assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15)) + end + def test_pluralization assert_equal("1 count", pluralize(1, "count")) assert_equal("2 counts", pluralize(2, "count")) @@ -285,7 +312,13 @@ class TextHelperTest < ActionView::TestCase url = "http://api.rubyonrails.com/Foo.html" email = "fantabulous@shiznadel.ic" - assert_equal %(

#{url[0...7]}...
#{email[0...7]}...

), auto_link("

#{url}
#{email}

") { |url| truncate(url, 10) } + assert_equal %(

#{url[0...7]}...
#{email[0...7]}...

), auto_link("

#{url}
#{email}

") { |url| truncate(url, :length => 10) } + end + + def test_auto_link_with_options_hash + assert_equal 'Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.', + auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.", + :link => :all, :html => { :class => "menu", :target => "_blank" }) end def test_cycle_class -- cgit v1.2.3 From e0513e33c4da60255e7c1aa71babcc9414f26858 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Jul 2008 13:38:20 -0500 Subject: Routing whitespace cleanup --- actionpack/test/controller/routing_test.rb | 1 + actionpack/test/controller/test_test.rb | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 84996fd6b1..22e394dc95 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -834,6 +834,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do puts "#{1 / per_url} url/s\n\n" end end + def test_time_generation n = 5000 if RunTimeTests diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index b624005a57..61b8c83ee0 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -64,7 +64,7 @@ class TestTest < Test::Unit::TestCase HTML end - + def test_xml_output response.content_type = "application/xml" render :text => < { :count => 1, :only => { :tag => "img" } } } } end - + def test_should_not_impose_childless_html_tags_in_xml process :test_xml_output @@ -486,7 +486,7 @@ XML assert_nil @request.env['HTTP_X_REQUESTED_WITH'] end - def test_header_properly_reset_after_get_request + def test_header_properly_reset_after_get_request get :test_params @request.recycle! assert_nil @request.instance_variable_get("@request_method") @@ -532,15 +532,15 @@ XML assert_equal file.path, file.local_path assert_equal expected, file.read end - + def test_test_uploaded_file_with_binary filename = 'mona_lisa.jpg' path = "#{FILES_DIR}/#{filename}" content_type = 'image/png' - + binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary) assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read - + plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type) assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read end @@ -549,10 +549,10 @@ XML filename = 'mona_lisa.jpg' path = "#{FILES_DIR}/#{filename}" content_type = 'image/jpg' - + binary_file_upload = fixture_file_upload(path, content_type, :binary) assert_equal File.open(path, READ_BINARY).read, binary_file_upload.read - + plain_file_upload = fixture_file_upload(path, content_type) assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read end @@ -584,7 +584,7 @@ XML get :test_send_file assert_nothing_raised(NoMethodError) { @response.binary_content } end - + protected def with_foo_routing with_routing do |set| @@ -597,7 +597,6 @@ XML end end - class CleanBacktraceTest < Test::Unit::TestCase def test_should_reraise_the_same_object exception = Test::Unit::AssertionFailedError.new('message') @@ -658,7 +657,7 @@ end class NamedRoutesControllerTest < ActionController::TestCase tests ContentController - + def test_should_be_able_to_use_named_routes_before_a_request_is_done with_routing do |set| set.draw { |map| map.resources :contents } -- cgit v1.2.3 From a5db1488251304ec93256654859b430148f0c506 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Jul 2008 13:41:42 -0500 Subject: Prepare Route#generate and Route#recognize early. Also refactor segments a bit to try to make immutable. --- actionpack/test/controller/routing_test.rb | 151 +++++++++++------------------ actionpack/test/controller/test_test.rb | 4 +- 2 files changed, 57 insertions(+), 98 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 22e394dc95..6cf134c26f 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -67,66 +67,56 @@ class SegmentTest < Test::Unit::TestCase end def test_interpolation_statement - s = ROUTING::StaticSegment.new - s.value = "Hello" + s = ROUTING::StaticSegment.new("Hello") assert_equal "Hello", eval(s.interpolation_statement([])) assert_equal "HelloHello", eval(s.interpolation_statement([s])) - s2 = ROUTING::StaticSegment.new - s2.value = "-" + s2 = ROUTING::StaticSegment.new("-") assert_equal "Hello-Hello", eval(s.interpolation_statement([s, s2])) - s3 = ROUTING::StaticSegment.new - s3.value = "World" + s3 = ROUTING::StaticSegment.new("World") assert_equal "Hello-World", eval(s3.interpolation_statement([s, s2])) end end class StaticSegmentTest < Test::Unit::TestCase def test_interpolation_chunk_should_respect_raw - s = ROUTING::StaticSegment.new - s.value = 'Hello World' - assert ! s.raw? + s = ROUTING::StaticSegment.new('Hello World') + assert !s.raw? assert_equal 'Hello%20World', s.interpolation_chunk - s.raw = true + s = ROUTING::StaticSegment.new('Hello World', :raw => true) assert s.raw? assert_equal 'Hello World', s.interpolation_chunk end def test_regexp_chunk_should_escape_specials - s = ROUTING::StaticSegment.new - - s.value = 'Hello*World' + s = ROUTING::StaticSegment.new('Hello*World') assert_equal 'Hello\*World', s.regexp_chunk - s.value = 'HelloWorld' + s = ROUTING::StaticSegment.new('HelloWorld') assert_equal 'HelloWorld', s.regexp_chunk end def test_regexp_chunk_should_add_question_mark_for_optionals - s = ROUTING::StaticSegment.new - s.value = "/" - s.is_optional = true + s = ROUTING::StaticSegment.new("/", :optional => true) assert_equal "/?", s.regexp_chunk - s.value = "hello" + s = ROUTING::StaticSegment.new("hello", :optional => true) assert_equal "(?:hello)?", s.regexp_chunk end end class DynamicSegmentTest < Test::Unit::TestCase - def segment + def segment(options = {}) unless @segment - @segment = ROUTING::DynamicSegment.new - @segment.key = :a + @segment = ROUTING::DynamicSegment.new(:a, options) end @segment end def test_extract_value - s = ROUTING::DynamicSegment.new - s.key = :a + s = ROUTING::DynamicSegment.new(:a) hash = {:a => '10', :b => '20'} assert_equal '10', eval(s.extract_value) @@ -149,31 +139,31 @@ class DynamicSegmentTest < Test::Unit::TestCase end def test_regexp_value_check_rejects_nil - segment.regexp = /\d+/ + segment = segment(:regexp => /\d+/) + a_value = nil - assert ! eval(segment.value_check) + assert !eval(segment.value_check) end def test_optional_regexp_value_check_should_accept_nil - segment.regexp = /\d+/ - segment.is_optional = true + segment = segment(:regexp => /\d+/, :optional => true) + a_value = nil assert eval(segment.value_check) end def test_regexp_value_check_rejects_no_match - segment.regexp = /\d+/ + segment = segment(:regexp => /\d+/) a_value = "Hello20World" - assert ! eval(segment.value_check) + assert !eval(segment.value_check) a_value = "20Hi" - assert ! eval(segment.value_check) + assert !eval(segment.value_check) end def test_regexp_value_check_accepts_match - segment.regexp = /\d+/ - + segment = segment(:regexp => /\d+/) a_value = "30" assert eval(segment.value_check) end @@ -184,14 +174,14 @@ class DynamicSegmentTest < Test::Unit::TestCase end def test_optional_value_needs_no_check - segment.is_optional = true + segment = segment(:optional => true) + a_value = nil assert_equal nil, segment.value_check end def test_regexp_value_check_should_accept_match_with_default - segment.regexp = /\d+/ - segment.default = '200' + segment = segment(:regexp => /\d+/, :default => '200') a_value = '100' assert eval(segment.value_check) @@ -234,7 +224,7 @@ class DynamicSegmentTest < Test::Unit::TestCase end def test_extraction_code_should_return_on_mismatch - segment.regexp = /\d+/ + segment = segment(:regexp => /\d+/) hash = merged = {:a => 'Hi', :b => '3'} options = {:b => '3'} a_value = nil @@ -292,7 +282,7 @@ class DynamicSegmentTest < Test::Unit::TestCase end def test_value_regexp_should_match_exacly - segment.regexp = /\d+/ + segment = segment(:regexp => /\d+/) assert_no_match segment.value_regexp, "Hello 10 World" assert_no_match segment.value_regexp, "Hello 10" assert_no_match segment.value_regexp, "10 World" @@ -300,40 +290,36 @@ class DynamicSegmentTest < Test::Unit::TestCase end def test_regexp_chunk_should_return_string - segment.regexp = /\d+/ + segment = segment(:regexp => /\d+/) assert_kind_of String, segment.regexp_chunk end def test_build_pattern_non_optional_with_no_captures # Non optional - a_segment = ROUTING::DynamicSegment.new - a_segment.regexp = /\d+/ #number_of_captures is 0 + a_segment = ROUTING::DynamicSegment.new(nil, :regexp => /\d+/) assert_equal "(\\d+)stuff", a_segment.build_pattern('stuff') end def test_build_pattern_non_optional_with_captures # Non optional - a_segment = ROUTING::DynamicSegment.new - a_segment.regexp = /(\d+)(.*?)/ #number_of_captures is 2 + a_segment = ROUTING::DynamicSegment.new(nil, :regexp => /(\d+)(.*?)/) assert_equal "((\\d+)(.*?))stuff", a_segment.build_pattern('stuff') end def test_optionality_implied - a_segment = ROUTING::DynamicSegment.new - a_segment.key = :id + a_segment = ROUTING::DynamicSegment.new(:id) assert a_segment.optionality_implied? - a_segment.key = :action + a_segment = ROUTING::DynamicSegment.new(:action) assert a_segment.optionality_implied? end def test_modifiers_must_be_handled_sensibly - a_segment = ROUTING::DynamicSegment.new - a_segment.regexp = /david|jamis/i + a_segment = ROUTING::DynamicSegment.new(nil, :regexp => /david|jamis/i) assert_equal "((?i-mx:david|jamis))stuff", a_segment.build_pattern('stuff') - a_segment.regexp = /david|jamis/x + a_segment = ROUTING::DynamicSegment.new(nil, :regexp => /david|jamis/x) assert_equal "((?x-mi:david|jamis))stuff", a_segment.build_pattern('stuff') - a_segment.regexp = /david|jamis/ + a_segment = ROUTING::DynamicSegment.new(nil, :regexp => /david|jamis/) assert_equal "(david|jamis)stuff", a_segment.build_pattern('stuff') end end @@ -560,7 +546,7 @@ class RouteBuilderTest < Test::Unit::TestCase action = segments[-4] assert_equal :action, action.key - action.regexp = /show|in/ # Use 'in' to check partial matches + segments[-4] = ROUTING::DynamicSegment.new(:action, :regexp => /show|in/) builder.assign_default_route_options(segments) @@ -661,10 +647,10 @@ class RoutingTest < Test::Unit::TestCase ActionController::Routing.controller_paths = [] assert_equal [], ActionController::Routing.possible_controllers - ActionController::Routing::Routes.load! ActionController::Routing.controller_paths = [ root, root + '/app/controllers', root + '/vendor/plugins/bad_plugin/lib' ] + ActionController::Routing::Routes.load! assert_equal ["admin/user", "plugin", "user"], ActionController::Routing.possible_controllers.sort ensure @@ -1374,34 +1360,20 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end def slash_segment(is_optional = false) - returning ROUTING::DividerSegment.new('/') do |s| - s.is_optional = is_optional - end + ROUTING::DividerSegment.new('/', :optional => is_optional) end def default_route unless defined?(@default_route) - @default_route = ROUTING::Route.new - - @default_route.segments << (s = ROUTING::StaticSegment.new) - s.value = '/' - s.raw = true - - @default_route.segments << (s = ROUTING::DynamicSegment.new) - s.key = :controller - - @default_route.segments << slash_segment(:optional) - @default_route.segments << (s = ROUTING::DynamicSegment.new) - s.key = :action - s.default = 'index' - s.is_optional = true - - @default_route.segments << slash_segment(:optional) - @default_route.segments << (s = ROUTING::DynamicSegment.new) - s.key = :id - s.is_optional = true - - @default_route.segments << slash_segment(:optional) + segments = [] + segments << ROUTING::StaticSegment.new('/', :raw => true) + segments << ROUTING::DynamicSegment.new(:controller) + segments << slash_segment(:optional) + segments << ROUTING::DynamicSegment.new(:action, :default => 'index', :optional => true) + segments << slash_segment(:optional) + segments << ROUTING::DynamicSegment.new(:id, :optional => true) + segments << slash_segment(:optional) + @default_route = ROUTING::Route.new(segments).freeze end @default_route end @@ -1489,29 +1461,16 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end def test_significant_keys - user_url = ROUTING::Route.new - user_url.segments << (s = ROUTING::StaticSegment.new) - s.value = '/' - s.raw = true - - user_url.segments << (s = ROUTING::StaticSegment.new) - s.value = 'user' - - user_url.segments << (s = ROUTING::StaticSegment.new) - s.value = '/' - s.raw = true - s.is_optional = true - - user_url.segments << (s = ROUTING::DynamicSegment.new) - s.key = :user - - user_url.segments << (s = ROUTING::StaticSegment.new) - s.value = '/' - s.raw = true - s.is_optional = true + segments = [] + segments << ROUTING::StaticSegment.new('/', :raw => true) + segments << ROUTING::StaticSegment.new('user') + segments << ROUTING::StaticSegment.new('/', :raw => true, :optional => true) + segments << ROUTING::DynamicSegment.new(:user) + segments << ROUTING::StaticSegment.new('/', :raw => true, :optional => true) - user_url.requirements = {:controller => 'users', :action => 'show'} + requirements = {:controller => 'users', :action => 'show'} + user_url = ROUTING::Route.new(segments, requirements) keys = user_url.significant_keys.sort_by { |k| k.to_s } assert_equal [:action, :controller, :user], keys end diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 61b8c83ee0..58d9ca537f 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -117,8 +117,8 @@ XML @controller = TestController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new - ActionController::Routing::Routes.reload ActionController::Routing.use_controllers! %w(content admin/user test_test/test) + ActionController::Routing::Routes.load_routes! end def teardown @@ -412,7 +412,7 @@ XML def test_assert_routing_with_method with_routing do |set| - set.draw { |map| map.resources(:content) } + set.draw { |map| map.resources(:content) } assert_routing({ :method => 'post', :path => 'content' }, { :controller => 'content', :action => 'create' }) end end -- cgit v1.2.3 From 7aaf1689dda863b72623f0e52ad87e2b739cb22b Mon Sep 17 00:00:00 2001 From: Jan De Poorter Date: Tue, 29 Jul 2008 13:11:38 +0200 Subject: Fix that label_tag doesn't take a symbol for a name. [#719 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/form_tag_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 4e4102aec7..9b41ff8179 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -190,6 +190,12 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_label_tag_with_symbol + actual = label_tag :title + expected = %() + assert_dom_equal expected, actual + end + def test_label_tag_with_text actual = label_tag "title", "My Title" expected = %() -- cgit v1.2.3 From fea7771d2294bd810d04c03c125ceac5d6bb9806 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Tue, 29 Jul 2008 21:47:02 -0500 Subject: Updated NumberHelper: Full i18n support (except number_to_phone), consolidated API (almost all methods now support :precision, :delimiter and :separator). Added deprecation notices for old API. Added tests for new options [#716 state:resolved] Signed-off-by: Joshua Peek --- .../test/template/number_helper_i18n_test.rb | 46 ++++++++++++++++++--- actionpack/test/template/number_helper_test.rb | 48 ++++++++++++---------- 2 files changed, 67 insertions(+), 27 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 50c20c3627..ce0da398cc 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -2,17 +2,53 @@ require 'abstract_unit' class NumberHelperI18nTests < Test::Unit::TestCase include ActionView::Helpers::NumberHelper - + attr_reader :request + uses_mocha 'number_helper_i18n_tests' do def setup - @defaults = {:separator => ".", :unit => "$", :format => "%u%n", :delimiter => ",", :precision => 2} - I18n.backend.store_translations 'en-US', :currency => {:format => @defaults} + @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' } + @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 } + @human_defaults = { :precision => 1 } + @percentage_defaults = { :delimiter => '' } + @precision_defaults = { :delimiter => '' } + + I18n.backend.store_translations 'en-US', :number => { :format => @number_defaults, + :currency => { :format => @currency_defaults }, :human => @human_defaults } end def test_number_to_currency_translates_currency_formats - I18n.expects(:translate).with(:'currency.format', :locale => 'en-US').returns @defaults + I18n.expects(:translate).with( + [:'number.format', :'number.currency.format'], :locale => 'en-US' + ).returns([@number_defaults, @currency_defaults]) number_to_currency(1, :locale => 'en-US') end + + def test_number_with_precision_translates_number_formats + I18n.expects(:translate).with( + [:'number.format', :'number.precision.format'], :locale => 'en-US' + ).returns([@number_defaults, @precision_defaults]) + number_with_precision(1, :locale => 'en-US') + end + + def test_number_with_delimiter_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en-US').returns(@number_defaults) + number_with_delimiter(1, :locale => 'en-US') + end + + def test_number_to_percentage_translates_number_formats + I18n.expects(:translate).with( + [:'number.format', :'number.percentage.format'], :locale => 'en-US' + ).returns([@number_defaults, @percentage_defaults]) + number_to_percentage(1, :locale => 'en-US') + end + + def test_number_to_human_size_translates_human_formats + I18n.expects(:translate).with( + [:'number.format', :'number.human.format'], :locale => 'en-US' + ).returns([@number_defaults, @human_defaults]) + # can't be called with 1 because this directly returns without calling I18n.translate + number_to_human_size(1025, :locale => 'en-US') + end end -end \ No newline at end of file +end diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index bff349a754..9c9f54936c 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -26,7 +26,8 @@ class NumberHelperTest < ActionView::TestCase assert_equal("£1234567890,50", number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""})) assert_equal("$1,234,567,890.50", number_to_currency("1234567890.50")) assert_equal("1,234,567,890.50 Kč", number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"})) - assert_equal("$x.", number_to_currency("x")) + #assert_equal("$x.", number_to_currency("x")) # fails due to API consolidation + assert_equal("$x", number_to_currency("x")) assert_nil number_to_currency(nil) end @@ -35,7 +36,9 @@ class NumberHelperTest < ActionView::TestCase assert_equal("100%", number_to_percentage(100, {:precision => 0})) assert_equal("302.06%", number_to_percentage(302.0574, {:precision => 2})) assert_equal("100.000%", number_to_percentage("100")) + assert_equal("1000.000%", number_to_percentage("1000")) assert_equal("x%", number_to_percentage("x")) + assert_equal("1.000,000%", number_to_percentage(1000, :delimiter => '.', :separator => ',')) assert_nil number_to_percentage(nil) end @@ -63,28 +66,22 @@ class NumberHelperTest < ActionView::TestCase def test_number_with_precision assert_equal("111.235", number_with_precision(111.2346)) - assert_equal("31.83", number_with_precision(31.825, 2)) - assert_equal("111.23", number_with_precision(111.2346, 2)) - assert_equal("111.00", number_with_precision(111, 2)) + assert_equal("31.83", number_with_precision(31.825, :precision => 2)) + assert_equal("111.23", number_with_precision(111.2346, :precision => 2)) + assert_equal("111.00", number_with_precision(111, :precision => 2)) assert_equal("111.235", number_with_precision("111.2346")) - assert_equal("31.83", number_with_precision("31.825", 2)) - assert_equal("112", number_with_precision(111.50, 0)) - assert_equal("1234567892", number_with_precision(1234567891.50, 0)) + assert_equal("31.83", number_with_precision("31.825", :precision => 2)) + assert_equal("112", number_with_precision(111.50, :precision => 0)) + assert_equal("1234567892", number_with_precision(1234567891.50, :precision => 0)) # Return non-numeric params unchanged. assert_equal("x", number_with_precision("x")) assert_nil number_with_precision(nil) end - def test_number_with_precision_with_options_hash - assert_equal '111.235', number_with_precision(111.2346) - assert_equal '31.83', number_with_precision(31.825, :precision => 2) - assert_equal '111.23', number_with_precision(111.2346, :precision => 2) - assert_equal '111.00', number_with_precision(111, :precision => 2) - assert_equal '111.235', number_with_precision("111.2346") - assert_equal '31.83', number_with_precision("31.825", :precision => 2) - assert_equal '112', number_with_precision(111.50, :precision => 0) - assert_equal '1234567892', number_with_precision(1234567891.50, :precision => 0) + def test_number_with_precision_with_custom_delimiter_and_separator + assert_equal '31,83', number_with_precision(31.825, :precision => 2, :separator => ',') + assert_equal '1.231,83', number_with_precision(1231.825, :precision => 2, :separator => ',', :delimiter => '.') end def test_number_to_human_size @@ -98,18 +95,19 @@ class NumberHelperTest < ActionView::TestCase assert_equal '1.2 MB', number_to_human_size(1234567) assert_equal '1.1 GB', number_to_human_size(1234567890) assert_equal '1.1 TB', number_to_human_size(1234567890123) + assert_equal '1025 TB', number_to_human_size(1025.terabytes) assert_equal '444 KB', number_to_human_size(444.kilobytes) assert_equal '1023 MB', number_to_human_size(1023.megabytes) assert_equal '3 TB', number_to_human_size(3.terabytes) - assert_equal '1.18 MB', number_to_human_size(1234567, 2) - assert_equal '3 Bytes', number_to_human_size(3.14159265, 4) + assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2) + assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4) assert_equal("123 Bytes", number_to_human_size("123")) - assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, 2) - assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4) - assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4) + assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2) + assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4) + assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4) assert_equal '1 Byte', number_to_human_size(1.1) assert_equal '10 Bytes', number_to_human_size(10) - assert_nil number_to_human_size('x') + #assert_nil number_to_human_size('x') # fails due to API consolidation assert_nil number_to_human_size(nil) end @@ -120,4 +118,10 @@ class NumberHelperTest < ActionView::TestCase assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4) assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4) end + + def test_number_to_human_size_with_custom_delimiter_and_separator + assert_equal '1,01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2, :separator => ',') + assert_equal '1,01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4, :separator => ',') + assert_equal '1.000,1 TB', number_to_human_size(1000.1.terabytes, :delimiter => '.', :separator => ',') + end end -- cgit v1.2.3 From eaab895f83276674891227c656df9b4cebc50200 Mon Sep 17 00:00:00 2001 From: miloops Date: Tue, 22 Jul 2008 11:13:38 -0300 Subject: Prototype helpers should generate Element.insert instead of Insertion.new, which has been deprecated in Prototype 1.6. --- actionpack/test/template/prototype_helper_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 92cc85703b..eb3517ef91 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -287,13 +287,13 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest end def test_insert_html_with_string - assert_equal 'new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");', + assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });', @generator.insert_html(:top, 'element', '

This is a test

') - assert_equal 'new Insertion.Bottom("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");', + assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', @generator.insert_html(:bottom, 'element', '

This is a test

') - assert_equal 'new Insertion.Before("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");', + assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', @generator.insert_html(:before, 'element', '

This is a test

') - assert_equal 'new Insertion.After("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");', + assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', @generator.insert_html(:after, 'element', '

This is a test

') end @@ -366,8 +366,8 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest @generator.replace_html('baz', '

This is a test

') assert_equal <<-EOS.chomp, @generator.to_s -new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); -new Insertion.Bottom("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); +Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" }); +Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" }); ["foo", "bar"].each(Element.remove); Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); EOS -- cgit v1.2.3 From f3da46effae9f23f6ea473f7296e9c0c9bb49fce Mon Sep 17 00:00:00 2001 From: miloops Date: Thu, 31 Jul 2008 16:09:18 -0300 Subject: In javascript helpers option[:type] = :synchronous should work as described in docs. Signed-off-by: Michael Koziarski --- actionpack/test/template/prototype_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index eb3517ef91..abc9f930dd 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -77,6 +77,8 @@ class PrototypeHelperTest < PrototypeHelperBaseTest link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot" }) assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :type => :synchronous) end def test_link_to_remote_html_options @@ -429,6 +431,8 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); def test_sortable assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});), @generator.sortable('blah', :url => { :action => "order" }) + assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:Sortable.serialize("blah")})}});), + @generator.sortable('blah', :url => { :action => "order" }, :type => :synchronous) end def test_draggable @@ -439,6 +443,8 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); def test_drop_receiving assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});), @generator.drop_receiving('blah', :url => { :action => "order" }) + assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});), + @generator.drop_receiving('blah', :url => { :action => "order" }, :type => :synchronous) end def test_collection_first_and_last -- cgit v1.2.3 From 656f0e7c6c9a305abaf9f9b7fb80479b6f94efce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 31 Jul 2008 16:36:23 -0500 Subject: Fix file permissions Signed-off-by: Joshua Peek --- actionpack/test/controller/cgi_test.rb | 0 actionpack/test/controller/redirect_test.rb | 0 actionpack/test/controller/session/cookie_store_test.rb | 0 actionpack/test/template/date_helper_test.rb | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 actionpack/test/controller/cgi_test.rb mode change 100755 => 100644 actionpack/test/controller/redirect_test.rb mode change 100755 => 100644 actionpack/test/controller/session/cookie_store_test.rb mode change 100755 => 100644 actionpack/test/template/date_helper_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb old mode 100755 new mode 100644 diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb old mode 100755 new mode 100644 diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb old mode 100755 new mode 100644 diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb old mode 100755 new mode 100644 -- cgit v1.2.3 From dc66469e6464bbb6d7bd6f242731395b6574aca2 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Mon, 4 Aug 2008 22:26:14 -0500 Subject: Fixed i18n bulk translate issues in NumberHelper Signed-off-by: Joshua Peek --- .../test/template/number_helper_i18n_test.rb | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index ce0da398cc..2ee7f43a65 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -18,35 +18,35 @@ class NumberHelperI18nTests < Test::Unit::TestCase end def test_number_to_currency_translates_currency_formats - I18n.expects(:translate).with( - [:'number.format', :'number.currency.format'], :locale => 'en-US' - ).returns([@number_defaults, @currency_defaults]) + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.currency.format', :locale => 'en-US', + :raise => true).returns(@currency_defaults) number_to_currency(1, :locale => 'en-US') end def test_number_with_precision_translates_number_formats - I18n.expects(:translate).with( - [:'number.format', :'number.precision.format'], :locale => 'en-US' - ).returns([@number_defaults, @precision_defaults]) + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.precision.format', :locale => 'en-US', + :raise => true).returns(@precision_defaults) number_with_precision(1, :locale => 'en-US') end def test_number_with_delimiter_translates_number_formats - I18n.expects(:translate).with(:'number.format', :locale => 'en-US').returns(@number_defaults) + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) number_with_delimiter(1, :locale => 'en-US') end def test_number_to_percentage_translates_number_formats - I18n.expects(:translate).with( - [:'number.format', :'number.percentage.format'], :locale => 'en-US' - ).returns([@number_defaults, @percentage_defaults]) + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en-US', + :raise => true).returns(@percentage_defaults) number_to_percentage(1, :locale => 'en-US') end def test_number_to_human_size_translates_human_formats - I18n.expects(:translate).with( - [:'number.format', :'number.human.format'], :locale => 'en-US' - ).returns([@number_defaults, @human_defaults]) + I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.human.format', :locale => 'en-US', + :raise => true).returns(@human_defaults) # can't be called with 1 because this directly returns without calling I18n.translate number_to_human_size(1025, :locale => 'en-US') end -- cgit v1.2.3 From b2504f8ba0f9baadb9298647fd58ef2c136f9aae Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 6 Aug 2008 20:08:27 -0500 Subject: Tidy up ActionMailer rendering logic to take advantage of view path cache instead of using file system lookups --- actionpack/test/controller/assert_select_test.rb | 33 ++++++------------------ 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb index 5af579f3e3..1531e7c21a 100644 --- a/actionpack/test/controller/assert_select_test.rb +++ b/actionpack/test/controller/assert_select_test.rb @@ -17,6 +17,8 @@ unless defined?(ActionMailer) end end +ActionMailer::Base.template_root = FIXTURE_LOAD_PATH + class AssertSelectTest < Test::Unit::TestCase class AssertSelectController < ActionController::Base def response_with=(content) @@ -69,11 +71,10 @@ class AssertSelectTest < Test::Unit::TestCase ActionMailer::Base.deliveries = [] end - def teardown ActionMailer::Base.deliveries.clear end - + def assert_failure(message, &block) e = assert_raises(AssertionFailedError, &block) assert_match(message, e.message) if Regexp === message @@ -91,7 +92,6 @@ class AssertSelectTest < Test::Unit::TestCase assert_failure(/Expected at least 1 element matching \"p\", found 0/) { assert_select "p" } end - def test_equality_true_false render_html %Q{
} assert_nothing_raised { assert_select "div" } @@ -102,7 +102,6 @@ class AssertSelectTest < Test::Unit::TestCase assert_nothing_raised { assert_select "p", false } end - def test_equality_string_and_regexp render_html %Q{
foo
foo
} assert_nothing_raised { assert_select "div", "foo" } @@ -116,7 +115,6 @@ class AssertSelectTest < Test::Unit::TestCase assert_raises(AssertionFailedError) { assert_select "p", :text=>/foobar/ } end - def test_equality_of_html render_html %Q{

\n"This is not a big problem," he said.\n

} text = "\"This is not a big problem,\" he said." @@ -135,7 +133,6 @@ class AssertSelectTest < Test::Unit::TestCase assert_raises(AssertionFailedError) { assert_select "pre", :html=>text } end - def test_counts render_html %Q{
foo
foo
} assert_nothing_raised { assert_select "div", 2 } @@ -166,7 +163,6 @@ class AssertSelectTest < Test::Unit::TestCase end end - def test_substitution_values render_html %Q{
foo
foo
} assert_select "div#?", /\d+/ do |elements| @@ -181,7 +177,6 @@ class AssertSelectTest < Test::Unit::TestCase end end - def test_nested_assert_select render_html %Q{
foo
foo
} assert_select "div" do |elements| @@ -200,7 +195,7 @@ class AssertSelectTest < Test::Unit::TestCase assert_select "#3", false end end - + assert_failure(/Expected at least 1 element matching \"#4\", found 0\./) do assert_select "div" do assert_select "#4" @@ -208,7 +203,6 @@ class AssertSelectTest < Test::Unit::TestCase end end - def test_assert_select_text_match render_html %Q{
foo
bar
} assert_select "div" do @@ -225,7 +219,6 @@ class AssertSelectTest < Test::Unit::TestCase end end - # With single result. def test_assert_select_from_rjs_with_single_result render_rjs do |page| @@ -255,19 +248,16 @@ class AssertSelectTest < Test::Unit::TestCase end end - # # Test css_select. # - def test_css_select render_html %Q{
} assert 2, css_select("div").size assert 0, css_select("p").size end - def test_nested_css_select render_html %Q{
foo
foo
} assert_select "div#?", /\d+/ do |elements| @@ -286,7 +276,6 @@ class AssertSelectTest < Test::Unit::TestCase end end - # With one result. def test_css_select_from_rjs_with_single_result render_rjs do |page| @@ -309,12 +298,10 @@ class AssertSelectTest < Test::Unit::TestCase assert_equal 1, css_select("#2").size end - # # Test assert_select_rjs. # - # Test that we can pick up all statements in the result. def test_assert_select_rjs_picks_up_all_statements render_rjs do |page| @@ -381,7 +368,6 @@ class AssertSelectTest < Test::Unit::TestCase assert_raises(AssertionFailedError) { assert_select_rjs "test4" } end - def test_assert_select_rjs_for_replace render_rjs do |page| page.replace "test1", "
foo
" @@ -479,7 +465,7 @@ class AssertSelectTest < Test::Unit::TestCase end end end - + # Simple hide def test_assert_select_rjs_for_hide render_rjs do |page| @@ -500,7 +486,7 @@ class AssertSelectTest < Test::Unit::TestCase end end end - + # Simple toggle def test_assert_select_rjs_for_toggle render_rjs do |page| @@ -521,7 +507,7 @@ class AssertSelectTest < Test::Unit::TestCase end end end - + # Non-positioned insert. def test_assert_select_rjs_for_nonpositioned_insert render_rjs do |page| @@ -568,7 +554,7 @@ class AssertSelectTest < Test::Unit::TestCase assert_select "div", 4 end end - + # Simple selection from a single result. def test_nested_assert_select_rjs_with_single_result render_rjs do |page| @@ -600,7 +586,6 @@ class AssertSelectTest < Test::Unit::TestCase end end - def test_feed_item_encoded render_xml <<-EOF @@ -654,7 +639,6 @@ EOF end end - # # Test assert_select_email # @@ -670,7 +654,6 @@ EOF end end - protected def render_html(html) @controller.response_with = html -- cgit v1.2.3 From 105093f90728f81268367bd52581fccfa165f170 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Thu, 7 Aug 2008 13:13:47 -0500 Subject: Refactor DateHelper to use DateTimeSelector presenter pattern Signed-off-by: Joshua Peek --- actionpack/test/template/date_helper_i18n_test.rb | 22 +- actionpack/test/template/date_helper_test.rb | 299 ++++++++++++++++++---- 2 files changed, 260 insertions(+), 61 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index aca3593921..2b40074498 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -3,22 +3,22 @@ require 'abstract_unit' class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase include ActionView::Helpers::DateHelper attr_reader :request - + def setup @from = Time.mktime(2004, 6, 6, 21, 45, 0) end - + uses_mocha 'date_helper_distance_of_time_in_words_i18n_test' do # distance_of_time_in_words def test_distance_of_time_in_words_calls_i18n { # with include_seconds - [2.seconds, true] => [:'less_than_x_seconds', 5], - [9.seconds, true] => [:'less_than_x_seconds', 10], - [19.seconds, true] => [:'less_than_x_seconds', 20], - [30.seconds, true] => [:'half_a_minute', nil], - [59.seconds, true] => [:'less_than_x_minutes', 1], - [60.seconds, true] => [:'x_minutes', 1], + [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], @@ -38,7 +38,7 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase def assert_distance_of_time_in_words_translates_key(passed, expected) diff, include_seconds = *passed - key, count = *expected + key, count = *expected to = @from + diff options = {:locale => 'en-US', :scope => :'datetime.distance_in_words'} @@ -49,11 +49,11 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase end end end - + class DateHelperSelectTagsI18nTests < Test::Unit::TestCase include ActionView::Helpers::DateHelper attr_reader :request - + uses_mocha 'date_helper_select_tags_i18n_tests' do def setup I18n.stubs(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index d8c07e731b..1a645bccc6 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -557,11 +557,8 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_incomplete_order - expected = %(\n" - - expected << %(\n) expected << %(\n\n\n) expected << "\n" @@ -569,6 +566,10 @@ class DateHelperTest < ActionView::TestCase expected << %(\n\n\n\n\n\n\n\n\n\n\n\n) expected << "\n" + expected << %(\n" + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :order => [:day]) end @@ -909,6 +910,10 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), { :datetime_separator => "—", :date_separator => "/", :time_separator => ":", :start_year => 2003, :end_year => 2005, :prefix => "date[first]"}, :class => 'selector') end + def test_select_datetime_should_work_with_date + assert_nothing_raised { select_datetime(Date.today) } + end + def test_select_time expected = %(\n} + expected << %{\n\n\n\n\n\n\n\n\n\n\n} + expected << "\n" + + expected << " / " + + expected << %{\n" + + expected << " / " + + expected << %{\n" + + assert_dom_equal expected, date_select("post", "written_on", { :date_separator => " / " }) + end + def test_time_select @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) @@ -1330,6 +1336,33 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_time_select_with_separator + @post = Post.new + @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) + + expected = %{\n} + expected << %{\n} + expected << %{\n} + + expected << %(\n" + + expected << " - " + + expected << %(\n" + + expected << " - " + + expected << %(\n" + + assert_dom_equal expected, time_select("post", "written_on", { :time_separator => " - ", :include_seconds => true }) + end + def test_datetime_select @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) @@ -1412,6 +1445,47 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_datetime_select_with_separators + @post = Post.new + @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) + + expected = %{\n" + + expected << " / " + + expected << %{\n" + + expected << " / " + + expected << %{\n" + + expected << " , " + + expected << %(\n" + + expected << " - " + + expected << %(\n" + + expected << " - " + + expected << %(\n" + + assert_dom_equal expected, datetime_select("post", "updated_at", { :date_separator => " / ", :datetime_separator => " , ", :time_separator => " - ", :include_seconds => true }) + end + def test_date_select_with_zero_value_and_no_start_year expected = %(