Sha256: 4539ad2e33169d85e00f6b92b309894a87c135eafce28de068c4bb7681098fd4

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

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"
    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"
    subscriber.name = "John Doe"
    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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-1.0.0 test/pk_test.rb
activerecord-1.1.0 test/pk_test.rb