Skip to content

Commit e5fc096

Browse files
committed
The console --sandbox transaction should not be joinable
Thanks @neerajdotname for noticing this bug.
1 parent 8f9c81b commit e5fc096

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
ActiveRecord::Base.connection.begin_transaction
1+
ActiveRecord::Base.connection.begin_transaction(joinable: false)
2+
23
at_exit do
34
ActiveRecord::Base.connection.rollback_transaction
45
end

railties/test/application/console_test.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ def assert_output(expected, timeout = 0.2)
119119
assert output.include?(expected), "#{expected.inspect} expected, but got:\n\n#{output}"
120120
end
121121

122-
def write_prompt(command)
122+
def write_prompt(command, expected_output = nil)
123123
@master.puts command
124124
assert_output command
125+
assert_output expected_output if expected_output
126+
assert_output "> "
125127
end
126128

127129
def kill(pid)
@@ -143,21 +145,17 @@ def spawn_console
143145
def test_sandbox
144146
pid = spawn_console
145147

146-
write_prompt "Post.count"
147-
assert_output "=> 0"
148-
148+
write_prompt "Post.count", "=> 0"
149149
write_prompt "Post.create"
150-
assert_output "=> "
151-
152-
write_prompt "Post.count"
153-
assert_output "=> 1"
150+
write_prompt "Post.count", "=> 1"
154151

155152
kill pid
156153

157154
pid = spawn_console
158155

159-
write_prompt "Post.count"
160-
assert_output "=> 0"
156+
write_prompt "Post.count", "=> 0"
157+
write_prompt "Post.transaction { Post.create; raise }"
158+
write_prompt "Post.count", "=> 0"
161159
ensure
162160
kill pid
163161
end

0 commit comments

Comments
 (0)