Skip to content

Commit 0580694

Browse files
aidanharanAidan Haran
and
Aidan Haran
authored
Load schema before running Rails test (#912)
Co-authored-by: Aidan Haran <aharan@fusioneer.com>
1 parent b1a119c commit 0580694

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/cases/coerced_tests.rb

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,40 @@ def test_errors_when_an_insert_query_is_called_while_preventing_writes_coerced
7878
Subscriber.send(:load_schema!)
7979
original_test_errors_when_an_insert_query_is_called_while_preventing_writes
8080
end
81+
82+
# Fix randomly failing test. The loading of the model's schema was affecting the test.
83+
coerce_tests! :test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_containing_read_command_is_called_while_preventing_writes
84+
def test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_containing_read_command_is_called_while_preventing_writes_coerced
85+
Subscriber.send(:load_schema!)
86+
original_test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_containing_read_command_is_called_while_preventing_writes
87+
end
88+
89+
# Fix randomly failing test. The loading of the model's schema was affecting the test.
90+
coerce_tests! :test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_is_called_while_preventing_writes
91+
def test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_is_called_while_preventing_writes_coerced
92+
Subscriber.send(:load_schema!)
93+
original_test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_is_called_while_preventing_writes
94+
end
8195
end
8296
end
8397

8498
module ActiveRecord
8599
class AdapterPreventWritesLegacyTest < ActiveRecord::TestCase
86-
# We do some read queries. Remove assert_no_queries
100+
# Fix randomly failing test. The loading of the model's schema was affecting the test.
87101
coerce_tests! :test_errors_when_an_insert_query_prefixed_by_a_slash_star_comment_is_called_while_preventing_writes
88102
def test_errors_when_an_insert_query_prefixed_by_a_slash_star_comment_is_called_while_preventing_writes_coerced
89-
@connection_handler.while_preventing_writes do
90-
@connection.transaction do
91-
assert_raises(ActiveRecord::ReadOnlyError) do
92-
@connection.insert("/* some comment */ INSERT INTO subscribers(nick) VALUES ('138853948594')", nil, false)
93-
end
94-
end
95-
end
103+
Subscriber.send(:load_schema!)
104+
original_test_errors_when_an_insert_query_prefixed_by_a_slash_star_comment_is_called_while_preventing_writes
96105
end
97106

107+
# Fix randomly failing test. The loading of the model's schema was affecting the test.
108+
coerce_tests! :test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_is_called_while_preventing_writes
109+
def test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_is_called_while_preventing_writes_coerced
110+
Subscriber.send(:load_schema!)
111+
original_test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_is_called_while_preventing_writes
112+
end
113+
114+
# Fix randomly failing test. The loading of the model's schema was affecting the test.
98115
coerce_tests! :test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_containing_read_command_is_called_while_preventing_writes
99116
def test_errors_when_an_insert_query_prefixed_by_a_double_dash_comment_containing_read_command_is_called_while_preventing_writes_coerced
100117
Subscriber.send(:load_schema!)

0 commit comments

Comments
 (0)