aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb4
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb11
-rw-r--r--activerecord/test/cases/calculations_test.rb4
-rw-r--r--activerecord/test/cases/migration/command_recorder_test.rb8
4 files changed, 22 insertions, 5 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 7e331658a3..a2764f3e3b 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -226,6 +226,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 2, Firm.find(:first, :order => "id").clients.length
end
+ def test_finding_array_compatibility
+ assert_equal 2, Firm.order(:id).find{|f| f.id > 0}.clients.length
+ end
+
def test_find_with_blank_conditions
[[], {}, nil, ""].each do |blank|
assert_equal 2, Firm.find(:first, :order => "id").clients.find(:all, :conditions => blank).size
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index a1d0dafa57..26931e3e85 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -345,6 +345,17 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
assert orig_ship.destroyed?
end
+ def test_creation_failure_due_to_new_record_should_raise_error
+ pirate = pirates(:redbeard)
+ new_ship = Ship.new
+
+ assert_raise(ActiveRecord::RecordNotSaved) do
+ pirate.ship = new_ship
+ end
+ assert_nil pirate.ship
+ assert_nil new_ship.pirate_id
+ end
+
def test_replacement_failure_due_to_existing_record_should_raise_error
pirate = pirates(:blackbeard)
pirate.ship.name = nil
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 56f6d795b6..224b3f3d1f 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -397,6 +397,10 @@ class CalculationsTest < ActiveRecord::TestCase
Account.sum(:credit_limit, :from => 'accounts', :conditions => "credit_limit > 50")
end
+ def test_sum_array_compatibility
+ assert_equal Account.sum(:credit_limit), Account.sum(&:credit_limit)
+ end
+
def test_average_with_from_option
assert_equal Account.average(:credit_limit), Account.average(:credit_limit, :from => 'accounts')
assert_equal Account.average(:credit_limit, :conditions => "credit_limit > 50"),
diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb
index 85d38fac25..36007255fa 100644
--- a/activerecord/test/cases/migration/command_recorder_test.rb
+++ b/activerecord/test/cases/migration/command_recorder_test.rb
@@ -14,11 +14,9 @@ module ActiveRecord
assert recorder.respond_to?(:america)
end
- def test_non_existing_method_records_and_raises_on_inversion
- @recorder.send(:non_existing_method, :horses)
- assert_equal 1, @recorder.commands.length
- assert_raises(ActiveRecord::IrreversibleMigration) do
- @recorder.inverse
+ def test_send_calls_super
+ assert_raises(NoMethodError) do
+ @recorder.send(:non_existing_method, :horses)
end
end