Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move sandbox to AR and pass the sandbox as a value. This way, other O…

…RMs like Datamapper can also have their own sandboxing in rails console.
  • Loading branch information...
commit 92661b0c501a65b7f2d9ac8fbf9743152b8a031b 1 parent b9bba55
@josevalim josevalim authored
View
3  activerecord/lib/active_record/railtie.rb
@@ -29,7 +29,8 @@ class Railtie < Rails::Railtie
# When loading console, force ActiveRecord::Base to be loaded
# to avoid cross references when loading a constant for the
# first time. Also, make it output to STDERR.
- console do
+ console do |sandbox|
+ require "active_record/railties/console_sandbox" if sandbox
ActiveRecord::Base.logger = Logger.new(STDERR)
end
View
0  railties/lib/rails/console/sandbox.rb → ...ord/lib/active_record/railties/console_sandbox.rb
File renamed without changes
View
3  railties/lib/rails/application.rb
@@ -112,7 +112,7 @@ def load_generators
def load_console(sandbox=false)
initialize_console(sandbox)
- railties.all { |r| r.load_console }
+ railties.all { |r| r.load_console(sandbox) }
super()
self
end
@@ -196,7 +196,6 @@ def initialize_generators
def initialize_console(sandbox=false)
require "rails/console/app"
- require "rails/console/sandbox" if sandbox
require "rails/console/helpers"
end
end
View
4 railties/lib/rails/railtie.rb
@@ -173,8 +173,8 @@ def config
def eager_load!
end
- def load_console
- self.class.console.each(&:call)
+ def load_console(sandbox=false)
+ self.class.console.each { |block| block.call(sandbox) }
end
def load_tasks
View
18 railties/test/application/console_test.rb
@@ -8,9 +8,9 @@ def setup
boot_rails
end
- def load_environment
+ def load_environment(sandbox = false)
require "#{rails_root}/config/environment"
- Rails.application.load_console
+ Rails.application.load_console(sandbox)
end
def test_app_method_should_return_integration_session
@@ -73,6 +73,20 @@ def test_access_to_helpers
helper.truncate('Once upon a time in a world far far away')
end
+ def test_with_sandbox
+ require 'rails/all'
+ value = false
+
+ Class.new(Rails::Railtie) do
+ console do |sandbox|
+ value = sandbox
+ end
+ end
+
+ load_environment(true)
+ assert value
+ end
+
def test_active_record_does_not_panic_when_referencing_an_observed_constant
add_to_config "config.active_record.observers = :user_observer"
Please sign in to comment.
Something went wrong with that request. Please try again.