Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8947: habtm_duplicate_links_tests.diff

File habtm_duplicate_links_tests.diff, 3.5 kB (added by jcoglan, 1 year ago)
  • activerecord/test/associations_test.rb

    old new  
    15201520    assert_equal developers(:poor_jamis, :jamis, :david), projects(:active_record).developers 
    15211521  end 
    15221522 
     1523  def setup_habtm_association_with_duplicate_links 
     1524    @duplicate_category = categories(:duplicates) 
     1525    @duplicate_category.posts << posts(:welcome) << posts(:welcome) << posts(:welcome) 
     1526    @duplicate_category.posts << posts(:thinking) << posts(:thinking) << posts(:thinking) 
     1527  end 
     1528 
     1529  def test_habtm_with_unique_eager_loading 
     1530    setup_habtm_association_with_duplicate_links 
     1531    assert_equal 2, @duplicate_category.posts.size 
     1532  end 
     1533 
     1534  def test_habtm_scoped_find_with_unique_eager_loading 
     1535    setup_habtm_association_with_duplicate_links 
     1536    assert_equal 2, @duplicate_category.posts.find(:all).size 
     1537  end 
     1538 
     1539  def test_habtm_scoped_find_with_unique_eager_loading_and_limit 
     1540    setup_habtm_association_with_duplicate_links 
     1541    assert_equal 2, @duplicate_category.posts.find(:all, :limit => 2).size 
     1542  end 
     1543 
     1544  def test_habtm_scoped_find_with_unique_eager_loading_and_include 
     1545    setup_habtm_association_with_duplicate_links 
     1546    assert_equal 2, @duplicate_category.posts.find(:all, :include => :author_with_posts).size 
     1547  end 
     1548 
     1549  def test_habtm_scoped_find_with_unique_eager_loading_and_limit_and_include_limitable_reflection 
     1550    setup_habtm_association_with_duplicate_links 
     1551    assert_equal 2, @duplicate_category.posts.find(:all, :limit => 2, :include => :author_with_posts).size 
     1552  end 
     1553 
     1554  def test_habtm_scoped_find_with_unique_eager_loading_and_limit_and_include_non_limitable_reflection 
     1555    setup_habtm_association_with_duplicate_links 
     1556    assert_equal 2, @duplicate_category.posts.find(:all, :limit => 2, :include => :readers).size 
     1557  end 
     1558 
    15231559  def test_build 
    15241560    devel = Developer.find(1) 
    15251561    proj = devel.projects.build("name" => "Projekt") 
  • activerecord/test/fixtures/categories.yml

    old new  
    1212  id: 3 
    1313  name: Special category 
    1414  type: SpecialCategory 
     15 
     16duplicates: 
     17  id: 4 
     18  name: Duplicate links 
     19  type: Category 
  • activerecord/test/fixtures/category.rb

    old new  
    11class Category < ActiveRecord::Base 
    2   has_and_belongs_to_many :posts 
     2  has_and_belongs_to_many :posts, :uniq => true 
    33  has_and_belongs_to_many :special_posts, :class_name => "Post" 
    44  has_and_belongs_to_many :other_posts, :class_name => "Post" 
    55   
  • activerecord/test/fixtures/post.rb

    old new  
    1717  has_one  :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post 
    1818  has_many :special_comments 
    1919 
    20   has_and_belongs_to_many :categories 
     20  has_and_belongs_to_many :categories, :uniq => true 
    2121  has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id' 
    2222 
    2323  has_many :taggings, :as => :taggable