Permalink
Browse files

merges rails

  • Loading branch information...
fxn committed Mar 5, 2011
2 parents 34f5628 + 2076817 commit 9092052cb010ab9155cff196ef139cec41695324
Showing with 2,114 additions and 1,334 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 actionmailer/test/asset_host_test.rb
  3. +3 −3 actionmailer/test/base_test.rb
  4. +4 −0 actionpack/CHANGELOG
  5. +5 −3 actionpack/lib/action_controller/caching/actions.rb
  6. +1 −1 actionpack/lib/action_controller/metal.rb
  7. +46 −12 actionpack/lib/action_dispatch/middleware/stack.rb
  8. +4 −4 actionpack/lib/action_dispatch/middleware/static.rb
  9. +4 −3 actionpack/lib/action_dispatch/routing/route_set.rb
  10. +1 −1 actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
  11. +1 −1 actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
  12. +22 −2 actionpack/lib/action_view/helpers/form_helper.rb
  13. +5 −0 actionpack/test/controller/caching_test.rb
  14. +77 −0 actionpack/test/dispatch/middleware_stack/middleware_test.rb
  15. +21 −3 actionpack/test/template/asset_tag_helper_test.rb
  16. +12 −5 actionpack/test/template/date_helper_test.rb
  17. +135 −0 actionpack/test/template/form_helper_test.rb
  18. +2 −0 activemodel/CHANGELOG
  19. +19 −25 activemodel/lib/active_model/attribute_methods.rb
  20. +2 −2 activemodel/lib/active_model/errors.rb
  21. +5 −10 activemodel/lib/active_model/naming.rb
  22. +1 −1 activemodel/lib/active_model/translation.rb
  23. +7 −3 activemodel/test/cases/attribute_methods_test.rb
  24. +7 −0 activemodel/test/cases/translation_test.rb
  25. +0 −19 activemodel/test/cases/validations/i18n_validation_test.rb
  26. +3 −4 activemodel/test/models/person.rb
  27. +12 −0 activerecord/CHANGELOG
  28. +0 −1 activerecord/lib/active_record.rb
  29. +0 −433 activerecord/lib/active_record/association_preload.rb
  30. +3 −1 activerecord/lib/active_record/associations.rb
  31. +2 −2 activerecord/lib/active_record/associations/association.rb
  32. +0 −233 activerecord/lib/active_record/associations/class_methods/join_dependency.rb
  33. +0 −281 activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb
  34. +0 −26 activerecord/lib/active_record/associations/class_methods/join_dependency/join_base.rb
  35. +0 −80 activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb
  36. +231 −0 activerecord/lib/active_record/associations/join_dependency.rb
  37. +279 −0 activerecord/lib/active_record/associations/join_dependency/join_association.rb
  38. +24 −0 activerecord/lib/active_record/associations/join_dependency/join_base.rb
  39. +78 −0 activerecord/lib/active_record/associations/join_dependency/join_part.rb
  40. +177 −0 activerecord/lib/active_record/associations/preloader.rb
  41. +126 −0 activerecord/lib/active_record/associations/preloader/association.rb
  42. +17 −0 activerecord/lib/active_record/associations/preloader/belongs_to.rb
  43. +24 −0 activerecord/lib/active_record/associations/preloader/collection_association.rb
  44. +60 −0 activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb
  45. +17 −0 activerecord/lib/active_record/associations/preloader/has_many.rb
  46. +15 −0 activerecord/lib/active_record/associations/preloader/has_many_through.rb
  47. +23 −0 activerecord/lib/active_record/associations/preloader/has_one.rb
  48. +9 −0 activerecord/lib/active_record/associations/preloader/has_one_through.rb
  49. +21 −0 activerecord/lib/active_record/associations/preloader/singular_association.rb
  50. +66 −0 activerecord/lib/active_record/associations/preloader/through_association.rb
  51. +11 −0 activerecord/lib/active_record/attribute_methods.rb
  52. +1 −1 activerecord/lib/active_record/base.rb
  53. +10 −0 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  54. +6 −4 activerecord/lib/active_record/reflection.rb
  55. +4 −2 activerecord/lib/active_record/relation.rb
  56. +13 −1 activerecord/lib/active_record/relation/calculations.rb
  57. +2 −2 activerecord/lib/active_record/relation/finder_methods.rb
  58. +3 −3 activerecord/lib/active_record/relation/query_methods.rb
  59. +1 −0 activerecord/lib/active_record/test_case.rb
  60. +30 −15 activerecord/test/cases/associations/eager_test.rb
  61. +1 −1 activerecord/test/cases/associations/join_model_test.rb
  62. +1 −0 activerecord/test/cases/base_test.rb
  63. +30 −0 activerecord/test/cases/calculations_test.rb
  64. +1 −1 activerecord/test/cases/inheritance_test.rb
  65. +5 −0 activerecord/test/cases/pooled_connections_test.rb
  66. +2 −1 activerecord/test/models/category.rb
  67. +9 −0 activesupport/CHANGELOG
  68. +28 −23 activesupport/lib/active_support/cache/strategy/local_cache.rb
  69. +1 −1 activesupport/lib/active_support/configurable.rb
  70. +2 −2 activesupport/lib/active_support/core_ext/date/calculations.rb
  71. +3 −3 activesupport/lib/active_support/core_ext/date/zones.rb
  72. +4 −9 activesupport/lib/active_support/core_ext/date_time/calculations.rb
  73. +12 −7 activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
  74. +4 −0 activesupport/lib/active_support/core_ext/object/blank.rb
  75. +4 −13 activesupport/lib/active_support/core_ext/time/calculations.rb
  76. +58 −15 activesupport/lib/active_support/dependencies.rb
  77. +1 −1 activesupport/lib/active_support/ordered_options.rb
  78. +1 −1 activesupport/lib/active_support/time_with_zone.rb
  79. +108 −0 activesupport/test/class_cache_test.rb
  80. +7 −1 activesupport/test/configurable_test.rb
  81. +16 −16 activesupport/test/core_ext/date_ext_test.rb
  82. +4 −4 activesupport/test/core_ext/date_time_ext_test.rb
  83. +5 −5 activesupport/test/core_ext/duration_test.rb
  84. +5 −5 activesupport/test/core_ext/numeric_ext_test.rb
  85. +13 −3 activesupport/test/core_ext/time_ext_test.rb
  86. +8 −7 activesupport/test/core_ext/time_with_zone_test.rb
  87. +4 −4 activesupport/test/dependencies_test.rb
  88. +4 −4 activesupport/test/inflector_test.rb
  89. +4 −0 activesupport/test/test_case_test.rb
  90. +44 −4 ci/ci_build.rb
  91. +9 −1 railties/guides/source/active_support_core_extensions.textile
  92. +14 −1 railties/guides/source/contributing_to_ruby_on_rails.textile
  93. +4 −0 railties/lib/rails/commands/server.rb
  94. +4 −1 railties/lib/rails/engine.rb
  95. +4 −3 railties/lib/rails/generators/actions.rb
  96. +1 −1 railties/lib/rails/generators/base.rb
  97. +9 −7 railties/lib/rails/generators/rails/app/templates/public/index.html
  98. +25 −0 railties/test/generators/actions_test.rb
View
@@ -10,6 +10,7 @@ activerecord/doc
actionpack/doc
actionmailer/doc
activesupport/doc
+activesupport/test/tmp
activemodel/test/fixtures/fixture_database.sqlite3
actionpack/test/tmp
activesupport/test/fixtures/isolation_test
@@ -29,7 +29,7 @@ def test_asset_host_as_string
assert_equal %Q{<img alt="Somelogo" src="http://www.example.com/images/somelogo.png" />}, mail.body.to_s.strip
end
- def test_asset_host_as_one_arguement_proc
+ def test_asset_host_as_one_argument_proc
AssetHostMailer.config.asset_host = Proc.new { |source|
if source.starts_with?('/images')
"http://images.example.com"
@@ -41,7 +41,7 @@ def test_asset_host_as_one_arguement_proc
assert_equal %Q{<img alt="Somelogo" src="http://images.example.com/images/somelogo.png" />}, mail.body.to_s.strip
end
- def test_asset_host_as_two_arguement_proc
+ def test_asset_host_as_two_argument_proc
ActionController::Base.config.asset_host = Proc.new {|source,request|
if request && request.ssl?
"https://www.example.com"
@@ -32,21 +32,21 @@ def teardown
end
test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do
- @time = Time.now.beginning_of_day.to_datetime
+ time = Time.now.beginning_of_day.to_datetime
email = BaseMailer.welcome(:bcc => 'bcc@test.lindsaar.net',
:cc => 'cc@test.lindsaar.net',
:content_type => 'multipart/mixed',
:charset => 'iso-8559-1',
:mime_version => '2.0',
:reply_to => 'reply-to@test.lindsaar.net',
- :date => @time)
+ :date => time)
assert_equal(['bcc@test.lindsaar.net'], email.bcc)
assert_equal(['cc@test.lindsaar.net'], email.cc)
assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type)
assert_equal('iso-8559-1', email.charset)
assert_equal('2.0', email.mime_version)
assert_equal(['reply-to@test.lindsaar.net'], email.reply_to)
- assert_equal(@time, email.date)
+ assert_equal(time, email.date)
end
test "mail() renders the template using the method being processed" do
View
@@ -1,5 +1,9 @@
*Rails 3.1.0 (unreleased)*
+* ActionDispatch::MiddlewareStack now uses composition over inheritance. It is
+no longer an array which means there may be methods missing that were not
+tested.
+
* Add an :authenticity_token option to form_tag for custom handling or to omit the token (pass :authenticity_token => false). [Jakub Kuźma, Igor Wiedler]
* HTML5 button_tag helper. [Rizwan Reza]
@@ -103,12 +103,14 @@ def caches_action(*actions)
end
def _save_fragment(name, options)
- return unless caching_allowed?
-
content = response_body
content = content.join if content.is_a?(Array)
- write_fragment(name, content, options)
+ if caching_allowed?
+ write_fragment(name, content, options)
+ else
+ content
+ end
end
protected
@@ -36,7 +36,7 @@ def build(action, app=nil, &block)
action = action.to_s
raise "MiddlewareStack#build requires an app" unless app
- reverse.inject(app) do |a, middleware|
+ middlewares.reverse.inject(app) do |a, middleware|
middleware.valid?(action) ?
middleware.build(a) : a
end
@@ -2,17 +2,26 @@
require "active_support/dependencies"
module ActionDispatch
- class MiddlewareStack < Array
+ class MiddlewareStack
class Middleware
- attr_reader :args, :block
+ attr_reader :args, :block, :name, :classcache
def initialize(klass_or_name, *args, &block)
- @ref = ActiveSupport::Dependencies::Reference.new(klass_or_name)
+ @klass = nil
+
+ if klass_or_name.respond_to?(:name)
+ @klass = klass_or_name
+ @name = @klass.name
+ else
+ @name = klass_or_name.to_s
+ end
+
+ @classcache = ActiveSupport::Dependencies::Reference
@args, @block = args, block
end
def klass
- @ref.get
+ @klass || classcache[@name]
end
def ==(middleware)
@@ -22,7 +31,7 @@ def ==(middleware)
when Class
klass == middleware
else
- normalize(@ref.name) == normalize(middleware)
+ normalize(@name) == normalize(middleware)
end
end
@@ -41,18 +50,39 @@ def normalize(object)
end
end
- # Use this instead of super to work around a warning.
- alias :array_initialize :initialize
+ include Enumerable
+
+ attr_accessor :middlewares
def initialize(*args)
- array_initialize(*args)
+ @middlewares = []
yield(self) if block_given?
end
+ def each
+ @middlewares.each { |x| yield x }
+ end
+
+ def size
+ middlewares.size
+ end
+
+ def last
+ middlewares.last
+ end
+
+ def [](i)
+ middlewares[i]
+ end
+
+ def initialize_copy(other)
+ self.middlewares = other.middlewares.dup
+ end
+
def insert(index, *args, &block)
index = assert_index(index, :before)
middleware = self.class::Middleware.new(*args, &block)
- super(index, middleware)
+ middlewares.insert(index, middleware)
end
alias_method :insert_before, :insert
@@ -67,21 +97,25 @@ def swap(target, *args, &block)
delete(target)
end
+ def delete(target)
+ middlewares.delete target
+ end
+
def use(*args, &block)
middleware = self.class::Middleware.new(*args, &block)
- push(middleware)
+ middlewares.push(middleware)
end
def build(app = nil, &block)
app ||= block
raise "MiddlewareStack#build requires an app" unless app
- reverse.inject(app) { |a, e| e.build(a) }
+ middlewares.reverse.inject(app) { |a, e| e.build(a) }
end
protected
def assert_index(index, where)
- i = index.is_a?(Integer) ? index : self.index(index)
+ i = index.is_a?(Integer) ? index : middlewares.index(index)
raise "No such middleware to insert #{where}: #{index.inspect}" unless i
i
end
@@ -3,10 +3,10 @@
module ActionDispatch
class FileHandler
def initialize(at, root)
- @at, @root = at.chomp('/'), root.chomp('/')
- @compiled_at = (Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank?)
- @compiled_root = Regexp.compile(/^#{Regexp.escape(root)}/)
- @file_server = ::Rack::File.new(@root)
+ @at, @root = at.chomp('/'), root.chomp('/')
+ @compiled_at = @at.blank? ? nil : /^#{Regexp.escape(at)}/
+ @compiled_root = /^#{Regexp.escape(root)}/
+ @file_server = ::Rack::File.new(@root)
end
def match?(path)
@@ -50,12 +50,13 @@ def controller(params, default_controller=true)
private
def controller_reference(controller_param)
+ controller_name = "#{controller_param.camelize}Controller"
+
unless controller = @controllers[controller_param]
- controller_name = "#{controller_param.camelize}Controller"
controller = @controllers[controller_param] =
- ActiveSupport::Dependencies.ref(controller_name)
+ ActiveSupport::Dependencies.reference(controller_name)
end
- controller.get
+ controller.get(controller_name)
end
def dispatch(controller, action, env)
@@ -69,7 +69,7 @@ module ClassMethods
def register_javascript_expansion(expansions)
js_expansions = JavascriptIncludeTag.expansions
expansions.each do |key, values|
- js_expansions[key] = (js_expansions[key] || []) | Array(values) if values
+ js_expansions[key] = (js_expansions[key] || []) | Array(values)
end
end
end
@@ -46,7 +46,7 @@ module ClassMethods
def register_stylesheet_expansion(expansions)
style_expansions = StylesheetIncludeTag.expansions
expansions.each do |key, values|
- style_expansions[key] = (style_expansions[key] || []) | Array(values) if values
+ style_expansions[key] = (style_expansions[key] || []) | Array(values)
end
end
end
@@ -262,6 +262,24 @@ module FormHelper
# ...
# </form>
#
+ # === Removing hidden model id's
+ #
+ # The form_for method automatically includes the model id as a hidden field in the form.
+ # This is used to maintain the correlation between the form data and it's associated model.
+ # Some ORM systems do not use id's on nested models so in this case you want to be able
+ # to disable the hidden id.
+ #
+ # In the following example the Post model has many Comments stored within it in a NoSQL database,
+ # thus there is no primary key for comments.
+ #
+ # Example:
+ #
+ # <%= form(@post) do |f| %>
+ # <% f.fields_for(:comments, :include_id => false) do |cf| %>
+ # ...
+ # <% end %>
+ # <% end %>
+ #
# === Customized form builders
#
# You can also build forms using a customized FormBuilder class. Subclass
@@ -332,7 +350,7 @@ def form_for(record, options = {}, &proc)
options[:html][:remote] = options.delete(:remote)
options[:html][:authenticity_token] = options.delete(:authenticity_token)
-
+
builder = options[:parent_builder] = instantiate_builder(object_name, object, options, &proc)
fields_for = fields_for(object_name, object, options, &proc)
default_options = builder.multipart? ? { :multipart => true } : {}
@@ -1326,7 +1344,9 @@ def fields_for_with_nested_attributes(association_name, args, block)
def fields_for_nested_model(name, object, options, block)
object = convert_to_model(object)
- options[:hidden_field_id] = object.persisted?
+ parent_include_id = self.options.fetch(:include_id, true)
+ include_id = options.fetch(:include_id, parent_include_id)
+ options[:hidden_field_id] = object.persisted? && include_id
@template.fields_for(name, object, options, &block)
end
@@ -559,6 +559,11 @@ def test_four_oh_four_returns_404_for_multiple_requests
assert_response 404
end
+ def test_four_oh_four_renders_content
+ get :four_oh_four
+ assert_equal "404'd!", @response.body
+ end
+
def test_simple_runtime_error_returns_500_for_multiple_requests
get :simple_runtime_error
assert_response 500
@@ -0,0 +1,77 @@
+require 'abstract_unit'
+require 'action_dispatch/middleware/stack'
+
+module ActionDispatch
+ class MiddlewareStack
+ class MiddlewareTest < ActiveSupport::TestCase
+ class Omg; end
+
+ {
+ 'concrete' => Omg,
+ 'anonymous' => Class.new
+ }.each do |name, klass|
+
+ define_method("test_#{name}_klass") do
+ mw = Middleware.new klass
+ assert_equal klass, mw.klass
+ end
+
+ define_method("test_#{name}_==") do
+ mw1 = Middleware.new klass
+ mw2 = Middleware.new klass
+ assert_equal mw1, mw2
+ end
+
+ end
+
+ def test_string_class
+ mw = Middleware.new Omg.name
+ assert_equal Omg, mw.klass
+ end
+
+ def test_double_equal_works_with_classes
+ k = Class.new
+ mw = Middleware.new k
+ assert_operator mw, :==, k
+
+ result = mw != Class.new
+ assert result, 'middleware should not equal other anon class'
+ end
+
+ def test_double_equal_works_with_strings
+ mw = Middleware.new Omg
+ assert_operator mw, :==, Omg.name
+ end
+
+ def test_double_equal_normalizes_strings
+ mw = Middleware.new Omg
+ assert_operator mw, :==, "::#{Omg.name}"
+ end
+
+ def test_middleware_loads_classnames_from_cache
+ mw = Class.new(Middleware) {
+ attr_accessor :classcache
+ }.new(Omg.name)
+
+ fake_cache = { mw.name => Omg }
+ mw.classcache = fake_cache
+
+ assert_equal Omg, mw.klass
+
+ fake_cache[mw.name] = Middleware
+ assert_equal Middleware, mw.klass
+ end
+
+ def test_middleware_always_returns_class
+ mw = Class.new(Middleware) {
+ attr_accessor :classcache
+ }.new(Omg)
+
+ fake_cache = { mw.name => Middleware }
+ mw.classcache = fake_cache
+
+ assert_equal Omg, mw.klass
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 9092052

Please sign in to comment.