diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
commit | db045dbbf60b53dbe013ef25554fd013baf88134 (patch) | |
tree | 257830e3c76458c8ff3d1329de83f32b23926028 /activerecord/test/pk_test.rb | |
download | rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.gz rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.bz2 rails-db045dbbf60b53dbe013ef25554fd013baf88134.zip |
Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/pk_test.rb')
-rw-r--r-- | activerecord/test/pk_test.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/activerecord/test/pk_test.rb b/activerecord/test/pk_test.rb new file mode 100644 index 0000000000..aefaebde6e --- /dev/null +++ b/activerecord/test/pk_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' +require 'fixtures/topic' +require 'fixtures/subscriber' +require 'fixtures/movie' + +class PrimaryKeysTest < Test::Unit::TestCase + def setup + @topics = create_fixtures "topics" + @subscribers = create_fixtures "subscribers" + @movies = create_fixtures "movies" + end + + def test_integer_key + topic = Topic.find(1) + assert_equal(@topics["first"]["author_name"], topic.author_name) + topic = Topic.find(2) + assert_equal(@topics["second"]["author_name"], topic.author_name) + + topic = Topic.new + topic.title = "New Topic" + assert_equal(nil, topic.id) + assert_nothing_raised{ topic.save } + id = topic.id + + topicReloaded = Topic.find(id) + assert_equal("New Topic", topicReloaded.title) + end + + def test_string_key + subscriber = Subscriber.find(@subscribers["first"]["nick"]) + assert_equal(@subscribers["first"]["name"], subscriber.name) + subscriber = Subscriber.find(@subscribers["second"]["nick"]) + assert_equal(@subscribers["second"]["name"], subscriber.name) + + subscriber = Subscriber.new + subscriber.id = "jdoe" + assert_equal("jdoe", subscriber.id) + subscriber.name = "John Doe" + assert_nothing_raised{ subscriber.save } + + subscriberReloaded = Subscriber.find("jdoe") + assert_equal("John Doe", subscriberReloaded.name) + end + + def test_find_with_more_than_one_string_key + assert_equal 2, Subscriber.find(@subscribers["first"]["nick"], @subscribers["second"]["nick"]).length + end + + def test_primary_key_prefix + ActiveRecord::Base.primary_key_prefix_type = :table_name + assert_equal "topicid", Topic.primary_key + + ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore + assert_equal "topic_id", Topic.primary_key + + ActiveRecord::Base.primary_key_prefix_type = nil + assert_equal "id", Topic.primary_key + end +end |