aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-07-14 23:00:08 -0300
committerEmilio Tagua <miloops@gmail.com>2009-07-14 23:00:08 -0300
commit634f6713ee15c6fd958bafc7a3422acac2e3343f (patch)
tree0df11ceb12f9911ad16c950802af1e5874c89ab4 /activerecord/test/cases
parentfb46d00fdfa724dc0c252a46ec13c4ee4cda4708 (diff)
parent40b387580ff251e06632fbcc87c2a78c027a6b27 (diff)
downloadrails-634f6713ee15c6fd958bafc7a3422acac2e3343f.tar.gz
rails-634f6713ee15c6fd958bafc7a3422acac2e3343f.tar.bz2
rails-634f6713ee15c6fd958bafc7a3422acac2e3343f.zip
Merge commit 'rails/master'
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb8
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb16
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb14
3 files changed, 29 insertions, 9 deletions
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 7a4712d7c8..8529ff0285 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -243,8 +243,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal 2, people(:michael).jobs.size
end
- def test_get_ids
- assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort
+ def test_get_ids_for_belongs_to_source
+ assert_sql(/DISTINCT/) { assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort }
+ end
+
+ def test_get_ids_for_has_many_source
+ assert_equal [comments(:eager_other_comment1).id], authors(:mary).comment_ids
end
def test_get_ids_for_loaded_associations
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 17ed302465..183be1e2f9 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -277,6 +277,22 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :title => "Ants in pants" } }
end
+ def test_read_attribute_overwrites_private_method_not_considered_implemented
+ # simulate a model with a db column that shares its name an inherited
+ # private method (e.g. Object#system)
+ #
+ Object.class_eval do
+ private
+ def title; "private!"; end
+ end
+ assert !@target.instance_method_already_implemented?(:title)
+ topic = @target.new
+ assert_equal nil, topic.title
+
+ Object.send(:undef_method, :title) # remove test method from object
+ end
+
+
private
def time_related_columns_on_topic
Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 4f02be3c06..9612b0beb6 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -156,6 +156,13 @@ class SchemaDumperTest < ActiveRecord::TestCase
index_definition = standard_dump.split(/\n/).grep(/add_index.*companies/).first.strip
assert_equal 'add_index "companies", ["firm_id", "type", "rating", "ruby_type"], :name => "company_index"', index_definition
end
+
+ def test_schema_dump_should_honor_nonstandard_primary_keys
+ output = standard_dump
+ match = output.match(%r{create_table "movies"(.*)do})
+ assert_not_nil(match, "nonstandardpk table not found")
+ assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
+ end
if current_adapter?(:MysqlAdapter)
def test_schema_dump_should_not_add_default_value_for_mysql_text_field
@@ -163,13 +170,6 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_match %r{t.text\s+"body",\s+:null => false$}, output
end
- def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
- output = standard_dump
- match = output.match(%r{create_table "movies"(.*)do})
- assert_not_nil(match, "nonstandardpk table not found")
- assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
- end
-
def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
output = standard_dump
assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output