@@ -1100,86 +1100,35 @@ def schema_dump_path
11001100end
11011101
11021102class UnsafeRawSqlTest < ActiveRecord ::TestCase
1103- coerce_tests! %r{always allows Arel}
1103+ # Coerce the originals as they use 'LENGTH' instead of SQL Servers 'LEN' function.
1104+
1105+ coerce_tests! %r{order: always allows Arel}
11041106 test 'order: always allows Arel' do
11051107 ids_depr = with_unsafe_raw_sql_deprecated { Post . order ( Arel . sql ( "len(title)" ) ) . pluck ( :title ) }
11061108 ids_disabled = with_unsafe_raw_sql_disabled { Post . order ( Arel . sql ( "len(title)" ) ) . pluck ( :title ) }
11071109
11081110 assert_equal ids_depr , ids_disabled
11091111 end
11101112
1113+ coerce_tests! %r{pluck: always allows Arel}
11111114 test "pluck: always allows Arel" do
11121115 values_depr = with_unsafe_raw_sql_deprecated { Post . includes ( :comments ) . pluck ( :title , Arel . sql ( "len(title)" ) ) }
11131116 values_disabled = with_unsafe_raw_sql_disabled { Post . includes ( :comments ) . pluck ( :title , Arel . sql ( "len(title)" ) ) }
11141117
11151118 assert_equal values_depr , values_disabled
11161119 end
11171120
1118-
1119- coerce_tests! %r{order: disallows invalid Array arguments}
1120- test "order: disallows invalid Array arguments" do
1121- with_unsafe_raw_sql_disabled do
1122- assert_raises ( ActiveRecord ::UnknownAttributeReference ) do
1123- Post . order ( [ "author_id" , "len(title)" ] ) . pluck ( :id )
1124- end
1125- end
1126- end
1127-
11281121 coerce_tests! %r{order: allows valid Array arguments}
11291122 test "order: allows valid Array arguments" do
11301123 ids_expected = Post . order ( Arel . sql ( "author_id, len(title)" ) ) . pluck ( :id )
11311124
1132- ids_depr = with_unsafe_raw_sql_deprecated { Post . order ( [ "author_id" , Arel . sql ( "len(title)" ) ] ) . pluck ( :id ) }
1133- ids_disabled = with_unsafe_raw_sql_disabled { Post . order ( [ "author_id" , Arel . sql ( "len(title)" ) ] ) . pluck ( :id ) }
1125+ ids_depr = with_unsafe_raw_sql_deprecated { Post . order ( [ "author_id" , "len(title)" ] ) . pluck ( :id ) }
1126+ ids_disabled = with_unsafe_raw_sql_disabled { Post . order ( [ "author_id" , "len(title)" ] ) . pluck ( :id ) }
11341127
11351128 assert_equal ids_expected , ids_depr
11361129 assert_equal ids_expected , ids_disabled
11371130 end
11381131
1139- coerce_tests! %r{order: logs deprecation warning for unrecognized column}
1140- test "order: logs deprecation warning for unrecognized column" do
1141- with_unsafe_raw_sql_deprecated do
1142- assert_deprecated ( /Dangerous query method/ ) do
1143- Post . order ( "len(title)" )
1144- end
1145- end
1146- end
1147-
1148- coerce_tests! %r{pluck: disallows invalid column name}
1149- test "pluck: disallows invalid column name" do
1150- with_unsafe_raw_sql_disabled do
1151- assert_raises ( ActiveRecord ::UnknownAttributeReference ) do
1152- Post . pluck ( "len(title)" )
1153- end
1154- end
1155- end
1156-
1157- coerce_tests! %r{pluck: disallows invalid column name amongst valid names}
1158- test "pluck: disallows invalid column name amongst valid names" do
1159- with_unsafe_raw_sql_disabled do
1160- assert_raises ( ActiveRecord ::UnknownAttributeReference ) do
1161- Post . pluck ( :title , "len(title)" )
1162- end
1163- end
1164- end
1165-
1166- coerce_tests! %r{pluck: disallows invalid column names with includes}
1167- test "pluck: disallows invalid column names with includes" do
1168- with_unsafe_raw_sql_disabled do
1169- assert_raises ( ActiveRecord ::UnknownAttributeReference ) do
1170- Post . includes ( :comments ) . pluck ( :title , "len(title)" )
1171- end
1172- end
1173- end
1174-
1175- coerce_tests! %r{pluck: logs deprecation warning}
1176- test "pluck: logs deprecation warning" do
1177- with_unsafe_raw_sql_deprecated do
1178- assert_deprecated ( /Dangerous query method/ ) do
1179- Post . includes ( :comments ) . pluck ( :title , "len(title)" )
1180- end
1181- end
1182- end
11831132end
11841133
11851134
0 commit comments