diff options
Diffstat (limited to 'actionview/test/template/test_case_test.rb')
-rw-r--r-- | actionview/test/template/test_case_test.rb | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index d69d5819b6..40a5bfca53 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -1,20 +1,19 @@ -require 'abstract_unit' -require 'rails/engine' +require "abstract_unit" +require "rails/engine" module ActionView - module ATestHelper end module AnotherTestHelper def from_another_helper - 'Howdy!' + "Howdy!" end end module ASharedTestHelper def from_shared_helper - 'Holla!' + "Holla!" end end @@ -27,7 +26,7 @@ module ActionView test_case.class_eval do test "helpers defined on ActionView::TestCase are available" do assert test_case.ancestors.include?(ASharedTestHelper) - assert_equal 'Holla!', from_shared_helper + assert_equal "Holla!", from_shared_helper end end end @@ -55,18 +54,18 @@ module ActionView end test "works without testing a helper module" do - assert_equal 'Eloy', render('developers/developer', :developer => DeveloperStruct.new('Eloy')) + assert_equal "Eloy", render("developers/developer", developer: DeveloperStruct.new("Eloy")) end test "can render a layout with block" do assert_equal "Before (ChrisCruft)\n!\nAfter", - render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"} + render(layout: "test/layout_for_partial", locals: {name: "ChrisCruft"}) {"!"} end helper AnotherTestHelper test "additional helper classes can be specified as in a controller" do assert test_case.ancestors.include?(AnotherTestHelper) - assert_equal 'Howdy!', from_another_helper + assert_equal "Howdy!", from_another_helper end test "determine_default_helper_class returns nil if the test name constant resolves to a class" do @@ -103,38 +102,38 @@ module ActionView helper AnotherTestHelper test "additional helper classes can be specified as in a controller" do assert test_case.ancestors.include?(AnotherTestHelper) - assert_equal 'Howdy!', from_another_helper + assert_equal "Howdy!", from_another_helper test_case.helper_class.module_eval do def render_from_helper from_another_helper end end - assert_equal 'Howdy!', render(:partial => 'test/from_helper') + assert_equal "Howdy!", render(partial: "test/from_helper") end end class HelperInclusionTest < ActionView::TestCase module RenderHelper def render_from_helper - render :partial => 'customer', :collection => @customers + render partial: "customer", collection: @customers end end helper RenderHelper test "helper class that is being tested is always included in view instance" do - @controller.controller_path = 'test' + @controller.controller_path = "test" - @customers = [DeveloperStruct.new('Eloy'), DeveloperStruct.new('Manfred')] - assert_match(/Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')) + @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] + assert_match(/Hello: EloyHello: Manfred/, render(partial: "test/from_helper")) end end class ControllerHelperMethod < ActionView::TestCase module SomeHelper def some_method - render :partial => 'test/from_helper' + render partial: "test/from_helper" end end @@ -148,21 +147,21 @@ module ActionView EOF @controller.class.helper_method :render_from_helper - assert_equal 'controller_helper_method', some_method + assert_equal "controller_helper_method", some_method end end class ViewAssignsTest < ActionView::TestCase test "view_assigns returns a Hash of user defined ivars" do - @a = 'b' - @c = 'd' - assert_equal({:a => 'b', :c => 'd'}, view_assigns) + @a = "b" + @c = "d" + assert_equal({a: "b", c: "d"}, view_assigns) end test "view_assigns excludes internal ivars" do INTERNAL_IVARS.each do |ivar| assert defined?(ivar), "expected #{ivar} to be defined" - assert !view_assigns.keys.include?(ivar.to_s.tr('@', '').to_sym), "expected #{ivar} to be excluded from view_assigns" + assert !view_assigns.keys.include?(ivar.to_s.tr("@", "").to_sym), "expected #{ivar} to be excluded from view_assigns" end end end @@ -174,10 +173,10 @@ module ActionView end end) test "is able to make methods available to the view" do - assert_equal 'Word!', render(:partial => 'test/from_helper') + assert_equal "Word!", render(partial: "test/from_helper") end - def from_test_case; 'Word!'; end + def from_test_case; "Word!"; end helper_method :from_test_case end @@ -193,7 +192,6 @@ module ActionView test "protect_from_forgery? in any helpers returns false" do assert !view.help_me end - end class ATestHelperTest < ActionView::TestCase @@ -207,7 +205,7 @@ module ActionView test "a configured test controller is available" do assert_kind_of ActionController::Base, controller - assert_equal '', controller.controller_path + assert_equal "", controller.controller_path end test "no additional helpers should shared across test cases" do @@ -216,16 +214,16 @@ module ActionView end test "is able to use routes" do - controller.request.assign_parameters(@routes, 'foo', 'index', {}, '/foo', []) - assert_equal '/foo', url_for - assert_equal '/bar', url_for(:controller => 'bar') + controller.request.assign_parameters(@routes, "foo", "index", {}, "/foo", []) + assert_equal "/foo", url_for + assert_equal "/bar", url_for(controller: "bar") end test "is able to use named routes" do with_routing do |set| set.draw { resources :contents } - assert_equal 'http://test.host/contents/new', new_content_url - assert_equal 'http://test.host/contents/1', content_url(:id => 1) + assert_equal "http://test.host/contents/new", new_content_url + assert_equal "http://test.host/contents/1", content_url(id: 1) end end @@ -236,7 +234,7 @@ module ActionView @routes ||= ActionDispatch::Routing::RouteSet.new end - routes.draw { get "bar", :to => lambda {} } + routes.draw { get "bar", to: lambda {} } def self.call(*) end @@ -244,7 +242,7 @@ module ActionView set.draw { mount app => "/foo", :as => "foo_app" } - assert_equal '/foo/bar', foo_app.bar_path + assert_equal "/foo/bar", foo_app.bar_path end end @@ -257,21 +255,21 @@ module ActionView end end - assert_equal 'http://test.host/contents/new', render(:partial => 'test/from_helper') + assert_equal "http://test.host/contents/new", render(partial: "test/from_helper") end end test "is able to render partials with local variables" do - assert_equal 'Eloy', render('developers/developer', :developer => DeveloperStruct.new('Eloy')) - assert_equal 'Eloy', render(:partial => 'developers/developer', - :locals => { :developer => DeveloperStruct.new('Eloy') }) + assert_equal "Eloy", render("developers/developer", developer: DeveloperStruct.new("Eloy")) + assert_equal "Eloy", render(partial: "developers/developer", + locals: { developer: DeveloperStruct.new("Eloy") }) end test "is able to render partials from templates and also use instance variables" do @controller.controller_path = "test" - @customers = [DeveloperStruct.new('Eloy'), DeveloperStruct.new('Manfred')] - assert_match(/Hello: EloyHello: Manfred/, render(:file => 'test/list')) + @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] + assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list")) end test "is able to render partials from templates and also use instance variables after view has been referenced" do @@ -279,37 +277,36 @@ module ActionView view - @customers = [DeveloperStruct.new('Eloy'), DeveloperStruct.new('Manfred')] - assert_match(/Hello: EloyHello: Manfred/, render(:file => 'test/list')) + @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] + assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list")) end - end class AssertionsTest < ActionView::TestCase def render_from_helper - form_tag('/foo') do - safe_concat render(:text => '<ul><li>foo</li></ul>') + form_tag("/foo") do + safe_concat render(text: "<ul><li>foo</li></ul>") end end helper_method :render_from_helper test "uses the output_buffer for assert_select" do - render(:partial => 'test/from_helper') + render(partial: "test/from_helper") - assert_select 'form' do - assert_select 'li', :text => 'foo' + assert_select "form" do + assert_select "li", text: "foo" end end test "do not memoize the document_root_element in view tests" do - concat form_tag('/foo') + concat form_tag("/foo") - assert_select 'form' + assert_select "form" - concat content_tag(:b, 'Strong', class: 'foo') + concat content_tag(:b, "Strong", class: "foo") - assert_select 'form' - assert_select 'b.foo' + assert_select "form" + assert_select "b.foo" end end |