Skip to content

Commit dbdc676

Browse files
committed
Coercing a group of tests.
ActiveRecord::WhereChainTest#test_not_eq_with_array_parameter InheritanceTest#test_eager_load_belongs_to_primary_key_quoting NestedRelationScopingTest#test_merge_options EachTest#test_find_in_batches_should_quote_batch_order ActiveRecord::PredicateBuilderTest#test_registering_new_handlers ActiveRecord::Migration::ChangeSchemaTest#test_create_table_with_bigint ActiveRecord::Migration::ChangeSchemaTest#test_create_table_with_defaults FinderTest#test_0006_find_by doesn't have implicit ordering FinderTest#test_0010_find_by! doesn't have implicit ordering RelationTest#test_0005_find_by doesn't have implicit ordering RelationTest#test_0009_find_by! doesn't have implicit ordering FinderTest#test_exists_does_not_select_columns_without_alias FinderTest#test_find_doesnt_have_implicit_ordering FinderTest#test_string_sanitation FinderTest#test_take_and_first_and_last_with_integer_should_use_sql_limit 33 failures, 26 errors, 2 skips
1 parent 3177e67 commit dbdc676

File tree

1 file changed

+149
-2
lines changed

1 file changed

+149
-2
lines changed

test/cases/coerced_tests.rb

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'models/post'
55
class 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)
2020
end
2121

2222

23+
2324
require 'models/author'
2425
class 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
3738
end
3839

3940

41+
4042
module ActiveRecord
4143
module ConnectionAdapters
4244
class TypeLookupTest < ActiveRecord::TestCase
@@ -48,6 +50,7 @@ class TypeLookupTest < ActiveRecord::TestCase
4850
end
4951

5052

53+
5154
module ActiveRecord
5255
module ConnectionAdapters
5356
class MergeAndResolveDefaultUrlConfigTest < ActiveRecord::TestCase
@@ -63,3 +66,147 @@ class MergeAndResolveDefaultUrlConfigTest < ActiveRecord::TestCase
6366
end
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

Comments
 (0)