diff options
Diffstat (limited to 'activerecord')
6 files changed, 25 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 3c6f52e0fa..724b2e6d9c 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -102,6 +102,10 @@ module ActiveRecord # Clears the prepared statements cache. def clear_cache! + @statements.values.map { |hash| hash[:stmt] }.each { |stmt| + stmt.close unless stmt.closed? + } + @statements.clear end diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index f9f7448008..ed8e5ae140 100644 --- a/activerecord/lib/active_record/migration/command_recorder.rb +++ b/activerecord/lib/active_record/migration/command_recorder.rb @@ -79,8 +79,10 @@ module ActiveRecord end def invert_add_index(args) - table, columns, _ = *args - [:remove_index, [table, {:column => columns}]] + table, columns, options = *args + index_name = options.try(:[], :name) + options_hash = index_name ? {:name => index_name} : {:column => columns} + [:remove_index, [table, options_hash]] end def invert_remove_timestamps(args) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index d88e2693b6..e852f50d86 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -12,7 +12,7 @@ module ActiveRecord # These are explicitly delegated to improve performance (avoids method_missing) delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to => :to_a - delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key, :to => :klass + delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key, :connection, :column_hash,:to => :klass attr_reader :table, :klass, :loaded attr_accessor :extensions, :default_scoped diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index be92b30131..325fc58958 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -385,13 +385,10 @@ class EagerAssociationTest < ActiveRecord::TestCase c.id = "PL" end - b = Book.create! do |t| - t.id = "UE" - end + b = Book.create! - Subscription.create!(:subscriber_id => "PL", :book_id => "UE") + Subscription.create!(:subscriber_id => "PL", :book_id => b.id) s.reload - s.books s.book_ids = s.book_ids end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index fbb4ee6f7b..9644ac1b02 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -26,8 +26,8 @@ ActiveSupport::Deprecation.debug = true # Quote "type" if it's a reserved word for the current connection. QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') -# Enable Identity Map for testing -ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "false" ? false : true) +# Enable Identity Map only when ENV['IM'] is set to "true" +ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "true") def current_adapter?(*types) types.any? do |type| diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb index ae531ebb4c..0f79c99e1a 100644 --- a/activerecord/test/cases/migration/command_recorder_test.rb +++ b/activerecord/test/cases/migration/command_recorder_test.rb @@ -86,6 +86,18 @@ module ActiveRecord assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove end + def test_invert_add_index_with_name + @recorder.record :add_index, [:table, [:one, :two], {:name => "new_index"}] + remove = @recorder.inverse.first + assert_equal [:remove_index, [:table, {:name => "new_index"}]], remove + end + + def test_invert_add_index_with_no_options + @recorder.record :add_index, [:table, [:one, :two]] + remove = @recorder.inverse.first + assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove + end + def test_invert_rename_index @recorder.record :rename_index, [:old, :new] rename = @recorder.inverse.first |