diff options
Diffstat (limited to 'activerecord/test')
17 files changed, 64 insertions, 23 deletions
diff --git a/activerecord/test/cases/adapters/mysql/connection_test.rb b/activerecord/test/cases/adapters/mysql/connection_test.rb index 782aad72d6..f76a23a8ad 100644 --- a/activerecord/test/cases/adapters/mysql/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql/connection_test.rb @@ -48,6 +48,7 @@ class MysqlConnectionTest < ActiveRecord::TestCase def test_multi_results rows = ActiveRecord::Base.connection.select_rows('CALL ten();') assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}" + assert @connection.active?, "Bad connection use by 'MysqlAdapter.select_rows'" end end diff --git a/activerecord/test/cases/adapters/mysql/sp_test.rb b/activerecord/test/cases/adapters/mysql/sp_test.rb new file mode 100644 index 0000000000..3ca2917ca4 --- /dev/null +++ b/activerecord/test/cases/adapters/mysql/sp_test.rb @@ -0,0 +1,15 @@ +require "cases/helper" +require 'models/topic' + +class StoredProcedureTest < ActiveRecord::TestCase + fixtures :topics + + # Test that MySQL allows multiple results for stored procedures + if Mysql.const_defined?(:CLIENT_MULTI_RESULTS) + def test_multi_results_from_find_by_sql + topics = Topic.find_by_sql 'CALL topics();' + assert_equal 1, topics.size + assert ActiveRecord::Base.connection.active?, "Bad connection use by 'MysqlAdapter.select'" + end + end +end diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb index 9e285e57dc..3e0e6dce2c 100644 --- a/activerecord/test/cases/aggregations_test.rb +++ b/activerecord/test/cases/aggregations_test.rb @@ -99,7 +99,7 @@ class AggregationsTest < ActiveRecord::TestCase customers(:zaphod).save customers(:zaphod).reload assert_kind_of Address, customers(:zaphod).address - assert customers(:zaphod).address.street.nil? + assert_nil customers(:zaphod).address.street end def test_nil_assignment_results_in_nil diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index a1ce9b1689..28234ebe49 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -22,7 +22,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase def test_belongs_to Client.find(3).firm.name assert_equal companies(:first_firm).name, Client.find(3).firm.name - assert !Client.find(3).firm.nil?, "Microsoft should have a firm" + assert_not_nil Client.find(3).firm, "Microsoft should have a firm" end def test_belongs_to_with_primary_key diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ac2021c369..7e10a8ceeb 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -633,7 +633,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase # Should not be destroyed since the association is not dependent. assert_nothing_raised do - assert Client.find(client_id).firm.nil? + assert_nil Client.find(client_id).firm end end @@ -658,7 +658,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [client_id], Client.destroyed_client_ids[firm.id] # Should be destroyed since the association is dependent. - assert Client.find_by_id(client_id).nil? + assert_nil Client.find_by_id(client_id) end def test_clearing_an_exclusively_dependent_association_collection diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 469a21b9bf..e959ed46cc 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -253,7 +253,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase def test_dependence_with_missing_association_and_nullify Account.destroy_all firm = DependentFirm.find(:first) - assert firm.account.nil? + assert_nil firm.account firm.destroy end diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index fcdb81e92e..b83966e91c 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -427,8 +427,8 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase def test_has_many_through_uses_conditions_specified_on_the_has_many_association author = Author.find(:first) - assert !author.comments.blank? - assert author.nonexistant_comments.blank? + assert_present author.comments + assert_blank author.nonexistant_comments end def test_has_many_through_uses_correct_attributes diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 5256ab8d11..312628a3e3 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -449,7 +449,7 @@ class NestedScopingTest < ActiveRecord::TestCase Comment.send(:with_scope, :create => { :body => "Hey guys, nested scopes are broken. Please fix!" }) do Comment.send(:with_exclusive_scope, :create => { :post_id => 1 }) do assert_equal({:post_id => 1}, Comment.scoped.send(:scope_for_create)) - assert Comment.new.body.blank? + assert_blank Comment.new.body comment = Comment.create :body => "Hey guys" end end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 8d35f26b30..186bb55c01 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -806,6 +806,9 @@ if ActiveRecord::Base.connection.supports_migrations? Topic.connection.change_column "topics", "written_on", :datetime, :null => false Topic.reset_column_information + + Topic.connection.change_column "topics", "written_on", :datetime, :null => true + Topic.reset_column_information end end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index c42dda2ccb..3d6975d0b5 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -480,8 +480,8 @@ class DynamicScopeTest < ActiveRecord::TestCase end def test_dynamic_scope_should_create_methods_after_hitting_method_missing - assert Developer.methods.grep(/scoped_by_created_at/).blank? + assert_blank Developer.methods.grep(/scoped_by_created_at/) Developer.scoped_by_created_at(nil) - assert Developer.methods.grep(/scoped_by_created_at/).present? + assert_present Developer.methods.grep(/scoped_by_created_at/) end end diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 5cdcb05902..63d8c7d1c1 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -11,7 +11,7 @@ class PrimaryKeysTest < ActiveRecord::TestCase def test_to_key_with_default_primary_key topic = Topic.new - assert topic.to_key.nil? + assert_nil topic.to_key topic = Topic.find(1) assert_equal [1], topic.to_key end @@ -26,7 +26,7 @@ class PrimaryKeysTest < ActiveRecord::TestCase def test_to_key_with_primary_key_after_destroy topic = Topic.find(1) topic.destroy - assert_equal nil, topic.to_key + assert_equal [1], topic.to_key end def test_integer_key diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 9494990b04..d56e5a7999 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -209,7 +209,7 @@ class NestedRelationScopingTest < ActiveRecord::TestCase def test_nested_exclusive_scope_for_create comment = Comment.create_with(:body => "Hey guys, nested scopes are broken. Please fix!").scoping do Comment.unscoped.create_with(:post_id => 1).scoping do - assert Comment.new.body.blank? + assert_blank Comment.new.body Comment.create :body => "Hey guys" end end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index bd6e216c62..aa75aa27d4 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -411,7 +411,7 @@ class RelationTest < ActiveRecord::TestCase def test_find_in_empty_array authors = Author.scoped.where(:id => []) - assert authors.all.blank? + assert_blank authors.all end def test_exists @@ -486,7 +486,7 @@ class RelationTest < ActiveRecord::TestCase def test_relation_merging_with_locks devs = Developer.lock.where("salary >= 80000").order("id DESC") & Developer.limit(2) - assert devs.locked.present? + assert_present devs.locked end def test_relation_merging_with_preload diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 597b954d84..fce27d8972 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -84,6 +84,22 @@ class TimestampTest < ActiveRecord::TestCase Pet.belongs_to :owner, :touch => true end + def test_touching_a_record_with_a_belongs_to_that_uses_a_counter_cache_should_update_the_parent + Pet.belongs_to :owner, :counter_cache => :use_count, :touch => true + + pet = Pet.first + owner = pet.owner + owner.update_attribute(:happy_at, (time = 3.days.ago)) + previously_owner_updated_at = owner.updated_at + + pet.name = "I'm a parrot" + pet.save + + assert_not_equal previously_owner_updated_at, pet.owner.updated_at + ensure + Pet.belongs_to :owner, :touch => true + end + def test_touching_a_record_touches_parent_record_and_grandparent_record Toy.belongs_to :pet, :touch => true Pet.belongs_to :owner, :touch => true diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index d72c4bf7c4..cc146f5574 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -272,7 +272,7 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase topic = TopicWithObserverAttached.new topic.save! - assert topic.history, [:"TopicWithObserverAttachedObserver#after_commit"] + assert_equal topic.history, [:"TopicWithObserverAttachedObserver#after_commit"] end def test_after_rollback_called @@ -283,6 +283,6 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase raise ActiveRecord::Rollback end - assert topic.history, [:"TopicWithObserverObserver#after_rollback"] + assert_equal topic.history, [:"TopicWithObserverObserver#after_rollback"] end end diff --git a/activerecord/test/connections/native_oracle/connection.rb b/activerecord/test/connections/native_oracle/connection.rb index bb4040058f..00164466f2 100644 --- a/activerecord/test/connections/native_oracle/connection.rb +++ b/activerecord/test/connections/native_oracle/connection.rb @@ -1,10 +1,5 @@ -# gem "rsim-activerecord-oracle_enhanced-adapter" -# gem "activerecord-oracle_enhanced-adapter", ">=1.2.1" -# uses local copy of oracle_enhanced adapter -$:.unshift("../../oracle-enhanced/lib") +# uses oracle_enhanced adapter in ENV['ORACLE_ENHANCED_PATH'] or from github.com/rsim/oracle-enhanced.git require 'active_record/connection_adapters/oracle_enhanced_adapter' -# gem "activerecord-jdbc-adapter" -# require 'active_record/connection_adapters/jdbc_adapter' # otherwise failed with silence_warnings method missing exception require 'active_support/core_ext/kernel/reporting' diff --git a/activerecord/test/schema/mysql_specific_schema.rb b/activerecord/test/schema/mysql_specific_schema.rb index c78d99f4af..30e1c5a167 100644 --- a/activerecord/test/schema/mysql_specific_schema.rb +++ b/activerecord/test/schema/mysql_specific_schema.rb @@ -21,4 +21,15 @@ BEGIN END SQL + ActiveRecord::Base.connection.execute <<-SQL +DROP PROCEDURE IF EXISTS topics; +SQL + + ActiveRecord::Base.connection.execute <<-SQL +CREATE PROCEDURE topics() SQL SECURITY INVOKER +BEGIN + select * from topics limit 1; +END +SQL + end |