From 337c361e26fe5647036f94556fe792535a921f93 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Tue, 18 Nov 2008 20:45:55 +0100 Subject: Register 'checked' as an HTML boolean attribute. This way, 'tag :foo, :type => "checkbox", :checked => false' would output the expected instead of the old The latter would result in a checkbox that's initially checked. Signed-off-by: Jeremy Kemper --- actionpack/test/template/form_tag_helper_test.rb | 1 + 1 file changed, 1 insertion(+) (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 f8add0bab1..0c8af60aa4 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -238,6 +238,7 @@ class FormTagHelperTest < ActionView::TestCase def test_boolean_options assert_dom_equal %(), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes") assert_dom_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) + assert_dom_equal %(), tag(:input, :type => "checkbox", :checked => false) assert_dom_equal %(), select_tag("people", "", :multiple => true) assert_dom_equal %(), select_tag("people[]", "", :multiple => true) assert_dom_equal %(), select_tag("people", "", :multiple => nil) -- cgit v1.2.3 From 60d6f255177af3ca93721abb8551c8585fc8c67d Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Tue, 18 Nov 2008 15:16:43 -0600 Subject: Fix rendering html partial via inline render when with :js format [#1399 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/render_test.rb | 14 ++++++++++++++ .../fixtures/test/_partial_with_only_html_version.html.erb | 1 + 2 files changed, 15 insertions(+) create mode 100644 actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 462fba7045..d5320596d5 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -246,6 +246,15 @@ class TestController < ActionController::Base :locals => { :local_name => name } end + def helper_method_to_render_to_string(*args) + render_to_string(*args) + end + helper_method :helper_method_to_render_to_string + + def render_html_only_partial_within_inline + render :inline => "Hello world <%= helper_method_to_render_to_string :partial => 'test/partial_with_only_html_version' %>" + end + def formatted_html_erb end @@ -932,6 +941,11 @@ class RenderTest < ActionController::TestCase assert_equal "Goodbye, Local David", @response.body end + def test_rendering_html_only_partial_within_inline_with_js + get :render_html_only_partial_within_inline, :format => :js + assert_equal "Hello world partial with only html version", @response.body + end + def test_should_render_formatted_template get :formatted_html_erb assert_equal 'formatted html erb', @response.body diff --git a/actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb b/actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb new file mode 100644 index 0000000000..00e6b6d6da --- /dev/null +++ b/actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb @@ -0,0 +1 @@ +partial with only html version \ No newline at end of file -- cgit v1.2.3 From 917428bcce7bb22241bfc07daa5d0ddf9d107775 Mon Sep 17 00:00:00 2001 From: Gabe da Silveira Date: Fri, 14 Nov 2008 01:14:02 -0800 Subject: Make optimized named routes respect all reserved options and tie it into UrlRewriter::RESERVED_OPTIONS so it's DRY Signed-off-by: Michael Koziarski --- actionpack/test/controller/routing_test.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 9699a04abb..b8a143cfd9 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -706,12 +706,13 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do port = options.delete(:port) || 80 port_string = port == 80 ? '' : ":#{port}" - host = options.delete(:host) || "named.route.test" - anchor = "##{options.delete(:anchor)}" if options.key?(:anchor) + protocol = options.delete(:protocol) || "http" + host = options.delete(:host) || "named.route.test" + anchor = "##{options.delete(:anchor)}" if options.key?(:anchor) path = routes.generate(options) - only_path ? "#{path}#{anchor}" : "http://#{host}#{port_string}#{path}#{anchor}" + only_path ? "#{path}#{anchor}" : "#{protocol}://#{host}#{port_string}#{path}#{anchor}" end def request @@ -1726,6 +1727,11 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com") end + def test_named_route_url_method_with_protocol + controller = setup_named_route_test + assert_equal "https://named.route.test/people/5", controller.send(:show_url, 5, :protocol => "https") + end + def test_named_route_url_method_with_ordered_parameters controller = setup_named_route_test assert_equal "http://named.route.test/people/go/7/hello/joe/5", -- cgit v1.2.3 From 291d199de1271c254c44b94766d13013b222a125 Mon Sep 17 00:00:00 2001 From: Hiroshi Saito Date: Sun, 16 Nov 2008 17:51:39 +0900 Subject: Let polymorphic_path treat an array contains single name as without array [#1386 state:committed] Signed-off-by: David Heinemeier Hansson --- actionpack/test/controller/polymorphic_routes_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb index efa3c44bc0..42dbea3b8f 100644 --- a/actionpack/test/controller/polymorphic_routes_test.rb +++ b/actionpack/test/controller/polymorphic_routes_test.rb @@ -179,6 +179,12 @@ uses_mocha 'polymorphic URL helpers' do polymorphic_url([nil, @article]) end + def test_with_array_containing_single_name + @article.save + expects(:articles_url) + polymorphic_url([:articles]) + end + # TODO: Needs to be updated to correctly know about whether the object is in a hash or not def xtest_with_hash expects(:article_url).with(@article) -- cgit v1.2.3 From 27c03e69e94655482b0d77d3ae0ca902ce537f8c Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 19 Nov 2008 17:41:55 +0530 Subject: Remove deprecated render_component. Please use the plugin from http://github.com/rails/render_component/tree/master --- actionpack/test/controller/components_test.rb | 152 -------------------------- 1 file changed, 152 deletions(-) delete mode 100644 actionpack/test/controller/components_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/components_test.rb b/actionpack/test/controller/components_test.rb deleted file mode 100644 index e7b17aa34e..0000000000 --- a/actionpack/test/controller/components_test.rb +++ /dev/null @@ -1,152 +0,0 @@ -require 'abstract_unit' - -class CallerController < ActionController::Base - def calling_from_controller - render_component(:controller => "callee", :action => "being_called") - end - - def calling_from_controller_with_params - render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" }) - end - - def calling_from_controller_with_different_status_code - render_component(:controller => "callee", :action => "blowing_up") - end - - def calling_from_template - render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>" - end - - def internal_caller - render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>" - end - - def internal_callee - render :text => "Yes, ma'am" - end - - def set_flash - render_component(:controller => "callee", :action => "set_flash") - end - - def use_flash - render_component(:controller => "callee", :action => "use_flash") - end - - def calling_redirected - render_component(:controller => "callee", :action => "redirected") - end - - def calling_redirected_as_string - render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>" - end - - def rescue_action(e) raise end -end - -class CalleeController < ActionController::Base - def being_called - render :text => "#{params[:name] || "Lady"} of the House, speaking" - end - - def blowing_up - render :text => "It's game over, man, just game over, man!", :status => 500 - end - - def set_flash - flash[:notice] = 'My stoney baby' - render :text => 'flash is set' - end - - def use_flash - render :text => flash[:notice] || 'no flash' - end - - def redirected - redirect_to :controller => "callee", :action => "being_called" - end - - def rescue_action(e) raise end -end - -class ComponentsTest < ActionController::TestCase - tests CallerController - - def test_calling_from_controller - assert_deprecated do - get :calling_from_controller - assert_equal "Lady of the House, speaking", @response.body - end - end - - def test_calling_from_controller_with_params - assert_deprecated do - get :calling_from_controller_with_params - assert_equal "David of the House, speaking", @response.body - end - end - - def test_calling_from_controller_with_different_status_code - assert_deprecated do - get :calling_from_controller_with_different_status_code - assert_equal 500, @response.response_code - end - end - - def test_calling_from_template - assert_deprecated do - get :calling_from_template - assert_equal "Ring, ring: Lady of the House, speaking", @response.body - end - end - - def test_etag_is_set_for_parent_template_when_calling_from_template - assert_deprecated do - get :calling_from_template - expected_etag = etag_for("Ring, ring: Lady of the House, speaking") - assert_equal expected_etag, @response.headers['ETag'] - end - end - - def test_internal_calling - assert_deprecated do - get :internal_caller - assert_equal "Are you there? Yes, ma'am", @response.body - end - end - - def test_flash - assert_deprecated do - get :set_flash - assert_equal 'My stoney baby', flash[:notice] - get :use_flash - assert_equal 'My stoney baby', @response.body - get :use_flash - assert_equal 'no flash', @response.body - end - end - - def test_component_redirect_redirects - assert_deprecated do - get :calling_redirected - assert_redirected_to :controller=>"callee", :action => "being_called" - end - end - - def test_component_multiple_redirect_redirects - test_component_redirect_redirects - test_internal_calling - end - - def test_component_as_string_redirect_renders_redirected_action - assert_deprecated do - get :calling_redirected_as_string - assert_equal "Lady of the House, speaking", @response.body - end - end - - protected - def etag_for(text) - %("#{Digest::MD5.hexdigest(text)}") - end -end -- cgit v1.2.3 From 130fe74d17404e5c06353526c7b20beb4019cb69 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Nov 2008 14:00:16 +0100 Subject: Changed the default of ActionView#render to assume partials instead of files when not given an options hash [DHH] --- actionpack/test/fixtures/test/hello.builder | 2 +- .../test/template/compiled_templates_test.rb | 14 +++++++------- actionpack/test/template/render_test.rb | 22 +++++++++++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/test/hello.builder b/actionpack/test/fixtures/test/hello.builder index 86a8bb3d7b..a471553941 100644 --- a/actionpack/test/fixtures/test/hello.builder +++ b/actionpack/test/fixtures/test/hello.builder @@ -1,4 +1,4 @@ xml.html do xml.p "Hello #{@name}" - xml << render("test/greeting") + xml << render(:file => "test/greeting") end \ No newline at end of file diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index e005aa0f03..f7688b2072 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -12,30 +12,30 @@ uses_mocha 'TestTemplateRecompilation' do def test_template_gets_compiled assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render(:file => "test/hello_world.erb") assert_equal 1, @compiled_templates.instance_methods.size end def test_template_gets_recompiled_when_using_different_keys_in_local_assigns assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render("test/hello_world.erb") - assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"}) + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"}) assert_equal 2, @compiled_templates.instance_methods.size end def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render(:file => "test/hello_world.erb") ActionView::Template.any_instance.expects(:compile!).never - assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render(:file => "test/hello_world.erb") end 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") + assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } assert_equal 1, @compiled_templates.instance_methods.size end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 476e651757..0323c33b95 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -8,7 +8,7 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_file - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb") end def test_render_file_not_using_full_path @@ -16,11 +16,11 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_file_without_specific_extension - assert_equal "Hello world!", @view.render("test/hello_world") + assert_equal "Hello world!", @view.render(:file => "test/hello_world") end def test_render_file_at_top_level - assert_equal 'Elastica', @view.render('/shared') + assert_equal 'Elastica', @view.render(:file => '/shared') end def test_render_file_with_full_path @@ -29,20 +29,20 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_file_with_instance_variables - assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb") + assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar.erb") end def test_render_file_with_locals locals = { :secret => 'in the sauce' } - assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals) + assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals.erb", :locals => locals) end def test_render_file_not_using_full_path_with_dot_in_path - assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar") + assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar") end def test_render_has_access_current_template - assert_equal "test/template.erb", @view.render("test/template.erb") + assert_equal "test/template.erb", @view.render(:file => "test/template.erb") end def test_render_update @@ -51,6 +51,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal 'alert("Hello, World!");', @view.render(:update) { |page| page.alert('Hello, World!') } end + def test_render_partial_from_default + assert_equal "only partial", @view.render("test/partial_only") + end + def test_render_partial assert_equal "only partial", @view.render(:partial => "test/partial_only") end @@ -73,6 +77,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 }) end + def test_render_partial_with_locals_from_default + assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5) + end + def test_render_partial_with_errors @view.render(:partial => "test/raise") flunk "Render did not raise TemplateError" -- cgit v1.2.3 From e54c33bfc8eab7ac482d571ab6bb0285b40fa56b Mon Sep 17 00:00:00 2001 From: Aaron Batalion Date: Wed, 19 Nov 2008 18:10:02 -0500 Subject: need to make sure the asset type is cached with it in Cache.. name is sufficient, not self Signed-off-by: Jeremy Kemper --- actionpack/test/template/asset_tag_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (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 1a3a6e86fa..2c0caef583 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -648,4 +648,10 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase ensure ActionController::Base.asset_host = nil end + + def test_assert_css_and_js_of_the_same_name_return_correct_extension + assert_dom_equal(%(/collaboration/hieraki/javascripts/foo.js), javascript_path("foo")) + assert_dom_equal(%(/collaboration/hieraki/stylesheets/foo.css), stylesheet_path("foo")) + + end end -- cgit v1.2.3 From 20a346170cf3922d16e265487cfb1abcc85383c1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 19 Nov 2008 19:14:52 -0800 Subject: Mocha >= 0.9.0 must be available for Action Pack tests --- actionpack/test/abstract_unit.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 673efa6af0..9623afa89d 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -2,20 +2,26 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') +require 'rubygems' require 'yaml' require 'stringio' require 'test/unit' -require 'action_controller' -require 'action_controller/cgi_ext' -require 'action_controller/test_process' -require 'action_view/test_case' + +gem 'mocha', '>= 0.9.0' +require 'mocha' begin require 'ruby-debug' + Debugger.start rescue LoadError # Debugging disabled. `gem install ruby-debug` to enable. end +require 'action_controller' +require 'action_controller/cgi_ext' +require 'action_controller/test_process' +require 'action_view/test_case' + # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true @@ -26,14 +32,6 @@ 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. def uses_mocha(test_name) - unless Object.const_defined?(:Mocha) - require 'mocha' - require 'stubba' - end yield -rescue LoadError => load_error - raise unless load_error.message =~ /mocha/i - $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." end -- cgit v1.2.3