From a8afc6395b9ccbbe62c6deaa01294b4bd3aac758 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 26 May 2014 07:46:11 -0700 Subject: Add missing test case for quoting behavior It appears that the only time that `quote` is called with a column, but without first calling `type_cast` is when where is called with an array. My previous pull request broke this behavior, without failing tests. This adds a test for the only case I can think of that exercises the `if column.type == :integer` branch of `quote` effectively. --- activerecord/test/cases/base_test.rb | 4 ++++ activerecord/test/cases/relations_test.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index c565daba65..1b3aa84a06 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -518,6 +518,10 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Topic.find('1-meowmeow'), Topic.find(1) end + def test_find_by_slug_with_array + assert_equal Topic.find(['1-meowmeow', '2-hello']), Topic.find([1, 2]) + end + def test_equality_of_new_records assert_not_equal Topic.new, Topic.new assert_equal false, Topic.new == Topic.new diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 4b146c11bc..61111b254a 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -750,6 +750,13 @@ class RelationTest < ActiveRecord::TestCase assert_equal [], relation.to_a end + def test_typecasting_where_with_array + ids = Author.pluck(:id) + slugs = ids.map { |id| "#{id}-as-a-slug" } + + assert_equal Author.all.to_a, Author.where(id: slugs).to_a + end + def test_find_all_using_where_with_relation david = authors(:david) # switching the lines below would succeed in current rails -- cgit v1.2.3