diff options
Diffstat (limited to 'activerecord')
14 files changed, 35 insertions, 23 deletions
diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec index c3cd76a714..9d4cbbc150 100644 --- a/activerecord/activerecord.gemspec +++ b/activerecord/activerecord.gemspec @@ -22,6 +22,6 @@ Gem::Specification.new do |s| s.add_dependency('activesupport', version) s.add_dependency('activemodel', version) - s.add_dependency('arel', '~> 2.0.2') + s.add_dependency('arel', '~> 2.1.0') s.add_dependency('tzinfo', '~> 0.3.23') end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 6d52cc344d..3045e30407 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -55,20 +55,27 @@ module ActiveRecord def exec_query(sql, name = 'SQL', binds = []) end - # Executes insert +sql+ statement in the context of this connection using + # Executes insert +sql+ statement in the context of this connection using # +binds+ as the bind substitutes. +name+ is the logged along with # the executed +sql+ statement. def exec_insert(sql, name, binds) exec_query(sql, name, binds) end - # Executes delete +sql+ statement in the context of this connection using + # Executes delete +sql+ statement in the context of this connection using # +binds+ as the bind substitutes. +name+ is the logged along with # the executed +sql+ statement. def exec_delete(sql, name, binds) exec_query(sql, name, binds) end + # Executes update +sql+ statement in the context of this connection using + # +binds+ as the bind substitutes. +name+ is the logged along with + # the executed +sql+ statement. + def exec_update(sql, name, binds) + exec_query(sql, name, binds) + end + # Returns the last auto-generated ID from the affected table. # # +id_value+ will be returned unless the value is nil, in @@ -84,8 +91,8 @@ module ActiveRecord end # Executes the update statement and returns the number of rows affected. - def update(sql, name = nil) - update_sql(sql, name) + def update(sql, name = nil, binds = []) + exec_update(sql, name, binds) end # Executes the delete statement and returns the number of rows affected. diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index dee5c93b24..d3a054c29b 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -299,6 +299,7 @@ module ActiveRecord execute sql.gsub('?') { quote(*binds.shift.reverse) }, name @connection.affected_rows end + alias :exec_update :exec_delete def last_inserted_id(result) @connection.last_id diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 6bc3b1548f..862ce852e6 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -456,6 +456,7 @@ module ActiveRecord end end end + alias :exec_update :exec_delete def begin_db_transaction #:nodoc: exec_without_stmt "BEGIN" diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 70d3d58c8f..37db2be7a9 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -549,6 +549,7 @@ module ActiveRecord affected end end + alias :exec_update :exec_delete def sql_for_insert(sql, pk, id_value, sequence_name, binds) unless pk diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index fe2868f367..d2785b234a 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -187,6 +187,7 @@ module ActiveRecord exec_query(sql, name, binds) @connection.changes end + alias :exec_update :exec_delete def last_inserted_id(result) @connection.last_insert_row_id diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 0939ec2626..96fea741e0 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -509,7 +509,9 @@ class Fixtures # FIXME: Apparently JK uses this. connection = block_given? ? yield : ActiveRecord::Base.connection - files_to_read = table_names.reject { |table_name| fixture_is_cached?(connection, table_name) } + files_to_read = table_names.reject { |table_name| + fixture_is_cached?(connection, table_name) + } unless files_to_read.empty? connection.disable_referential_integrity do @@ -521,7 +523,7 @@ class Fixtures fixtures_map[path] = Fixtures.new( connection, table_name, - class_names[table_name.to_sym], + class_names[table_name.to_sym] || table_name.classify, File.join(fixtures_directory, path)) end diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 7d76d7a19f..182b5c9210 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -301,8 +301,8 @@ db_namespace = namespace :db do require 'active_record/fixtures' ActiveRecord::Base.establish_connection(Rails.env) - base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures') - fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir + base_dir = File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten + fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir["#{fixtures_dir}/**/*.{yml,csv}"].map {|f| f[(fixtures_dir.size + 1)..-5] }).each do |fixture_file| Fixtures.create_fixtures(fixtures_dir, fixture_file) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 658a949331..ae9afad48a 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -220,7 +220,7 @@ module ActiveRecord stmt.take limit if limit stmt.order(*order) stmt.key = table[primary_key] - @klass.connection.update stmt.to_sql + @klass.connection.update stmt.to_sql, 'SQL', bind_values end end diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 9006914508..7518bc19f9 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -576,9 +576,9 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase end def test_polymorphic_counter_cache - tagging = taggings(:welcome_general) - post = posts(:welcome) - comment = comments(:greetings) + tagging = taggings(:welcome_general) + post = post = posts(:welcome) + comment = comments(:greetings) assert_difference 'post.reload.taggings_count', -1 do assert_difference 'comment.reload.taggings_count', +1 do diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 9bc7910fc6..3e92a77830 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -170,10 +170,10 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal [comment], category.posts[0].comments end end - + def test_associations_loaded_for_all_records post = Post.create!(:title => 'foo', :body => "I like cars!") - comment = SpecialComment.create!(:body => 'Come on!', :post => post) + SpecialComment.create!(:body => 'Come on!', :post => post) first_category = Category.create! :name => 'First!', :posts => [post] second_category = Category.create! :name => 'Second!', :posts => [post] diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 70a4e06dbe..89117593fd 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -760,7 +760,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_primary_key_option_on_source post = posts(:welcome) category = categories(:general) - categorization = Categorization.create!(:post_id => post.id, :named_category_name => category.name) + Categorization.create!(:post_id => post.id, :named_category_name => category.name) assert_equal [category], post.named_categories assert_equal [category.name], post.named_category_ids # checks when target loaded diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index fa40fad56d..3e20155210 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -45,6 +45,11 @@ class FixturesTest < ActiveRecord::TestCase end end + def test_create_fixtures + Fixtures.create_fixtures(FIXTURES_ROOT, "parrots") + assert Parrot.find_by_name('Curious George'), 'George is in the database' + end + def test_multiple_clean_fixtures fixtures_array = nil assert_nothing_raised { fixtures_array = create_fixtures(*FIXTURES) } diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb index 199e59657d..2238529f0f 100644 --- a/activerecord/test/cases/identity_map_test.rb +++ b/activerecord/test/cases/identity_map_test.rb @@ -137,8 +137,6 @@ class IdentityMapTest < ActiveRecord::TestCase assert_equal(["name"], swistak.changed) assert_equal({"name" => ["Marcin Raczkowski", "Swistak Sreberkowiec"]}, swistak.changes) - s = Subscriber.find('swistak') - assert swistak.name_changed? assert_equal("Swistak Sreberkowiec", swistak.name) end @@ -149,8 +147,6 @@ class IdentityMapTest < ActiveRecord::TestCase Subscriber.update_all({:name => "Raczkowski Marcin"}, {:name => "Marcin Raczkowski"}) - s = Subscriber.find('swistak') - assert_equal({"name"=>["Marcin Raczkowski", "Swistak Sreberkowiec"]}, swistak.changes) assert_equal("Swistak Sreberkowiec", swistak.name) end @@ -163,8 +159,6 @@ class IdentityMapTest < ActiveRecord::TestCase Subscriber.update_all({:name => "Swistak Sreberkowiec"}, {:name => "Marcin Raczkowski"}) - s = Subscriber.find('swistak') - assert_equal("Swistak Sreberkowiec", swistak.name) assert_equal({"name"=>["Marcin Raczkowski", "Swistak Sreberkowiec"]}, swistak.changes) assert swistak.name_changed? @@ -175,7 +169,7 @@ class IdentityMapTest < ActiveRecord::TestCase pirate.birds.create!(:name => 'Posideons Killer') pirate.birds.create!(:name => 'Killer bandita Dionne') - posideons, killer = pirate.birds + posideons, _ = pirate.birds pirate.reload |