44require 'models/post'
55class SanitizeTest < ActiveRecord ::TestCase
66
7- coerce_tests :test_sanitize_sql_like_example_use_case
7+ coerce_tests! :test_sanitize_sql_like_example_use_case
88
99 def test_sanitize_sql_like_example_use_case_coerced
1010 searchable_post = Class . new ( Post ) do
@@ -20,12 +20,13 @@ def self.search(term)
2020end
2121
2222
23+
2324require 'models/author'
2425class YamlSerializationTest < ActiveRecord ::TestCase
2526
2627 fixtures :authors
2728
28- coerce_tests :test_types_of_virtual_columns_are_not_changed_on_round_trip
29+ coerce_tests! :test_types_of_virtual_columns_are_not_changed_on_round_trip
2930
3031 def test_types_of_virtual_columns_are_not_changed_on_round_trip_coerced
3132 author = Author . select ( 'authors.*, 5 as posts_count' ) . first
@@ -37,6 +38,7 @@ def test_types_of_virtual_columns_are_not_changed_on_round_trip_coerced
3738end
3839
3940
41+
4042module ActiveRecord
4143 module ConnectionAdapters
4244 class TypeLookupTest < ActiveRecord ::TestCase
@@ -48,6 +50,7 @@ class TypeLookupTest < ActiveRecord::TestCase
4850end
4951
5052
53+
5154module ActiveRecord
5255 module ConnectionAdapters
5356 class MergeAndResolveDefaultUrlConfigTest < ActiveRecord ::TestCase
@@ -63,3 +66,147 @@ class MergeAndResolveDefaultUrlConfigTest < ActiveRecord::TestCase
6366end
6467
6568
69+
70+ require 'models/post'
71+ module ActiveRecord
72+ class WhereChainTest < ActiveRecord ::TestCase
73+
74+ coerce_tests! :test_not_eq_with_array_parameter
75+ def test_not_eq_with_array_parameter_coerced
76+ expected = Arel ::Nodes ::Not . new ( "title = N'hello'" )
77+ relation = Post . where . not ( [ 'title = ?' , 'hello' ] )
78+ assert_equal ( [ expected ] , relation . where_values )
79+ end
80+
81+ end
82+ end
83+
84+
85+
86+ require 'models/company'
87+ class InheritanceTest < ActiveRecord ::TestCase
88+
89+ fixtures :companies , :projects , :subscribers , :accounts , :vegetables
90+
91+ coerce_tests! :test_eager_load_belongs_to_primary_key_quoting
92+ def test_eager_load_belongs_to_primary_key_quoting_coerced
93+ con = Account . connection
94+ assert_sql ( /\[ companies\] \. \[ id\] IN \( 1\) / ) do
95+ Account . all . merge! ( :includes => :firm ) . find ( 1 )
96+ end
97+ end
98+
99+ end
100+
101+
102+
103+ require 'models/developer'
104+ require 'models/computer'
105+ class NestedRelationScopingTest < ActiveRecord ::TestCase
106+
107+ fixtures :authors , :developers , :projects , :comments , :posts
108+
109+ coerce_tests! :test_merge_options
110+ def test_merge_options_coerced
111+ Developer . where ( 'salary = 80000' ) . scoping do
112+ Developer . limit ( 10 ) . scoping do
113+ devs = Developer . all
114+ sql = devs . to_sql
115+ assert_match '(salary = 80000)' , sql
116+ assert_match 'FETCH NEXT 10 ROWS ONLY' , sql
117+ end
118+ end
119+ end
120+
121+ end
122+
123+
124+
125+ require 'models/post'
126+ require 'models/subscriber'
127+ class EachTest < ActiveRecord ::TestCase
128+
129+ fixtures :posts , :subscribers
130+
131+ coerce_tests! :test_find_in_batches_should_quote_batch_order
132+ def test_find_in_batches_should_quote_batch_order_coerced
133+ c = Post . connection
134+ assert_sql ( /ORDER BY \[ posts\] \. \[ id\] / ) do
135+ Post . find_in_batches ( :batch_size => 1 ) do |batch |
136+ assert_kind_of Array , batch
137+ assert_kind_of Post , batch . first
138+ end
139+ end
140+ end
141+
142+ end
143+
144+
145+
146+ require 'models/topic'
147+ module ActiveRecord
148+ class PredicateBuilderTest < ActiveRecord ::TestCase
149+
150+ coerce_tests! :test_registering_new_handlers
151+ def test_registering_new_handlers_coerced
152+ PredicateBuilder . register_handler ( Regexp , proc do |column , value |
153+ Arel ::Nodes ::InfixOperation . new ( '~' , column , Arel . sql ( value . source ) )
154+ end )
155+ assert_match %r{\[ topics\] \. \[ title\] ~ rails}i , Topic . where ( title : /rails/ ) . to_sql
156+ end
157+
158+ end
159+ end
160+
161+
162+
163+ module ActiveRecord
164+ class Migration
165+ class ChangeSchemaTest < ActiveRecord ::TestCase
166+
167+ coerce_tests! :test_create_table_with_bigint ,
168+ :test_create_table_with_defaults # We test these.
169+
170+ end
171+ end
172+ end
173+
174+
175+
176+ require 'models/topic'
177+ class FinderTest < ActiveRecord ::TestCase
178+
179+ coerce_tests! %r{doesn't have implicit ordering} ,
180+ :test_find_doesnt_have_implicit_ordering # We have implicit ordering, via FETCH.
181+
182+ coerce_tests! :test_exists_does_not_select_columns_without_alias
183+ def test_exists_does_not_select_columns_without_alias_coerced
184+ assert_sql ( /SELECT\s +1 AS one FROM \[ topics\] .*OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY/i ) do
185+ Topic . exists?
186+ end
187+ end
188+
189+ coerce_tests! :test_string_sanitation
190+ def test_string_sanitation_coerced
191+ assert_not_equal "'something ' 1=1'" , ActiveRecord ::Base . sanitize ( "something ' 1=1" )
192+ assert_equal "N'something; select table'" , ActiveRecord ::Base . sanitize ( "something; select table" )
193+ end
194+
195+ coerce_tests! :test_take_and_first_and_last_with_integer_should_use_sql_limit
196+ def test_take_and_first_and_last_with_integer_should_use_sql_limit_coerced
197+ assert_sql ( /OFFSET 0 ROWS FETCH NEXT 3 ROWS ONLY/ ) { Topic . take ( 3 ) . entries }
198+ assert_sql ( /OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY/ ) { Topic . first ( 2 ) . entries }
199+ assert_sql ( /OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY/ ) { Topic . last ( 5 ) . entries }
200+ end
201+
202+ end
203+
204+
205+
206+ class RelationTest < ActiveRecord ::TestCase
207+
208+ coerce_tests! %r{doesn't have implicit ordering} # We have implicit ordering, via FETCH.
209+
210+ end
211+
212+
0 commit comments