diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-04 16:39:01 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-04 16:47:35 +0200 |
commit | 92661b0c501a65b7f2d9ac8fbf9743152b8a031b (patch) | |
tree | b49e621c5db5b3ba72a1952577c863193b916e16 /railties | |
parent | b9bba555caa95389e97bd7d32472ddc1e429d7c2 (diff) | |
download | rails-92661b0c501a65b7f2d9ac8fbf9743152b8a031b.tar.gz rails-92661b0c501a65b7f2d9ac8fbf9743152b8a031b.tar.bz2 rails-92661b0c501a65b7f2d9ac8fbf9743152b8a031b.zip |
Move sandbox to AR and pass the sandbox as a value. This way, other ORMs like Datamapper can also have their own sandboxing in rails console.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/console/sandbox.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 4 | ||||
-rw-r--r-- | railties/test/application/console_test.rb | 18 |
4 files changed, 19 insertions, 12 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 4e82761e5d..dd01bbab1d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -112,7 +112,7 @@ module Rails 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 @@ module Rails def initialize_console(sandbox=false) require "rails/console/app" - require "rails/console/sandbox" if sandbox require "rails/console/helpers" end end diff --git a/railties/lib/rails/console/sandbox.rb b/railties/lib/rails/console/sandbox.rb deleted file mode 100644 index 65a3d68619..0000000000 --- a/railties/lib/rails/console/sandbox.rb +++ /dev/null @@ -1,6 +0,0 @@ -ActiveRecord::Base.connection.increment_open_transactions -ActiveRecord::Base.connection.begin_db_transaction -at_exit do - ActiveRecord::Base.connection.rollback_db_transaction - ActiveRecord::Base.connection.decrement_open_transactions -end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 7fca565124..b183eb8ddd 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -173,8 +173,8 @@ module Rails 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 diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 793e73556c..5ae6323345 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -8,9 +8,9 @@ class ConsoleTest < Test::Unit::TestCase 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 @@ class ConsoleTest < Test::Unit::TestCase 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" |