Guest User

Untitled

a guest
Apr 26th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. def test_eager_with_multiple_associations_with_same_table_has_many_and_habtm
  2. # Eager includes of has many and habtm associations aren't necessarily sorted in the same way
  3. # Test regular association, association with conditions, association with
  4. # STI, and association with conditions assured not to be true
  5.  
  6. post_types = [:posts, :other_posts, :special_posts]
  7. # test both has_many and has_and_belongs_to_many
  8. [Author, Category].each do |className|
  9. d1 = find_all_ordered(className)
  10. # test including all post types at once
  11. d2 = find_all_ordered(className, post_types)
  12. d1.each_index do |i|
  13. assert_equal(d1[i], d2[i])
  14. assert_equal_after_sort(d1[i].posts, d2[i].posts)
  15. post_types[1..-1].each do |post_type|
  16. # test including post_types together
  17. d3 = find_all_ordered(className, [:posts, post_type])
  18. assert_equal(d1[i], d3[i])
  19. assert_equal_after_sort(d1[i].posts, d3[i].posts)
  20. assert_equal_after_sort(d1[i].send(post_type), d2[i].send(post_type), d3[i].send(post_type))
  21. end
  22. end
  23. end
  24. end
Add Comment
Please, Sign In to add comment