diff options
Diffstat (limited to 'actionpack/test/template')
19 files changed, 420 insertions, 21 deletions
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 6a44197525..a04694714d 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -65,7 +65,6 @@ class AssetTagHelperTest < ActionView::TestCase %(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />), %(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />), %(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />), - %(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />), %(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />), %(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />), %(auto_discovery_link_tag(:rss, "//localhost/feed")) => %(<link href="//localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />), @@ -193,9 +192,9 @@ class AssetTagHelperTest < ActionView::TestCase ImageLinkToTag = { %(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />), %(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />), + %(image_tag("gold.png", :size => "20")) => %(<img alt="Gold" height="20" src="/images/gold.png" width="20" />), %(image_tag("gold.png", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />), %(image_tag("gold.png", "size" => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />), - %(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />), %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />), %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />), %(image_tag("google.com.png")) => %(<img alt="Google.com" src="/images/google.com.png" />), @@ -299,6 +298,16 @@ class AssetTagHelperTest < ActionView::TestCase %(audio_tag(["audio.mp3", "audio.ogg"], :autobuffer => true, :controls => true)) => %(<audio autobuffer="autobuffer" controls="controls"><source src="/audios/audio.mp3" /><source src="/audios/audio.ogg" /></audio>) } + def test_autodiscovery_link_tag_deprecated_types + result = nil + assert_deprecated do + result = auto_discovery_link_tag(:xml) + end + + expected = %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />) + assert_equal expected, result + end + def test_auto_discovery_link_tag AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index c13878af98..a4da7cd4b0 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -2658,6 +2658,30 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, datetime_select("post", "updated_at", :discard_minute => true) end + def test_datetime_select_disabled_and_discard_minute + @post = Post.new + @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) + + expected = %{<select id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]">\n} + 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) } + expected << "</select>\n" + expected << %{<select id="post_updated_at_2i" disabled="disabled" name="post[updated_at(2i)]">\n} + 1.upto(12) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 6}>#{Date::MONTHNAMES[i]}</option>\n) } + expected << "</select>\n" + expected << %{<select id="post_updated_at_3i" disabled="disabled" name="post[updated_at(3i)]">\n} + 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 15}>#{i}</option>\n) } + expected << "</select>\n" + + expected << " — " + + expected << %{<select id="post_updated_at_4i" disabled="disabled" name="post[updated_at(4i)]">\n} + 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } + expected << "</select>\n" + expected << %{<input type="hidden" id="post_updated_at_5i" disabled="disabled" name="post[updated_at(5i)]" value="16" />\n} + + assert_dom_equal expected, datetime_select("post", "updated_at", :discard_minute => true, :disabled => true) + end + def test_datetime_select_invalid_order @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb new file mode 100644 index 0000000000..01b101cb49 --- /dev/null +++ b/actionpack/test/template/digestor_test.rb @@ -0,0 +1,160 @@ +require 'abstract_unit' +require 'fileutils' + +class FixtureTemplate + attr_reader :source + + def initialize(template_path) + @source = File.read(template_path) + rescue Errno::ENOENT + raise ActionView::MissingTemplate.new([], "", [], true, []) + end +end + +class FixtureFinder + FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor" + TMP_DIR = "#{File.dirname(__FILE__)}/../tmp" + + def find(logical_name, keys, partial, options) + FixtureTemplate.new("#{TMP_DIR}/digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") + end +end + +class TemplateDigestorTest < ActionView::TestCase + def setup + FileUtils.cp_r FixtureFinder::FIXTURES_DIR, FixtureFinder::TMP_DIR + end + + def teardown + FileUtils.rm_r File.join(FixtureFinder::TMP_DIR, "digestor") + ActionView::Digestor.cache.clear + end + + def test_top_level_change_reflected + assert_digest_difference("messages/show") do + change_template("messages/show") + end + end + + def test_explicit_dependency + assert_digest_difference("messages/show") do + change_template("messages/_message") + end + end + + def test_second_level_dependency + assert_digest_difference("messages/show") do + change_template("comments/_comments") + end + end + + def test_second_level_dependency_within_same_directory + assert_digest_difference("messages/show") do + change_template("messages/_header") + end + end + + def test_third_level_dependency + assert_digest_difference("messages/show") do + change_template("comments/_comment") + end + end + + def test_logging_of_missing_template + assert_logged "Couldn't find template for digesting: messages/something_missing.html" do + digest("messages/show") + end + end + + def test_nested_template_directory + assert_digest_difference("messages/show") do + change_template("messages/actions/_move") + end + end + + def test_dont_generate_a_digest_for_missing_templates + assert_equal '', digest("nothing/there") + end + + def test_collection_dependency + assert_digest_difference("messages/index") do + change_template("messages/_message") + end + + assert_digest_difference("messages/index") do + change_template("events/_event") + end + end + + def test_collection_derived_from_record_dependency + assert_digest_difference("messages/show") do + change_template("events/_event") + end + end + + def test_extra_whitespace_in_render_partial + assert_digest_difference("messages/edit") do + change_template("messages/_form") + end + end + + def test_extra_whitespace_in_render_named_partial + assert_digest_difference("messages/edit") do + change_template("messages/_header") + end + end + + def test_extra_whitespace_in_render_record + assert_digest_difference("messages/edit") do + change_template("messages/_message") + end + end + + def test_extra_whitespace_in_render_with_parenthesis + assert_digest_difference("messages/edit") do + change_template("events/_event") + end + end + + def test_old_style_hash_in_render_invocation + assert_digest_difference("messages/edit") do + change_template("comments/_comment") + end + end + + private + def assert_logged(message) + old_logger = ActionView::Base.logger + log = StringIO.new + ActionView::Base.logger = Logger.new(log) + + begin + yield + + log.rewind + assert_match message, log.read + ensure + ActionView::Base.logger = old_logger + end + end + + def assert_digest_difference(template_name) + previous_digest = digest(template_name) + ActionView::Digestor.cache.clear + + yield + + assert previous_digest != digest(template_name), "digest didn't change" + ActionView::Digestor.cache.clear + end + + def digest(template_name) + ActionView::Digestor.digest(template_name, :html, FixtureFinder.new) + end + + def change_template(template_name) + File.open("#{FixtureFinder::TMP_DIR}/digestor/#{template_name}.html.erb", "w") do |f| + f.write "\nTHIS WAS CHANGED!" + end + end +end diff --git a/actionpack/test/template/erb/helper.rb b/actionpack/test/template/erb/helper.rb index 799f9e4036..a1973068d5 100644 --- a/actionpack/test/template/erb/helper.rb +++ b/actionpack/test/template/erb/helper.rb @@ -1,5 +1,6 @@ module ERBTest class ViewContext + include ActionView::Helpers::UrlHelper include SharedTestRoutes.url_helpers include ActionView::Helpers::TagHelper include ActionView::Helpers::JavaScriptHelper @@ -20,4 +21,4 @@ module ERBTest "<%= #{str} do %>#{rest}<% end %>" end end -end
\ No newline at end of file +end diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb index f1cb920963..3e5b029cea 100644 --- a/actionpack/test/template/erb_util_test.rb +++ b/actionpack/test/template/erb_util_test.rb @@ -45,7 +45,7 @@ class ErbUtilTest < ActiveSupport::TestCase end def test_html_escape_once - assert_equal '1 <>&"' 2 & 3', html_escape_once('1 <>&"\' 2 & 3') + assert_equal '1 <>&"' 2 & 3', html_escape_once('1 <>&"\' 2 & 3') end def test_html_escape_once_returns_unsafe_strings_when_passed_unsafe_strings diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 5c6cb45530..246c4bfada 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -81,8 +81,6 @@ class FormHelperTest < ActionView::TestCase @post.tags = [] @post.tags << Tag.new - @blog_post = Blog::Post.new("And his name will be forty and four.", 44) - @car = Car.new("#000FFF") end @@ -1168,7 +1166,9 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_model_using_relative_model_naming - form_for(@blog_post) do |f| + blog_post = Blog::Post.new("And his name will be forty and four.", 44) + + form_for(blog_post) do |f| concat f.text_field :title concat f.submit('Edit post') end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index f908de865e..54ab8b4d3a 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1124,7 +1124,7 @@ class FormOptionsHelperTest < ActionView::TestCase def test_options_for_select_with_element_attributes assert_dom_equal( - "<option value=\"<Denmark>\" class=\"bold\"><Denmark></option>\n<option value=\"USA\" onclick=\"alert('Hello World');\">USA</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Germany\">Germany</option>", + "<option value=\"<Denmark>\" class=\"bold\"><Denmark></option>\n<option value=\"USA\" onclick=\"alert('Hello World');\">USA</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Germany\">Germany</option>", options_for_select([ [ "<Denmark>", { :class => 'bold' } ], [ "USA", { :onclick => "alert('Hello World');" } ], [ "Sweden" ], "Germany" ]) ) end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 81ba92f2e6..945dff2a29 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -225,6 +225,18 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_select_tag_with_nil_option_tags_and_include_blank + actual = select_tag "places", nil, :include_blank => true + expected = %(<select id="places" name="places"><option value=""></option></select>) + assert_dom_equal expected, actual + end + + def test_select_tag_with_nil_option_tags_and_prompt + actual = select_tag "places", nil, :prompt => "string" + expected = %(<select id="places" name="places"><option value="">string</option></select>) + assert_dom_equal expected, actual + end + def test_text_area_tag_size_string actual = text_area_tag "body", "hello world", "size" => "20x40" expected = %(<textarea cols="20" id="body" name="body" rows="40">\nhello world</textarea>) @@ -379,7 +391,7 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag assert_dom_equal( - %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />), + %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />), submit_tag("Save", :onclick => "alert('hello!')", :data => { :disable_with => "Saving..." }) ) end diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 4a9a382afa..58784c26fa 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -44,14 +44,14 @@ class JavaScriptHelperTest < ActionView::TestCase def test_button_to_function assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do - assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />), + assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />), button_to_function("Greeting", "alert('Hello world!')") end end def test_button_to_function_with_onclick assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do - assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />", + assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />", button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')") end end @@ -65,21 +65,21 @@ class JavaScriptHelperTest < ActionView::TestCase def test_link_to_function assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do - assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>), + assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>), link_to_function("Greeting", "alert('Hello world!')") end end def test_link_to_function_with_existing_onclick assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do - assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>), + assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>), link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')") end end def test_function_with_href assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do - assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>), + assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>), link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') end end diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb index 1713ce935c..7f4c84929f 100644 --- a/actionpack/test/template/log_subscriber_test.rb +++ b/actionpack/test/template/log_subscriber_test.rb @@ -8,9 +8,10 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def setup super - @controller = Object.new - @controller.stubs(:_prefixes).returns(%w(test)) - @view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) + view_paths = ActionController::Base.view_paths + lookup_context = ActionView::LookupContext.new(view_paths, {}, ["test"]) + renderer = ActionView::Renderer.new(lookup_context) + @view = ActionView::Base.new(renderer, {}) Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH)) ActionView::LogSubscriber.attach_to :action_view end diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index ef9c5ce10c..073bd14783 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -11,6 +11,17 @@ class LookupContextTest < ActiveSupport::TestCase I18n.locale = :en end + test "allows to override default_formats with ActionView::Base.default_formats" do + begin + formats = ActionView::Base.default_formats + ActionView::Base.default_formats = [:foo, :bar] + + assert_equal [:foo, :bar], ActionView::LookupContext.new([]).default_formats + ensure + ActionView::Base.default_formats = formats + end + end + test "process view paths on initialization" do assert_kind_of ActionView::PathSet, @lookup_context.view_paths end diff --git a/actionpack/test/template/record_identifier_test.rb b/actionpack/test/template/record_identifier_test.rb new file mode 100644 index 0000000000..22038110a5 --- /dev/null +++ b/actionpack/test/template/record_identifier_test.rb @@ -0,0 +1,49 @@ +require 'abstract_unit' +require 'controller/fake_models' + +class RecordIdentifierTest < ActiveSupport::TestCase + include ActionView::RecordIdentifier + + def setup + @klass = Comment + @record = @klass.new + @singular = 'comment' + @plural = 'comments' + @uncountable = Sheep + end + + def test_dom_id_with_new_record + assert_equal "new_#{@singular}", dom_id(@record) + end + + def test_dom_id_with_new_record_and_prefix + assert_equal "custom_prefix_#{@singular}", dom_id(@record, :custom_prefix) + end + + def test_dom_id_with_saved_record + @record.save + assert_equal "#{@singular}_1", dom_id(@record) + end + + def test_dom_id_with_prefix + @record.save + assert_equal "edit_#{@singular}_1", dom_id(@record, :edit) + end + + def test_dom_class + assert_equal @singular, dom_class(@record) + end + + def test_dom_class_with_prefix + assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix) + end + + def test_dom_id_as_singleton_method + @record.save + assert_equal "#{@singular}_1", ActionView::RecordIdentifier.dom_id(@record) + end + + def test_dom_class_as_singleton_method + assert_equal @singular, ActionView::RecordIdentifier.dom_class(@record) + end +end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b26354e7cc..ddf5c6a1b3 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -97,6 +97,14 @@ module RenderTestCases assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(:template => "plain_text_with_characters") end + def test_render_ruby_template_with_handlers + assert_equal "Hello from Ruby code", @view.render(:template => "ruby_template") + end + + def test_render_ruby_template_inline + assert_equal '4', @view.render(:inline => "(2**2).to_s", :type => :ruby) + end + def test_render_file_with_localization_on_context_level old_locale, @view.locale = @view.locale, :da assert_equal "Hey verden", @view.render(:file => "test/hello_world") @@ -443,6 +451,15 @@ module RenderTestCases assert_equal %(<title>David</title>), @view.render(:file => "test/layout_render_object") end + + def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call + ActionView::Template.register_template_handler :foo1, :foo2, CustomHandler + assert_equal @view.render(:inline => "Hello, World!", :type => :foo1), @view.render(:inline => "Hello, World!", :type => :foo2) + end + + def test_render_throws_exception_when_no_extensions_passed_to_register_template_handler_function_call + assert_raises(ArgumentError) { ActionView::Template.register_template_handler CustomHandler } + end end class CachedViewRenderTest < ActiveSupport::TestCase diff --git a/actionpack/test/template/spec_type_test.rb b/actionpack/test/template/spec_type_test.rb new file mode 100644 index 0000000000..08a7bdf81d --- /dev/null +++ b/actionpack/test/template/spec_type_test.rb @@ -0,0 +1,39 @@ +require 'abstract_unit' + +class ActionViewSpecTypeTest < ActiveSupport::TestCase + def assert_view actual + assert_equal ActionView::TestCase, actual + end + + def refute_view actual + refute_equal ActionView::TestCase, actual + end + + def test_spec_type_resolves_for_matching_helper_strings + assert_view MiniTest::Spec.spec_type("WidgetHelper") + assert_view MiniTest::Spec.spec_type("WidgetHelperTest") + assert_view MiniTest::Spec.spec_type("Widget Helper Test") + # And is not case sensitive + assert_view MiniTest::Spec.spec_type("widgethelper") + assert_view MiniTest::Spec.spec_type("widgethelpertest") + assert_view MiniTest::Spec.spec_type("widget helper test") + end + + def test_spec_type_resolves_for_matching_view_strings + assert_view MiniTest::Spec.spec_type("WidgetView") + assert_view MiniTest::Spec.spec_type("WidgetViewTest") + assert_view MiniTest::Spec.spec_type("Widget View Test") + # And is not case sensitive + assert_view MiniTest::Spec.spec_type("widgetview") + assert_view MiniTest::Spec.spec_type("widgetviewtest") + assert_view MiniTest::Spec.spec_type("widget view test") + end + + def test_spec_type_wont_match_non_space_characters + refute_view MiniTest::Spec.spec_type("Widget Helper\tTest") + refute_view MiniTest::Spec.spec_type("Widget Helper\rTest") + refute_view MiniTest::Spec.spec_type("Widget Helper\nTest") + refute_view MiniTest::Spec.spec_type("Widget Helper\fTest") + refute_view MiniTest::Spec.spec_type("Widget HelperXTest") + end +end diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 061f5bb53f..86ba5f3b4d 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -59,6 +59,13 @@ class TestERBTemplate < ActiveSupport::TestCase @context = Context.new end + def test_mime_type_is_deprecated + template = new_template + assert_deprecated 'Template#mime_type is deprecated and will be removed' do + template.mime_type + end + end + def test_basic_template @template = new_template assert_equal "Hello", render diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 387aafebd4..5265ae6b3a 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -64,7 +64,7 @@ module ActionView assert_equal 'Howdy!', from_another_helper end - test "determine_default_helper_class returns nil if name.sub(/Test$/, '').constantize resolves to a class" do + test "determine_default_helper_class returns nil if the test name constant resolves to a class" do assert_nil self.class.determine_default_helper_class("String") end diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb index 108a674d95..e843a1deb4 100644 --- a/actionpack/test/template/test_test.rb +++ b/actionpack/test/template/test_test.rb @@ -78,3 +78,59 @@ class CrazyStringHelperTest < ActionView::TestCase assert_equal PeopleHelper, self.class.helper_class end end + +describe PeopleHelper do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe PeopleHelper, :helper_class do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe PeopleHelper do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end + +describe PeopleHelper, :helper_class do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end + +describe "PeopleHelper" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe "PeopleHelperTest" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe "PeopleHelper" do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end + +describe "PeopleHelperTest" do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index c0f694b2bf..412d13bb2b 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -149,7 +149,7 @@ class TextHelperTest < ActionView::TestCase end def test_truncate_with_block_should_escape_the_block - assert_equal "Here is a long test and ...<script>alert('foo');</script>", + assert_equal "Here is a long test and ...<script>alert('foo');</script>", truncate("Here is a long test and I need a continue to read link", :length => 27) { "<script>alert('foo');</script>" } end @@ -303,6 +303,19 @@ class TextHelperTest < ActionView::TestCase assert_equal options, passed_options end + def test_excerpt_with_separator + options = { :separator => ' ', :radius => 1 } + assert_equal('...a very beautiful...', excerpt('This is a very beautiful morning', 'very', options)) + assert_equal('This is...', excerpt('This is a very beautiful morning', 'this', options)) + assert_equal('...beautiful morning', excerpt('This is a very beautiful morning', 'morning', options)) + + options = { :separator => "\n", :radius => 0 } + assert_equal("...very long...", excerpt("my very\nvery\nvery long\nstring", 'long', options)) + + options = { :separator => "\n", :radius => 1 } + assert_equal("...very\nvery long\nstring", excerpt("my very\nvery\nvery long\nstring", 'long', options)) + end + def test_word_wrap assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15)) end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index f9f8c36fff..134177d74d 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -20,9 +20,9 @@ class UrlHelperTest < ActiveSupport::TestCase get "/article/:id" => "foo#article", :as => :article end + include ActionView::Helpers::UrlHelper include routes.url_helpers - include ActionView::Helpers::UrlHelper include ActionView::Helpers::JavaScriptHelper include ActionDispatch::Assertions::DomAssertions include ActionView::Context @@ -244,7 +244,7 @@ class UrlHelperTest < ActiveSupport::TestCase def test_link_tag_with_custom_onclick link = link_to("Hello", "http://www.example.com", :onclick => "alert('yay!')") - expected = %{<a href="http://www.example.com" onclick="alert('yay!')">Hello</a>} + expected = %{<a href="http://www.example.com" onclick="alert('yay!')">Hello</a>} assert_dom_equal expected, link end |