diff options
-rw-r--r-- | actionpack/test/controller/base_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/benchmarkable.rb | 2 | ||||
-rw-r--r-- | railties/guides/source/action_controller_overview.textile | 9 | ||||
-rw-r--r-- | railties/guides/source/contributing_to_ruby_on_rails.textile | 2 | ||||
-rw-r--r-- | railties/guides/source/getting_started.textile | 8 | ||||
-rw-r--r-- | railties/test/application/initializers/active_record_test.rb | 62 |
9 files changed, 80 insertions, 15 deletions
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 145ef12b94..affa9a6add 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -68,7 +68,7 @@ class DefaultUrlOptionsController < ActionController::Base render :inline => "<%= #{params[:route]} %>" end - def default_url_options(options = nil) + def default_url_options { :host => 'www.override.com', :action => 'new', :locale => 'en' } end end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index bc45fabf34..734b6f3aef 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -548,7 +548,7 @@ class UrlHelperControllerTest < ActionController::TestCase def test_named_route_should_show_host_and_path_using_controller_default_url_options class << @controller - def default_url_options(options = nil) + def default_url_options {:host => 'testtwo.host'} end end diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 96dc258288..13b7c6e214 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -72,9 +72,13 @@ module ActiveRecord # and then establishes the connection. initializer "active_record.initialize_database" do |app| ActiveSupport.on_load(:active_record) do + db_connection_type = "DATABASE_URL" unless ENV['DATABASE_URL'] + db_connection_type = "database.yml" self.configurations = app.config.database_configuration end + Rails.logger.info "Connecting to database specified by #{db_connection_type}" + establish_connection end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 300a3636e3..f6497d9bad 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1992,9 +1992,7 @@ class BasicsTest < ActiveRecord::TestCase original_logger = ActiveRecord::Base.logger log = StringIO.new ActiveRecord::Base.logger = Logger.new(log) - assert_deprecated do - ActiveRecord::Base.benchmark("Logging", :level => :debug, :silence => true) { ActiveRecord::Base.logger.debug "Loud" } - end + ActiveRecord::Base.benchmark("Logging", :level => :debug, :silence => true) { ActiveRecord::Base.logger.debug "Loud" } ActiveRecord::Base.benchmark("Logging", :level => :debug, :silence => false) { ActiveRecord::Base.logger.debug "Quiet" } assert_no_match(/Loud/, log.string) assert_match(/Quiet/, log.string) diff --git a/activesupport/lib/active_support/benchmarkable.rb b/activesupport/lib/active_support/benchmarkable.rb index cc94041a1d..f149a7f0ed 100644 --- a/activesupport/lib/active_support/benchmarkable.rb +++ b/activesupport/lib/active_support/benchmarkable.rb @@ -35,7 +35,7 @@ module ActiveSupport options[:level] ||= :info result = nil - ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield } + ms = Benchmark.ms { result = options[:silence] ? silence { yield } : yield } logger.send(options[:level], '%s (%.1fms)' % [ message, ms ]) result else diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index bc85f07ecc..baa83a0f9c 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -148,18 +148,19 @@ In this case, when a user opens the URL +/clients/active+, +params[:status]+ wil h4. +default_url_options+ -You can set global default parameters that will be used when generating URLs with +default_url_options+. To do this, define a method with that name in your controller: +You can set global default parameters for URL generation by defining a method called +default_url_options+ in your controller. Such a method must return a hash with the desired defaults, whose keys must be symbols: <ruby> class ApplicationController < ActionController::Base - # The options parameter is the hash passed in to 'url_for' - def default_url_options(options) + def default_url_options {:locale => I18n.locale} end end </ruby> -These options will be used as a starting-point when generating URLs, so it's possible they'll be overridden by +url_for+. Because this method is defined in the controller, you can define it on +ApplicationController+ so it would be used for all URL generation, or you could define it on only one controller for all URLs generated there. +These options will be used as a starting point when generating URLs, so it's possible they'll be overridden by the options passed in +url_for+ calls. + +If you define +default_url_options+ in +ApplicationController+, as in the example above, it would be used for all URL generation. The method can also be defined in one specific controller, in which case it only affects URLs generated there. h3. Session diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index dadacb9b36..c54c5be63a 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -42,7 +42,7 @@ h4. Install git Ruby on Rails uses git for source code control. The "git homepage":http://git-scm.com/ has installation instructions. There are a variety of resources on the net that will help you get familiar with git: -* "Everyday Git":http://www.kernel.org/pub/software/scm/git/docs/everyday.html will teach you just enough about git to get by. +* "Everyday Git":http://schacon.github.com/git/everyday.html will teach you just enough about git to get by. * The "PeepCode screencast":https://peepcode.com/products/git on git ($9) is easier to follow. * "GitHub":http://help.github.com offers links to a variety of git resources. * "Pro Git":http://progit.org/book/ is an entire book about git with a Creative Commons license. diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8f2fa47c8b..01a3a1977a 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -10,7 +10,7 @@ you should be familiar with: endprologue. -WARNING. This Guide is based on Rails 3.1. Some of the code shown here will not +WARNING. This Guide is based on Rails 3.2. Some of the code shown here will not work in earlier versions of Rails. h3. Guide Assumptions @@ -23,9 +23,9 @@ prerequisites installed: * The "Ruby":http://www.ruby-lang.org/en/downloads language version 1.8.7 or higher TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails -3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 +3.0 and above. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults -on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth +on Rails 3.0 and above, so if you want to use Rails 3.0 or above with 1.9.x jump on 1.9.2 for smooth sailing. * The "RubyGems":http://rubyforge.org/frs/?group_id=126 packaging system @@ -248,7 +248,7 @@ the following: $ rails --version </shell> -If it says something like "Rails 3.1.3" you are ready to continue. +If it says something like "Rails 3.2.3" you are ready to continue. h4. Creating the Blog Application diff --git a/railties/test/application/initializers/active_record_test.rb b/railties/test/application/initializers/active_record_test.rb new file mode 100644 index 0000000000..edf78a8a0a --- /dev/null +++ b/railties/test/application/initializers/active_record_test.rb @@ -0,0 +1,62 @@ +require "isolation/abstract_unit" +require "rack/test" + +module ApplicationTests + class ActiveRecordTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + @database_url = ENV['DATABASE_URL'] + ENV.delete('DATABASE_URL') + build_app + boot_rails + end + + def teardown + teardown_app + ENV['DATABASE_URL'] = @database_url + end + + test "blows up when no DATABASE_URL env var or database.yml" do + FileUtils.rm_rf("#{app_path}/config/database.yml") + boot_rails + simple_controller + + get '/foo' + assert last_response.body.include?("We're sorry, but something went wrong (500)") + end + + test "uses DATABASE_URL env var when config/database.yml doesn't exist" do + database_path = "/db/foo.sqlite3" + FileUtils.rm_rf("#{app_path}/config/database.yml") + ENV['DATABASE_URL'] = "sqlite3://#{database_path}" + simple_controller + + get '/foo' + assert_equal 'foo', last_response.body + + # clean up + FileUtils.rm("#{app_path}/#{database_path}") + end + + test "DATABASE_URL env var takes precedence over config/database.yml" do + database_path = "/db/foo.sqlite3" + ENV['DATABASE_URL'] = "sqlite3://#{database_path}" + simple_controller + + get '/foo' + assert File.read("#{app_path}/log/production.log").include?("DATABASE_URL") + + # clean up + FileUtils.rm("#{app_path}/#{database_path}") + end + + test "logs the use of config/database.yml" do + simple_controller + + get '/foo' + assert File.read("#{app_path}/log/production.log").include?("database.yml") + end + end +end |