From daa592293b5a10f487cc9000863e052d2a28884f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 22 Sep 2017 10:29:23 +0900 Subject: Use `TOPLEVEL_BINDING` in rails runner command Binding to capture the local scope. This means that if a constant with same name as constant specified by the user exists in local scope, constant defined in local will use. This is different from what the user expects. Therefore, fixed to use top-level binding instead of local scope. Fixes #30644 --- railties/test/application/runner_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties/test/application/runner_test.rb') diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 64c46c4b45..aa5d495c97 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -128,5 +128,17 @@ module ApplicationTests assert_match "production", rails("runner", "puts Rails.env") end end + + def test_can_call_same_name_class_as_defined_in_thor + app_file "app/models/task.rb", <<-MODEL + class Task + def self.count + 42 + end + end + MODEL + + assert_match "42", rails("runner", "puts Task.count") + end end end -- cgit v1.2.3