aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb13
-rw-r--r--actionpack/lib/action_controller/test_case.rb7
-rw-r--r--actionpack/lib/action_dispatch/http/rack_cache.rb8
-rw-r--r--actionpack/lib/action_dispatch/testing/performance_test.rb19
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb62
-rw-r--r--actionpack/lib/sprockets/railtie.rb12
6 files changed, 54 insertions, 67 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index b18be60201..93241fc056 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -2,6 +2,7 @@ require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/module/anonymous'
require 'action_dispatch/http/mime_types'
module ActionController
@@ -140,12 +141,14 @@ module ActionController
# This method also does namespace lookup. Foo::Bar::UsersController will
# try to find Foo::Bar::User, Foo::User and finally User.
def _default_wrap_model #:nodoc:
+ return nil if self.anonymous?
+
model_name = self.name.sub(/Controller$/, '').singularize
begin
model_klass = model_name.constantize
rescue NameError, ArgumentError => e
- if e.message =~ /is not missing constant|uninitialized constant #{model_name}/
+ if e.message =~ /is not missing constant|uninitialized constant #{model_name}/
namespaces = model_name.split("::")
namespaces.delete_at(-2)
break if namespaces.last == model_name
@@ -163,12 +166,12 @@ module ActionController
unless options[:only] || options[:except]
model ||= _default_wrap_model
- if !(model.respond_to?(:abstract_class?) && model.abstract_class?) && model.respond_to?(:column_names)
- options[:only] = model.column_names
+ if model.respond_to?(:attribute_names) && model.attribute_names.present?
+ options[:only] = model.attribute_names
end
end
- unless options[:name]
+ unless options[:name] || self.anonymous?
model ||= _default_wrap_model
options[:name] = model ? model.to_s.demodulize.underscore :
controller_name.singularize
@@ -226,7 +229,7 @@ module ActionController
# Checks if we should perform parameters wrapping.
def _wrapper_enabled?
ref = request.content_mime_type.try(:ref)
- _wrapper_formats.include?(ref) && !request.request_parameters[_wrapper_key]
+ _wrapper_formats.include?(ref) && _wrapper_key && !request.request_parameters[_wrapper_key]
end
end
end
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 0085f542aa..89ff5ba174 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -2,6 +2,7 @@ require 'rack/session/abstract/id'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/module/anonymous'
module ActionController
module TemplateAssertions
@@ -413,7 +414,11 @@ module ActionController
@request.env['REQUEST_METHOD'] = http_method
parameters ||= {}
- @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
+ controller_class_name = @controller.class.anonymous? ?
+ "anonymous_controller" :
+ @controller.class.name.underscore.sub(/_controller$/, '')
+
+ @request.assign_parameters(@routes, controller_class_name, action.to_s, parameters)
@request.session = ActionController::TestSession.new(session) if session
@request.session["flash"] = @request.flash.update(flash || {})
diff --git a/actionpack/lib/action_dispatch/http/rack_cache.rb b/actionpack/lib/action_dispatch/http/rack_cache.rb
index b5c1435903..cc8edee300 100644
--- a/actionpack/lib/action_dispatch/http/rack_cache.rb
+++ b/actionpack/lib/action_dispatch/http/rack_cache.rb
@@ -14,11 +14,15 @@ module ActionDispatch
end
def read(key)
- @store.read(key) || []
+ if data = @store.read(key)
+ Marshal.load(data)
+ else
+ []
+ end
end
def write(key, value)
- @store.write(key, value)
+ @store.write(key, Marshal.dump(value))
end
::Rack::Cache::MetaStore::RAILS = self
diff --git a/actionpack/lib/action_dispatch/testing/performance_test.rb b/actionpack/lib/action_dispatch/testing/performance_test.rb
index e7aeb45fb3..13fe693c32 100644
--- a/actionpack/lib/action_dispatch/testing/performance_test.rb
+++ b/actionpack/lib/action_dispatch/testing/performance_test.rb
@@ -1,17 +1,10 @@
require 'active_support/testing/performance'
-begin
- module ActionDispatch
- # An integration test that runs a code profiler on your test methods.
- # Profiling output for combinations of each test method, measurement, and
- # output format are written to your tmp/performance directory.
- #
- # By default, process_time is measured and both flat and graph_html output
- # formats are written, so you'll have two output files per test method.
- class PerformanceTest < ActionDispatch::IntegrationTest
- include ActiveSupport::Testing::Performance
- end
+module ActionDispatch
+ # An integration test that runs a code profiler on your test methods.
+ # Profiling output for combinations of each test method, measurement, and
+ # output format are written to your tmp/performance directory.
+ class PerformanceTest < ActionDispatch::IntegrationTest
+ include ActiveSupport::Testing::Performance
end
-rescue NameError
- $stderr.puts "Specify ruby-prof as application's dependency in Gemfile to run benchmarks."
end
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index b6bb90a3ce..07e2c8d341 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -243,7 +243,7 @@ module ActionView
#
# === Setting the method
#
- # You can force the form to use the full array of HTTP verbs by setting
+ # You can force the form to use the full array of HTTP verbs by setting
#
# :method => (:get|:post|:put|:delete)
#
@@ -584,8 +584,8 @@ module ActionView
# <% end %>
# ...
# <% end %>
- def fields_for(record, record_object = nil, options = {}, &block)
- builder = instantiate_builder(record, record_object, options, &block)
+ def fields_for(record_name, record_object = nil, options = {}, &block)
+ builder = instantiate_builder(record_name, record_object, options, &block)
output = capture(builder, &block)
output.concat builder.hidden_field(:id) if output && options[:hidden_field_id] && !builder.emitted_hidden_id?
output
@@ -898,16 +898,13 @@ module ActionView
private
- def instantiate_builder(record, *args, &block)
- options = args.extract_options!
- record_object = args.shift
-
- case record
+ def instantiate_builder(record_name, record_object, options, &block)
+ case record_name
when String, Symbol
object = record_object
- object_name = record
+ object_name = record_name
else
- object = record
+ object = record_name
object_name = ActiveModel::Naming.param_key(object)
end
@@ -1219,35 +1216,30 @@ module ActionView
RUBY_EVAL
end
- def fields_for(record_or_name_or_array, *args, &block)
- if options.has_key?(:index)
- index = "[#{options[:index]}]"
- elsif defined?(@auto_index)
- self.object_name = @object_name.to_s.sub(/\[\]$/,"")
- index = "[#{@auto_index}]"
- else
- index = ""
- end
-
- args << {} unless args.last.is_a?(Hash)
- args.last[:builder] ||= options[:builder]
- args.last[:parent_builder] = self
+ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
+ fields_options, record_object = record_object, nil if record_object.is_a?(Hash)
+ fields_options[:builder] ||= options[:builder]
+ fields_options[:parent_builder] = self
- case record_or_name_or_array
+ case record_name
when String, Symbol
- if nested_attributes_association?(record_or_name_or_array)
- return fields_for_with_nested_attributes(record_or_name_or_array, args, block)
- else
- name = record_or_name_or_array
+ if nested_attributes_association?(record_name)
+ return fields_for_with_nested_attributes(record_name, record_object, fields_options, block)
end
else
- object = record_or_name_or_array.is_a?(Array) ? record_or_name_or_array.last : record_or_name_or_array
- name = ActiveModel::Naming.param_key(object)
- args.unshift(object)
+ record_object = record_name.is_a?(Array) ? record_name.last : record_name
+ record_name = ActiveModel::Naming.param_key(record_object)
+ end
+
+ index = if options.has_key?(:index)
+ "[#{options[:index]}]"
+ elsif defined?(@auto_index)
+ self.object_name = @object_name.to_s.sub(/\[\]$/,"")
+ "[#{@auto_index}]"
end
- name = "#{object_name}#{index}[#{name}]"
+ record_name = "#{object_name}#{index}[#{record_name}]"
- @template.fields_for(name, *args, &block)
+ @template.fields_for(record_name, record_object, fields_options, &block)
end
def label(method, text = nil, options = {}, &block)
@@ -1336,10 +1328,8 @@ module ActionView
@object.respond_to?("#{association_name}_attributes=")
end
- def fields_for_with_nested_attributes(association_name, args, block)
+ def fields_for_with_nested_attributes(association_name, association, options, block)
name = "#{object_name}[#{association_name}_attributes]"
- options = args.extract_options!
- association = args.shift
association = convert_to_model(association)
if association.respond_to?(:persisted?)
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index c75b7d4de0..8cee3babe2 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -34,15 +34,7 @@ module Sprockets
app.assets = asset_environment(app)
ActiveSupport.on_load(:action_view) do
- if app.assets.respond_to?(:context_class)
- context = app.assets.context_class
-
- # TODO: Remove this condition when Sprockets 2.0.beta.3 is released
- else
- context = app.assets.context
- end
-
- context.instance_eval do
+ app.assets.context_class.instance_eval do
include ::ActionView::Helpers::SprocketsHelper
end
end
@@ -99,7 +91,7 @@ module Sprockets
compressor
when :yui
require 'yui/compressor'
- YUI::JavaScriptCompressor.new(:munge => true)
+ YUI::CssCompressor.new
else
sym
end