|
25 | 25 |
|
26 | 26 | class PersistenceTest < ActiveRecord::TestCase
|
27 | 27 | fixtures :topics, :companies, :developers, :accounts, :minimalistics, :authors, :author_addresses,
|
28 |
| - :posts, :minivans, :clothing_items |
| 28 | + :posts, :minivans, :clothing_items, :cpk_books |
29 | 29 |
|
30 | 30 | def test_update_many
|
31 | 31 | topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
|
@@ -292,6 +292,40 @@ def test_destroy_many_with_invalid_id
|
292 | 292 | assert_equal clients, Client.find([2, 3])
|
293 | 293 | end
|
294 | 294 |
|
| 295 | + def test_destroy_with_single_composite_primary_key |
| 296 | + book = cpk_books(:cpk_great_author_first_book) |
| 297 | + |
| 298 | + assert_difference("Cpk::Book.count", -1) do |
| 299 | + destroyed = Cpk::Book.destroy(book.id) |
| 300 | + assert_equal destroyed, book |
| 301 | + end |
| 302 | + end |
| 303 | + |
| 304 | + def test_destroy_with_multiple_composite_primary_keys |
| 305 | + books = [ |
| 306 | + cpk_books(:cpk_great_author_first_book), |
| 307 | + cpk_books(:cpk_great_author_second_book), |
| 308 | + ] |
| 309 | + |
| 310 | + assert_difference("Cpk::Book.count", -2) do |
| 311 | + destroyed = Cpk::Book.destroy(books.map(&:id)) |
| 312 | + assert_equal books.sort, destroyed.sort |
| 313 | + assert destroyed.all?(&:frozen?), "destroyed clients should be frozen" |
| 314 | + end |
| 315 | + end |
| 316 | + |
| 317 | + def test_destroy_with_invalid_ids_for_a_model_that_expects_composite_keys |
| 318 | + books = [ |
| 319 | + cpk_books(:cpk_great_author_first_book), |
| 320 | + cpk_books(:cpk_great_author_second_book), |
| 321 | + ] |
| 322 | + |
| 323 | + assert_raise(ActiveRecord::RecordNotFound) do |
| 324 | + ids = books.map { |book| book.id.first } |
| 325 | + Cpk::Book.destroy(ids) |
| 326 | + end |
| 327 | + end |
| 328 | + |
295 | 329 | def test_becomes
|
296 | 330 | assert_kind_of Reply, topics(:first).becomes(Reply)
|
297 | 331 | assert_equal "The First Topic", topics(:first).becomes(Reply).title
|
|
0 commit comments