aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/inheritance_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-14 12:32:29 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-14 12:32:29 +0000
commit605bc77533cf3b6700e91eda8994cdf6b82341cc (patch)
tree687a1c7e3bd319be5c0a6090dea190d6a8778658 /activerecord/test/inheritance_test.rb
parent317f13c2a8c047b3868a58e0121453b092557dba (diff)
downloadrails-605bc77533cf3b6700e91eda8994cdf6b82341cc.tar.gz
rails-605bc77533cf3b6700e91eda8994cdf6b82341cc.tar.bz2
rails-605bc77533cf3b6700e91eda8994cdf6b82341cc.zip
Added a better exception for when a type column is used in a table without the intention of triggering single-table inheritance. Added that single-table inheritance will only kick in if the inheritance_column (by default "type") is present. Otherwise, inheritance wont have any magic side effects
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@149 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/inheritance_test.rb')
-rwxr-xr-xactiverecord/test/inheritance_test.rb34
1 files changed, 22 insertions, 12 deletions
diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb
index 6f8175801d..e595ed1e92 100755
--- a/activerecord/test/inheritance_test.rb
+++ b/activerecord/test/inheritance_test.rb
@@ -1,20 +1,13 @@
require 'abstract_unit'
require 'fixtures/company'
-
+require 'fixtures/project'
class InheritanceTest < Test::Unit::TestCase
- def setup
- @company_fixtures = create_fixtures "companies"
- end
+ fixtures :companies, :projects
- def switch_to_alt_inheritance_column
- # we don't want misleading test results, so get rid of the values in the type column
- Company.find_all(nil, "id").each do |c|
- c['type'] = nil
- c.save
- end
-
- def Company.inheritance_column() "ruby_type" end
+ def test_a_bad_type_column
+ Company.connection.insert "INSERT INTO companies (id, type, name) VALUES(100, 'bad_class!', 'Not happening')"
+ assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
end
def test_inheritance_find
@@ -122,4 +115,21 @@ class InheritanceTest < Test::Unit::TestCase
switch_to_alt_inheritance_column
test_complex_inheritance
end
+
+ def test_inheritance_without_mapping
+ assert_kind_of SpecialProject, SpecialProject.find(1)
+ assert_nothing_raised { SpecialProject.create("name" => "And breaaaaathe!") }
+
+ end
+
+ private
+ def switch_to_alt_inheritance_column
+ # we don't want misleading test results, so get rid of the values in the type column
+ Company.find_all(nil, "id").each do |c|
+ c['type'] = nil
+ c.save
+ end
+
+ def Company.inheritance_column() "ruby_type" end
+ end
end \ No newline at end of file