diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderer/partial_renderer.rb | 18 | ||||
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 1 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/template/sprockets_helper_test.rb | 9 |
6 files changed, 38 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index fe0288521f..ec6c2c8db3 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'active_support/core_ext/big_decimal/conversions' require 'active_support/core_ext/float/rounding' require 'active_support/core_ext/object/blank' diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index 51c784493e..c0ac332c4e 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -362,14 +362,28 @@ module ActionView def partial_path(object = @object) @partial_names[object.class.name] ||= begin object = object.to_model if object.respond_to?(:to_model) - object.class.model_name.partial_path.dup.tap do |partial| path = @lookup_context.prefixes.first - partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/) + merge_path_into_partial(path, partial) end end end + def merge_path_into_partial(path, partial) + if path.include?(?/) && partial.include?(?/) + overlap = [] + path_array = File.dirname(path).split('/') + partial_array = partial.split('/')[0..-3] # skip model dir & partial + + path_array.each_with_index do |dir, index| + overlap << dir if dir == partial_array[index] + end + + partial.gsub!(/^#{overlap.join('/')}\//,'') + partial.insert(0, "#{File.dirname(path)}/") + end + end + def retrieve_variable(path) variable = @options[:as].try(:to_sym) || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym variable_counter = :"#{variable}_counter" if @collection diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index a68f0e84f8..424eeae35c 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -10,6 +10,7 @@ namespace :assets do Sprockets::Helpers::RailsHelper assets = Rails.application.config.assets.precompile + Rails.application.config.action_controller.perform_caching = true Rails.application.assets.precompile(*assets) end diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index a95e7c0649..ec3d36d5ad 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -72,6 +72,8 @@ module Sprockets def debug_assets? params[:debug_assets] == '1' || params[:debug_assets] == 'true' + rescue NoMethodError + false end # Override to specify an alternative prefix for asset path generation. diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index be59da9105..ce4b407c7d 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -14,6 +14,14 @@ module Fun end end +module Quiz + class QuestionsController < ActionController::Base + def new + render :partial => Quiz::Question.new("Namespaced Partial") + end + end +end + class TestController < ActionController::Base protect_from_forgery @@ -1251,6 +1259,12 @@ class RenderTest < ActionController::TestCase assert_template('fun/games/_form') end + def test_namespaced_object_partial + @controller = Quiz::QuestionsController.new + get :new + assert_equal "Namespaced Partial", @response.body + end + def test_partial_collection get :partial_collection assert_equal "Hello: davidHello: mary", @response.body diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index f11d1bba15..1135c55ff0 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -12,7 +12,6 @@ class SprocketsHelperTest < ActionView::TestCase super @controller = BasicController.new - @controller.stubs(:params).returns({}) @request = Class.new do def protocol() 'http://' end @@ -27,10 +26,8 @@ class SprocketsHelperTest < ActionView::TestCase @assets.paths << FIXTURES.join("sprockets/app/stylesheets") @assets.paths << FIXTURES.join("sprockets/app/images") - application = Object.new + application = Struct.new(:config, :assets).new(config, @assets) Rails.stubs(:application).returns(application) - application.stubs(:config).returns(config) - application.stubs(:assets).returns(@assets) @config = config @config.action_controller ||= ActiveSupport::InheritableOptions.new @config.perform_caching = true @@ -54,7 +51,7 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "/dir/audio", asset_path("/dir/audio") end - + test "asset_path with absolute urls" do assert_equal "http://www.example.com/video/play", asset_path("http://www.example.com/video/play") @@ -74,7 +71,7 @@ class SprocketsHelperTest < ActionView::TestCase assert_match %r{http://assets-\d.example.com/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") end - + test "With a proc asset host that returns no protocol the url should be protocol relative" do @controller.config.asset_host = Proc.new do |asset| "assets-999.example.com" |