|
24 | 24 | require "models/too_long_table_name"
|
25 | 25 | require "support/stubs/strong_parameters"
|
26 | 26 | require "support/async_helper"
|
| 27 | +require "models/cpk/book" |
27 | 28 |
|
28 | 29 | class CalculationsTest < ActiveRecord::TestCase
|
29 | 30 | include AsyncHelper
|
30 | 31 |
|
31 |
| - fixtures :companies, :accounts, :authors, :author_addresses, :topics, :speedometers, :minivans, :books, :posts, :comments |
| 32 | + fixtures :companies, :accounts, :authors, :author_addresses, :topics, :speedometers, :minivans, :books, :posts, :comments, :cpk_books |
32 | 33 |
|
33 | 34 | def test_should_sum_field
|
34 | 35 | assert_equal 318, Account.sum(:credit_limit)
|
@@ -940,6 +941,25 @@ def test_ids
|
940 | 941 | assert_equal Company.all.map(&:id).sort, Company.all.ids.sort
|
941 | 942 | end
|
942 | 943 |
|
| 944 | + def ids_for_a_composite_primary_key |
| 945 | + assert_equal Cpk::Book.all.map(&:id).sort, Cpk::Book.all.ids.sort |
| 946 | + end |
| 947 | + |
| 948 | + def test_ids_for_a_composite_primary_key_with_scope |
| 949 | + book = cpk_books(:cpk_great_author_first_book) |
| 950 | + |
| 951 | + assert_equal [[book.author_id, book.number]], Cpk::Book.all.where(title: book.title).ids |
| 952 | + end |
| 953 | + |
| 954 | + def test_ids_for_a_composite_primary_key_on_loaded_relation |
| 955 | + book = cpk_books(:cpk_great_author_first_book) |
| 956 | + relation = Cpk::Book.where(title: book.title) |
| 957 | + relation.to_a |
| 958 | + |
| 959 | + assert_predicate relation, :loaded? |
| 960 | + assert_equal [[book.author_id, book.number]], relation.ids |
| 961 | + end |
| 962 | + |
943 | 963 | def test_ids_with_scope
|
944 | 964 | scoped_ids = [1, 2]
|
945 | 965 | assert_equal Company.where(id: scoped_ids).map(&:id).sort, Company.where(id: scoped_ids).ids.sort
|
|
0 commit comments