From 3b6bdfc1050a83c6339421257d60a6163bf3c687 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 8 Oct 2009 14:13:36 -0500 Subject: API change: content_tag_for outputs prefixed class name --- actionpack/lib/action_view/helpers/record_tag_helper.rb | 6 +++--- actionpack/test/template/record_tag_helper_test.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index 0cdb70e217..31411dc08a 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -15,7 +15,7 @@ module ActionView def div_for(record, *args, &block) content_tag_for(:div, record, *args, &block) end - + # content_tag_for creates an HTML element with id and class parameters # that relate to the specified Active Record object. For example: # @@ -34,7 +34,7 @@ module ActionView # <% content_tag_for(:tr, @person, :foo) do %> ... # # produces: - # + # # ... # # content_tag_for also accepts a hash of options, which will be converted to @@ -50,7 +50,7 @@ module ActionView def content_tag_for(tag_name, record, *args, &block) prefix = args.first.is_a?(Hash) ? nil : args.shift options = args.extract_options! - options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) }) + options.merge!({ :class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix) }) content_tag(tag_name, options, &block) end end diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index 77d1374020..1cd18c0692 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -27,7 +27,7 @@ class RecordTagHelperTest < ActionView::TestCase end def test_content_tag_for_prefix - expected = %() + expected = %() actual = content_tag_for(:ul, @post, :archived) { } assert_dom_equal expected, actual end -- cgit v1.2.3 From 992c2db76cd6cd6aa9a6ba3711a6ea1ad8910062 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 8 Oct 2009 18:12:28 -0700 Subject: Finish porting over the initializers to the app object and fix all the tests --- actionpack/lib/action_controller/metal/session_management.rb | 2 +- actionpack/lib/action_view/paths.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/session_management.rb b/actionpack/lib/action_controller/metal/session_management.rb index ffce8e1bd1..654aa08cd3 100644 --- a/actionpack/lib/action_controller/metal/session_management.rb +++ b/actionpack/lib/action_controller/metal/session_management.rb @@ -16,7 +16,7 @@ module ActionController #:nodoc: self.session_store = ActiveRecord::SessionStore else @@session_store = store.is_a?(Symbol) ? - Session.const_get(store.to_s.camelize) : + ActionDispatch::Session.const_get(store.to_s.camelize) : store end end diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index 5524a3219a..23bde61f9c 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -1,8 +1,11 @@ module ActionView #:nodoc: class PathSet < Array #:nodoc: - def self.type_cast(obj) + def self.type_cast(obj, cache = nil) + # TODO: Clean this up if obj.is_a?(String) - cache = !defined?(Rails) || !Rails.respond_to?(:configuration) || Rails.configuration.cache_classes + if cache.nil? + cache = !defined?(Rails) || Rails.application.config.cache_classes + end FileSystemResolverWithFallback.new(obj, :cache => cache) else obj -- cgit v1.2.3 From ee37ff46e9ad381a8331a6a3deed001b001f75ee Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 9 Oct 2009 00:53:48 -1000 Subject: Get rid of constant name usage for stack trace help in favor of overriding #inspect and .name. --- actionpack/lib/action_view/base.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 82b419d846..31e9c5ef9d 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -236,15 +236,15 @@ module ActionView #:nodoc: # they are in AC. if controller.class.respond_to?(:_helper_serial) klass = @views[controller.class._helper_serial] ||= Class.new(self) do - name = controller.class.name.gsub(/::/, '__') - - Subclasses.class_eval do - if method(:const_defined?).arity == 1 - remove_const(name) if const_defined?(name) # Ruby 1.8.x - else - remove_const(name) if const_defined?(name, false) # Ruby 1.9.x - end - const_set(name, self) + const_set(:CONTROLLER_CLASS, controller.class) + + # Try to make stack traces clearer + def self.name + "ActionView for #{CONTROLLER_CLASS}" + end + + def inspect + "#<#{self.class.name}>" end if controller.respond_to?(:_helpers) -- cgit v1.2.3 From 2954cf13697cac564ec8a5f30638aa699b1874c1 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 9 Oct 2009 00:54:12 -1000 Subject: Avoid super in define_method for Rubinius --- actionpack/lib/action_dispatch/http/mime_type.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index cc989d6625..e85823d8db 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -10,7 +10,12 @@ module Mime %w(<< concat shift unshift push pop []= clear compact! collect! delete delete_at delete_if flatten! map! insert reject! reverse! replace slice! sort! uniq!).each do |method| - define_method(method) {|*args| @symbols = nil; super(*args) } + module_eval <<-CODE + def #{method}(*args) + @symbols = nil + super + end + CODE end end -- cgit v1.2.3 From 16a48a95e3cb0044587df7b0e83b017a94506739 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 9 Oct 2009 00:55:00 -1000 Subject: Fix issue with standalone ActionView --- actionpack/lib/action_view/render/partials.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 4f60566a09..2eb88ae3e5 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -296,7 +296,10 @@ module ActionView end def _find_template(path) - prefix = @view.controller.controller_path unless path.include?(?/) + if controller = @view.controller + prefix = controller.controller_path unless path.include?(?/) + end + @view.find(path, {:formats => @view.formats}, prefix, true) end -- cgit v1.2.3 From b9ce8216fa849a47ad0b0f99fa510e226a23c12e Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 10 Oct 2009 00:30:25 -1000 Subject: Fix a bug where render :text could not handle yield :symbol. Fixes guides generation --- actionpack/lib/action_view/render/rendering.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 0cab035ede..b6f5b9b6d1 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -14,6 +14,7 @@ module ActionView case options when Hash layout = options[:layout] + options[:locals] ||= {} if block_given? return concat(_render_partial(options.merge(:partial => layout), &block)) @@ -25,11 +26,11 @@ module ActionView if file = options[:file] template = find(file, {:formats => formats}) - _render_template(template, layout, :locals => options[:locals] || {}) + _render_template(template, layout, :locals => options[:locals]) elsif inline = options[:inline] _render_inline(inline, layout, options) elsif text = options[:text] - _render_text(text, layout, options) + _render_text(text, layout, options[:locals]) end when :update update_page(&block) @@ -80,16 +81,19 @@ module ActionView def _render_inline(inline, layout, options) handler = Template.handler_class_for_extension(options[:type] || "erb") - template = Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {}) - locals = options[:locals] || {} + template = Template.new(options[:inline], + "inline #{options[:inline].inspect}", handler, {}) + + locals = options[:locals] content = template.render(self, locals) - content = layout.render(self, locals) {|*name| _layout_for(*name) { content } } if layout - content + _render_text(content, layout, locals) end - def _render_text(text, layout, options) - text = layout.render(self, options[:locals]) { text } if layout - text + def _render_text(content, layout, locals) + content = layout.render(self, locals) do |*name| + _layout_for(*name) { content } + end if layout + content end # This is the API to render a ViewContext's template from a controller. -- cgit v1.2.3 From 7bc5e3bd02632bd3545b9097e14ea289e9531bb5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Oct 2009 19:53:40 -0500 Subject: Add define a "stuff" controller in fixtures to support routing tests --- actionpack/test/lib/controller/fake_controllers.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index 9ec7f330b8..54b6e3ba4c 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -7,6 +7,7 @@ module Admin class << self; alias_method :const_available?, :const_defined?; end class UserController < ActionController::Base; end class NewsFeedController < ActionController::Base; end + class StuffController < ActionController::Base; end end module Api -- cgit v1.2.3 From 5d071b4bc28596896b8e51703afe2d0ff44c4143 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Oct 2009 19:58:36 -0500 Subject: Drop implementation specific routing test assertions --- actionpack/test/controller/routing_test.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index edf243337f..32d60d8b7a 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -984,9 +984,6 @@ class RouteSetTest < ActiveSupport::TestCase end assert_equal 1, set.routes.size - route = set.routes.first - - assert route.segments.last.optional? assert_equal '/users/show/10', set.generate(:controller => 'users', :action => 'show', :id => 10) assert_equal '/users/index/10', set.generate(:controller => 'users', :id => 10) -- cgit v1.2.3 From 673f73b53822a8a94bac0b6d4ffc485f6eaeb9cd Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Oct 2009 20:04:44 -0500 Subject: Add define another "stuff" controller to support routing tests --- actionpack/test/lib/controller/fake_controllers.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index 54b6e3ba4c..c993836a61 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -27,6 +27,7 @@ class HiController < ActionController::Base; end class ImageController < ActionController::Base; end class PeopleController < ActionController::Base; end class SessionsController < ActionController::Base; end +class StuffController < ActionController::Base; end class SubpathBooksController < ActionController::Base; end class WeblogController < ActionController::Base; end -- cgit v1.2.3 From 21be1dcffa98321fc999e39d11e902d717affad1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Oct 2009 20:16:55 -0500 Subject: Relative url generations are covered more thoroughly by url rewriter tests --- actionpack/test/controller/routing_test.rb | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 32d60d8b7a..f3eef58f46 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -240,18 +240,6 @@ class LegacyRouteSetTests < Test::Unit::TestCase x.send(:home_url)) end - def test_basic_named_route_with_relative_url_root - rs.draw do |map| - map.home '', :controller => 'content', :action => 'list' - end - x = setup_for_named_route - ActionController::Base.relative_url_root = "/foo" - assert_equal("http://test.host/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 rs.draw do |map| map.page 'page/:title', :controller => 'content', :action => 'show_page' -- cgit v1.2.3 From 1610cd0827129c28518ee6586d8ecf922576bf20 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Oct 2009 20:19:47 -0500 Subject: Move safe buffer into test/template --- actionpack/test/template/safe_buffer_test.rb | 41 ++++++++++++++++++++++++++++ actionpack/test/view/safe_buffer_test.rb | 41 ---------------------------- 2 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 actionpack/test/template/safe_buffer_test.rb delete mode 100644 actionpack/test/view/safe_buffer_test.rb (limited to 'actionpack') diff --git a/actionpack/test/template/safe_buffer_test.rb b/actionpack/test/template/safe_buffer_test.rb new file mode 100644 index 0000000000..2236709627 --- /dev/null +++ b/actionpack/test/template/safe_buffer_test.rb @@ -0,0 +1,41 @@ +require 'abstract_unit' + +class SafeBufferTest < ActionView::TestCase + def setup + @buffer = ActionView::SafeBuffer.new + end + + test "Should look like a string" do + assert @buffer.is_a?(String) + assert_equal "", @buffer + end + + test "Should escape a raw string which is passed to them" do + @buffer << "