mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
7117fdb8ce
Ticket 2292 - Sequences, schemas, and fixtures r3917@asus: jeremy | 2005-10-15 10:43:24 -0700 fix pk assert r3918@asus: jeremy | 2005-10-15 10:46:52 -0700 rework query cache connection= override r3919@asus: jeremy | 2005-10-15 10:47:45 -0700 correct fixtures usage r3920@asus: jeremy | 2005-10-15 10:53:23 -0700 correct attr assignment r3921@asus: jeremy | 2005-10-15 12:59:10 -0700 sequences r3922@asus: jeremy | 2005-10-15 16:36:09 -0700 reset fixtures work with sequences r3951@asus: jeremy | 2005-10-15 23:23:12 -0700 cut down excess features r3952@asus: jeremy | 2005-10-15 23:40:30 -0700 don't test for PostgreSQL specifically git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2639 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
79 lines
2.4 KiB
Ruby
79 lines
2.4 KiB
Ruby
require 'abstract_unit'
|
|
require 'fixtures/topic'
|
|
require 'fixtures/subscriber'
|
|
require 'fixtures/movie'
|
|
require 'fixtures/keyboard'
|
|
|
|
class PrimaryKeysTest < Test::Unit::TestCase
|
|
fixtures :topics, :subscribers, :movies
|
|
|
|
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_customized_primary_key_auto_assigns_on_save
|
|
keyboard = Keyboard.new(:name => 'HHKB')
|
|
assert_nothing_raised { keyboard.save }
|
|
assert keyboard.id
|
|
assert_equal keyboard.id, Keyboard.find_by_name('HHKB').id
|
|
end
|
|
|
|
def test_customized_primary_key_can_be_get_before_saving
|
|
keyboard = Keyboard.new
|
|
assert_respond_to(keyboard, :key_number)
|
|
assert_nothing_raised { keyboard.key_number }
|
|
end
|
|
|
|
def test_customized_string_primary_key_settable_before_save
|
|
subscriber = Subscriber.new
|
|
assert_nothing_raised { subscriber.id = 'webster123' }
|
|
assert_equal 'webster123', subscriber.id
|
|
assert_equal 'webster123', subscriber.nick
|
|
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
|
|
Topic.reset_primary_key
|
|
assert_equal "topicid", Topic.primary_key
|
|
|
|
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
|
|
Topic.reset_primary_key
|
|
assert_equal "topic_id", Topic.primary_key
|
|
|
|
ActiveRecord::Base.primary_key_prefix_type = nil
|
|
Topic.reset_primary_key
|
|
assert_equal "id", Topic.primary_key
|
|
end
|
|
end
|