Permalink
Browse files

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
2 parents 5bc98c9 + 31293ba commit 8b293e99ff2da0b5a60ff7bc5cde7bda9a2f715e @fxn fxn committed Jan 12, 2011
Showing with 522 additions and 303 deletions.
  1. +1 −1 actionpack/lib/action_controller/caching/fragments.rb
  2. +2 −2 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
  3. +1 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  4. +1 −3 actionpack/lib/action_view/test_case.rb
  5. +21 −0 actionpack/test/template/test_case_test.rb
  6. +1 −1 activerecord/Rakefile
  7. +30 −17 activerecord/lib/active_record/association_preload.rb
  8. +60 −81 activerecord/lib/active_record/associations.rb
  9. +5 −1 activerecord/lib/active_record/associations/association_collection.rb
  10. +14 −18 activerecord/lib/active_record/associations/association_proxy.rb
  11. +2 −1 activerecord/lib/active_record/associations/class_methods/join_dependency.rb
  12. +31 −18 activerecord/lib/active_record/associations/has_one_association.rb
  13. +2 −7 activerecord/lib/active_record/associations/has_one_through_association.rb
  14. +11 −10 activerecord/lib/active_record/base.rb
  15. +2 −2 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  16. +16 −0 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  17. +25 −0 activerecord/lib/active_record/reflection.rb
  18. +5 −9 activerecord/lib/active_record/relation/calculations.rb
  19. +1 −1 activerecord/lib/active_record/schema_dumper.rb
  20. +52 −0 activerecord/test/cases/associations/association_proxy_test.rb
  21. +9 −0 activerecord/test/cases/associations/belongs_to_associations_test.rb
  22. +13 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  23. +71 −23 activerecord/test/cases/associations/has_one_associations_test.rb
  24. +1 −1 activerecord/test/cases/associations/has_one_through_associations_test.rb
  25. +3 −2 activerecord/test/cases/associations/join_model_test.rb
  26. +12 −12 activerecord/test/cases/autosave_association_test.rb
  27. +5 −0 activerecord/test/cases/calculations_test.rb
  28. +15 −5 activerecord/test/cases/helper.rb
  29. +29 −25 activerecord/test/cases/locking_test.rb
  30. +1 −2 activerecord/test/cases/migration_test.rb
  31. +1 −1 activerecord/test/cases/multiple_db_test.rb
  32. +2 −2 activerecord/test/cases/nested_attributes_test.rb
  33. +1 −1 activerecord/test/cases/pooled_connections_test.rb
  34. +1 −1 activerecord/test/cases/query_cache_test.rb
  35. +1 −1 activerecord/test/cases/session_store/session_test.rb
  36. +2 −1 activerecord/test/cases/unconnected_test.rb
  37. +0 −13 activerecord/test/cases/validations/uniqueness_validation_test.rb
  38. +0 −18 activerecord/test/connections/native_sqlite3/in_memory_connection.rb
  39. +19 −0 activerecord/test/connections/native_sqlite3_mem/connection.rb
  40. +1 −0 activerecord/test/fixtures/ships.yml
  41. +4 −0 activerecord/test/models/pirate.rb
  42. +7 −0 activerecord/test/models/reply.rb
  43. +2 −0 activerecord/test/models/sponsor.rb
  44. +4 −0 activerecord/test/models/topic.rb
  45. +4 −0 activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
  46. +1 −1 activesupport/lib/active_support/core_ext/date/conversions.rb
  47. +1 −1 activesupport/lib/active_support/core_ext/date_time/conversions.rb
  48. +1 −1 activesupport/lib/active_support/core_ext/time/conversions.rb
  49. +1 −1 activesupport/lib/active_support/deprecation/proxy_wrappers.rb
  50. +10 −3 activesupport/test/core_ext/{bigdecimal.rb → bigdecimal_test.rb}
  51. +1 −0 activesupport/test/core_ext/hash_ext_test.rb
  52. +1 −0 activesupport/test/json/encoding_test.rb
  53. +9 −9 ci/ci_build.rb
  54. +1 −1 railties/Rakefile
  55. +5 −5 railties/test/railties/shared_tests.rb
@@ -59,7 +59,7 @@ def write_fragment(key, content, options = nil)
key = fragment_cache_key(key)
instrument_fragment_cache :write_fragment, key do
- content = content.html_safe.to_str if content.respond_to?(:html_safe)
+ content = content.to_str
cache_store.write(key, content, options)
end
content
@@ -50,11 +50,11 @@ def call(env)
# Only this middleware cares about RoutingError. So, let's just raise
# it here.
if headers['X-Cascade'] == 'pass'
- exception = ActionController::RoutingError.new("No route matches #{env['PATH_INFO'].inspect}")
+ raise ActionController::RoutingError, "No route matches #{env['PATH_INFO'].inspect}"
end
rescue Exception => exception
+ raise exception if env['action_dispatch.show_exceptions'] == false
end
- raise exception if env['action_dispatch.show_exceptions'] == false
exception ? render_exception(env, exception) : [status, headers, body]
end
@@ -450,7 +450,7 @@ def generate
end
def raise_routing_error
- raise ActionController::RoutingError.new("No route matches #{options.inspect}")
+ raise ActionController::RoutingError, "No route matches #{options.inspect}"
end
def different_controller?
@@ -156,10 +156,8 @@ def _render_partial(options)
# The instance of ActionView::Base that is used by +render+.
def view
@view ||= begin
- view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
+ view = @controller.view_context
view.singleton_class.send :include, _helpers
- view.singleton_class.send :include, @controller._routes.url_helpers
- view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
view.extend(Locals)
view.locals = self.locals
view.output_buffer = self.output_buffer
@@ -116,6 +116,27 @@ def render_from_helper
end
end
+ class ControllerHelperMethod < ActionView::TestCase
+ module SomeHelper
+ def some_method
+ render :partial => 'test/from_helper'
+ end
+ end
+
+ helper SomeHelper
+
+ test "can call a helper method defined on the current controller from a helper" do
+ @controller.singleton_class.class_eval <<-EOF, __FILE__, __LINE__ + 1
+ def render_from_helper
+ 'controller_helper_method'
+ end
+ EOF
+ @controller.class.helper_method :render_from_helper
+
+ assert_equal 'controller_helper_method', some_method
+ end
+ end
+
class AssignsTest < ActionView::TestCase
setup do
ActiveSupport::Deprecation.stubs(:warn)
View
@@ -41,7 +41,7 @@ namespace :test do
end
end
-%w( mysql mysql2 postgresql sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
+%w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
Rake::TestTask.new("test_#{adapter}") { |t|
connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}"
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
@@ -126,21 +126,21 @@ def add_preloaded_records_to_collection(parent_records, reflection_name, associa
parent_records.each do |parent_record|
association_proxy = parent_record.send(reflection_name)
association_proxy.loaded
- association_proxy.target.push(*Array.wrap(associated_record))
+ association_proxy.target.concat(Array.wrap(associated_record))
association_proxy.send(:set_inverse_instance, associated_record)
end
end
def add_preloaded_record_to_collection(parent_records, reflection_name, associated_record)
parent_records.each do |parent_record|
- parent_record.send("set_#{reflection_name}_target", associated_record)
+ parent_record.send(:association_proxy, reflection_name).target = associated_record
end
end
- def set_association_collection_records(id_to_record_map, reflection_name, associated_records, key)
+ def set_association_collection_records(id_to_parent_map, reflection_name, associated_records, key)
associated_records.each do |associated_record|
- mapped_records = id_to_record_map[associated_record[key].to_s]
- add_preloaded_records_to_collection(mapped_records, reflection_name, associated_record)
+ parent_records = id_to_parent_map[associated_record[key].to_s]
+ add_preloaded_records_to_collection(parent_records, reflection_name, associated_record)
end
end
@@ -158,14 +158,17 @@ def set_association_single_records(id_to_record_map, reflection_name, associated
seen_keys[seen_key] = true
mapped_records = id_to_record_map[seen_key]
mapped_records.each do |mapped_record|
- association_proxy = mapped_record.send("set_#{reflection_name}_target", associated_record)
+ association_proxy = mapped_record.send(:association_proxy, reflection_name)
+ association_proxy.target = associated_record
association_proxy.send(:set_inverse_instance, associated_record)
end
end
id_to_record_map.each do |id, records|
next if seen_keys.include?(id.to_s)
- records.each {|record| record.send("set_#{reflection_name}_target", nil) }
+ records.each do |record|
+ record.send(:association_proxy, reflection_name).target = nil
+ end
end
end
@@ -196,7 +199,6 @@ def preload_has_and_belongs_to_many_association(records, reflection, preload_opt
right = Arel::Table.new(options[:join_table]).alias('t0')
-
join_condition = left[reflection.klass.primary_key].eq(
right[reflection.association_foreign_key])
@@ -218,24 +220,35 @@ def preload_has_and_belongs_to_many_association(records, reflection, preload_opt
custom_conditions = append_conditions(reflection, preload_options)
- all_associated_records = associated_records(ids) do |some_ids|
+ klass = associated_records_proxy.klass
+
+ associated_records(ids) { |some_ids|
method = in_or_equal(some_ids)
conditions = right[reflection.foreign_key].send(*method)
conditions = custom_conditions.inject(conditions) do |ast, cond|
ast.and cond
end
- associated_records_proxy.where(conditions).to_a
- end
-
- set_association_collection_records(id_to_record_map, reflection.name, all_associated_records, 'the_parent_record_id')
+ relation = associated_records_proxy.where(conditions)
+ klass.connection.select_all(relation.arel.to_sql, 'SQL', relation.bind_values)
+ }.map! { |row|
+ parent_records = id_to_record_map[row['the_parent_record_id'].to_s]
+ associated_record = klass.instantiate row
+ add_preloaded_records_to_collection(
+ parent_records, reflection.name, associated_record)
+ associated_record
+ }
end
def preload_has_one_association(records, reflection, preload_options={})
- return if records.first.send("loaded_#{reflection.name}?")
+ return if records.first.send(:association_proxy, reflection.name).loaded?
id_to_record_map, ids = construct_id_map(records, reflection.options[:primary_key])
options = reflection.options
- records.each {|record| record.send("set_#{reflection.name}_target", nil)}
+
+ records.each do |record|
+ record.send(:association_proxy, reflection.name).target = nil
+ end
+
if options[:through]
through_records = preload_through_records(records, reflection, options[:through])
@@ -317,7 +330,7 @@ def preload_through_records(records, reflection, through_association)
end
def preload_belongs_to_association(records, reflection, preload_options={})
- return if records.first.send("loaded_#{reflection.name}?")
+ return if records.first.send(:association_proxy, reflection.name).loaded?
options = reflection.options
klasses_and_ids = {}
@@ -415,7 +428,7 @@ def associated_records(ids)
in_clause_length = connection.in_clause_length || ids.size
records = []
ids.each_slice(in_clause_length) do |some_ids|
- records += yield(some_ids)
+ records.concat yield(some_ids)
end
records
end
Oops, something went wrong.

0 comments on commit 8b293e9

Please sign in to comment.