diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 23 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/digestor.rb | 38 | ||||
-rw-r--r-- | actionpack/test/controller/parameters/multi_parameter_attributes_test.rb | 23 | ||||
-rw-r--r-- | actionpack/test/template/digestor_test.rb | 14 |
5 files changed, 74 insertions, 26 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 4bed35aca7..48ba1518e0 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,14 +1,31 @@ ## Rails 4.0.0 (unreleased) ## -* `date_select` helper accepts :with_css_classes => true to add css classes similar with type - of generated select tags. *Pavel Nikitin* +* `date_select` helper accepts `with_css_classes: true` to add css classes similar with type + of generated select tags. + + *Pavel Nikitin* + +* Only non-js/css under app/assets path will be included in default config.assets.precompile. + + *Josh Peek* + +* Remove support for the RAILS_ASSET_ID environment configuration + (no longer needed now that we have the asset pipeline). + + *Josh Peek* + +* Remove old asset_path configuration (no longer needed now that we have the asset pipeline). + + *Josh Peek* * `assert_template` can be used to assert on the same template with different locals Fix #3675 *Yves Senn* -* Remove old asset tag concatenation (no longer needed now that we have the asset pipeline). *Josh Peek* +* Remove old asset tag concatenation (no longer needed now that we have the asset pipeline). + + *Josh Peek* * Accept :remote as symbolic option for `link_to` helper. *Riley Lynch* diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 6f46954266..e33201b273 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -203,7 +203,7 @@ module ActionController _value = self[filter] params[filter] = _value unless Hash === _value end - keys.grep(/\A#{Regexp.escape(filter)}\(\di\)\z/) { |key| params[key] = self[key] } + keys.grep(/\A#{Regexp.escape(filter)}\(\d+[if]?\)\z/) { |key| params[key] = self[key] } when Hash then self.slice(*filter.keys).each do |key, values| return unless values diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb index f5852dbe73..1c6eaf36f7 100644 --- a/actionpack/lib/action_view/digestor.rb +++ b/actionpack/lib/action_view/digestor.rb @@ -1,3 +1,5 @@ +require 'mutex_m' + module ActionView class Digestor EXPLICIT_DEPENDENCY = /# Template Dependency: ([^ ]+)/ @@ -19,16 +21,30 @@ module ActionView /x cattr_reader(:cache) - @@cache = Hash.new + @@cache = Hash.new.extend Mutex_m def self.digest(name, format, finder, options = {}) - cache["#{name}.#{format}"] ||= new(name, format, finder, options).digest + cache.synchronize do + unsafe_digest name, format, finder, options + end end - attr_reader :name, :format, :finder, :options + ### + # This method is NOT thread safe. DO NOT CALL IT DIRECTLY, instead call + # Digestor.digest + def self.unsafe_digest(name, format, finder, options = {}) # :nodoc: + key = "#{name}.#{format}" - def initialize(name, format, finder, options = {}) - @name, @format, @finder, @options = name, format, finder, options + cache.fetch(key) do + klass = options[:partial] || name.include?("/_") ? PartialDigestor : Digestor + cache[key] = klass.new(name, format, finder).digest + end + end + + attr_reader :name, :format, :finder + + def initialize(name, format, finder) + @name, @format, @finder = name, format, finder end def digest @@ -48,7 +64,7 @@ module ActionView def nested_dependencies dependencies.collect do |dependency| - dependencies = Digestor.new(dependency, format, finder, partial: true).nested_dependencies + dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies dependencies.any? ? { dependency => dependencies } : dependency end end @@ -68,7 +84,7 @@ module ActionView end def partial? - options[:partial] || name.include?("/_") + false end def source @@ -77,7 +93,7 @@ module ActionView def dependency_digest dependencies.collect do |template_name| - Digestor.digest(template_name, format, finder, partial: true) + Digestor.unsafe_digest(template_name, format, finder, partial: true) end.join("-") end @@ -101,4 +117,10 @@ module ActionView source.scan(EXPLICIT_DEPENDENCY).flatten.uniq end end + + class PartialDigestor < Digestor # :nodoc: + def partial? + true + end + end end diff --git a/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb b/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb index 2214ec769c..15338059bc 100644 --- a/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb +++ b/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb @@ -5,18 +5,20 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase test "permitted multi-parameter attribute keys" do params = ActionController::Parameters.new({ book: { - "shipped_at(1i)" => "2012", - "shipped_at(2i)" => "3", - "shipped_at(3i)" => "25", - "shipped_at(4i)" => "10", - "shipped_at(5i)" => "15", - "published_at(1i)" => "1999", - "published_at(2i)" => "2", - "published_at(3i)" => "5" + "shipped_at(1i)" => "2012", + "shipped_at(2i)" => "3", + "shipped_at(3i)" => "25", + "shipped_at(4i)" => "10", + "shipped_at(5i)" => "15", + "published_at(1i)" => "1999", + "published_at(2i)" => "2", + "published_at(3i)" => "5", + "price(1)" => "R$", + "price(2f)" => "2.02" } }) - permitted = params.permit book: [ :shipped_at ] + permitted = params.permit book: [ :shipped_at, :price ] assert permitted.permitted? @@ -26,6 +28,9 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase assert_equal "10", permitted[:book]["shipped_at(4i)"] assert_equal "15", permitted[:book]["shipped_at(5i)"] + assert_equal "R$", permitted[:book]["price(1)"] + assert_equal "2.02", permitted[:book]["price(2f)"] + assert_nil permitted[:book]["published_at(1i)"] assert_nil permitted[:book]["published_at(2i)"] assert_nil permitted[:book]["published_at(3i)"] diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 8181aa11f7..b9d26da3af 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -13,20 +13,24 @@ 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") + FixtureTemplate.new("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 + @cwd = Dir.pwd + @tmp_dir = Dir.mktmpdir + + FileUtils.cp_r FixtureFinder::FIXTURES_DIR, @tmp_dir + Dir.chdir @tmp_dir end def teardown - FileUtils.rm_r File.join(FixtureFinder::TMP_DIR, "digestor") + Dir.chdir @cwd + FileUtils.rm_r @tmp_dir ActionView::Digestor.cache.clear end @@ -159,7 +163,7 @@ class TemplateDigestorTest < ActionView::TestCase end def change_template(template_name) - File.open("#{FixtureFinder::TMP_DIR}/digestor/#{template_name}.html.erb", "w") do |f| + File.open("digestor/#{template_name}.html.erb", "w") do |f| f.write "\nTHIS WAS CHANGED!" end end |