From 76d5428c3360ae837107ccedb418fc7b0d2aa578 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Wed, 3 Feb 2010 15:42:53 +1100 Subject: [PATCH 1/5] Updating index.html to remove script/generate and making railties tests pass again --- .../rails/app/templates/public/index.html | 2 +- .../test/generators/app_generator_test.rb | 28 +++---------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/railties/lib/generators/rails/app/templates/public/index.html b/railties/lib/generators/rails/app/templates/public/index.html index b153ae392f..ef916f9c5a 100644 --- a/railties/lib/generators/rails/app/templates/public/index.html +++ b/railties/lib/generators/rails/app/templates/public/index.html @@ -255,7 +255,7 @@
  1. -

    Use script/generate to create your models and controllers

    +

    Use rails generate to create your models and controllers

    To see all available options, run it without parameters.

  2. diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 95a33c50f8..93ef67818d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -35,7 +35,7 @@ def test_application_skeleton_is_created public/images public/javascripts public/stylesheets - script/performance + script/rails test/fixtures test/functional test/integration @@ -98,34 +98,14 @@ def test_prototype_and_test_unit_are_skipped_if_required assert_no_file "test" end - def test_shebang_is_added_to_files + def test_shebang_is_added_to_rails_file run_generator [destination_root, "--ruby", "foo/bar/baz"] - - %w( - about - console - dbconsole - destroy - generate - plugin - runner - server - ).each { |path| assert_file "script/#{path}", /#!foo\/bar\/baz/ } + assert_file "script/rails", /#!foo\/bar\/baz/ end def test_shebang_when_is_the_same_as_default_use_env run_generator [destination_root, "--ruby", Thor::Util.ruby_command] - - %w( - about - console - dbconsole - destroy - generate - plugin - runner - server - ).each { |path| assert_file "script/#{path}", /#!\/usr\/bin\/env/ } + assert_file "script/rails", /#!\/usr\/bin\/env/ end def test_template_from_dir_pwd From fbdef7aafe753d2375b16c5dcf70a463996b929f Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Wed, 3 Feb 2010 16:39:04 +1100 Subject: [PATCH 2/5] Made rake db:create also create the test database if you are in development mode --- activerecord/lib/active_record/railties/databases.rake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 2ef8676f39..8ca7c394fd 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -26,8 +26,12 @@ namespace :db do end end - desc 'Create the database defined in config/database.yml for the current Rails.env' + desc 'Create the database defined in config/database.yml for the current Rails.env - also makes test database if in development mode' task :create => :load_config do + # Make the test database at the same time as the development one + if Rails.env == 'development' + create_database(ActiveRecord::Base.configurations['test']) + end create_database(ActiveRecord::Base.configurations[Rails.env]) end From 9d653908059523bc2e3e1e646c0bcd4ebe5a80d7 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Wed, 3 Feb 2010 18:06:38 +1100 Subject: [PATCH 3/5] Added encoding qery support for SQLite3 to make rake db:charset work on all databases shipping with Rails 3 --- .../connection_adapters/sqlite3_adapter.rb | 11 +++++++++++ .../lib/active_record/railties/databases.rake | 3 +++ 2 files changed, 14 insertions(+) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index d933bc924d..f295af16f0 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -24,6 +24,17 @@ def self.sqlite3_connection(config) # :nodoc: module ConnectionAdapters #:nodoc: class SQLite3Adapter < SQLiteAdapter # :nodoc: + + # Returns the current database encoding format as a string, eg: 'UTF-8' + def encoding + if @connection.respond_to?(:encoding) + @connection.encoding[0]['encoding'] + else + encoding = @connection.send(:get_query_pragma, 'encoding') + encoding[0]['encoding'] + end + end + end end end diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 8ca7c394fd..4343bef3d4 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -200,6 +200,9 @@ namespace :db do when 'postgresql' ActiveRecord::Base.establish_connection(config) puts ActiveRecord::Base.connection.encoding + when 'sqlite3' + ActiveRecord::Base.establish_connection(config) + puts ActiveRecord::Base.connection.encoding else puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' end From 38d13f9597c4e92643e3b6513e85a7a8475d5b1b Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Wed, 3 Feb 2010 18:31:57 +1100 Subject: [PATCH 4/5] Deprecated freeze rake tasks and cleaned up annotations.rake --- railties/lib/rails/tasks/annotations.rake | 2 +- railties/lib/rails/tasks/framework.rake | 75 +++-------------------- 2 files changed, 8 insertions(+), 69 deletions(-) diff --git a/railties/lib/rails/tasks/annotations.rake b/railties/lib/rails/tasks/annotations.rake index 79973b3145..10a9311b2d 100644 --- a/railties/lib/rails/tasks/annotations.rake +++ b/railties/lib/rails/tasks/annotations.rake @@ -13,7 +13,7 @@ namespace :notes do end end - desc "Enumerate a custom annotation, specify with ANNOTATION=WTFHAX" + desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM" task :custom do SourceAnnotationExtractor.enumerate ENV['ANNOTATION'] end diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 5d7c094d8b..65d3c48f2d 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -1,80 +1,19 @@ namespace :rails do namespace :freeze do - desc "Lock this application to the current gems (by unpacking them into vendor/rails)" + desc "The rails:freeze:gems is deprecated, please use bundle install instead" task :gems do - deps = %w(actionpack activerecord actionmailer activesupport activeresource) - require 'rubygems' - require 'rubygems/gem_runner' - - rails = (version = ENV['VERSION']) ? - Gem.cache.find_name('rails', "= #{version}").first : - Gem.cache.find_name('rails').sort_by { |g| g.version }.last - - version ||= rails.version - - unless rails - puts "No rails gem #{version} is installed. Do 'gem list rails' to see what you have available." - exit - end - - puts "Freezing to the gems for Rails #{rails.version}" - rm_rf "vendor/rails" - mkdir_p "vendor/rails" - - begin - chdir("vendor/rails") do - rails.dependencies.select { |g| deps.include? g.name }.each do |g| - Gem::GemRunner.new.run(["unpack", g.name, "--version", g.version_requirements.to_s]) - mv(Dir.glob("#{g.name}*").first, g.name) - end - - Gem::GemRunner.new.run(["unpack", "rails", "--version", "=#{version}"]) - FileUtils.mv(Dir.glob("rails*").first, "railties") - end - rescue Exception - rm_rf "vendor/rails" - raise - end + puts "The rails:freeze:gems is deprecated, please use bundle install instead" end - desc 'Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0' + desc 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install' task :edge do - require 'open-uri' - version = ENV["RELEASE"] || "edge" - target = "rails_#{version}.zip" - commits = "http://github.com/api/v1/yaml/rails/rails/commits/master" - url = "http://dev.rubyonrails.org/archives/#{target}" - - chdir 'vendor' do - latest_revision = YAML.load(open(commits))["commits"].first["id"] - - puts "Downloading Rails from #{url}" - File.open('rails.zip', 'wb') do |dst| - open url do |src| - while chunk = src.read(4096) - dst << chunk - end - end - end - - puts 'Unpacking Rails' - rm_rf 'rails' - `unzip rails.zip` - %w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner| - rm_f goner - end - - touch "rails/REVISION_#{latest_revision}" - end - - puts 'Updating current scripts, javascripts, and configuration settings' - Rake::Task['rails:update'].invoke + puts 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install' end end - desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems" + desc 'The unfreeze command has been deprecated, please use bundler commands instead' task :unfreeze do - rm_rf "vendor/rails" + puts 'The unfreeze command has been deprecated, please use bundler commands instead' end desc "Update both configs, scripts and public/javascripts from Rails" @@ -112,7 +51,7 @@ namespace :rails do invoke_from_app_generator :create_prototype_files end - desc "Add new scripts to the application script/ directory" + desc "Adds new scripts to the application script/ directory" task :scripts do invoke_from_app_generator :create_script_files end From f390eade5fd70615ba2ee8e089821bcf2d5f7b17 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Wed, 3 Feb 2010 19:50:51 +1100 Subject: [PATCH 5/5] Adding 'db' as a shortcut for dbconsole to the rails command --- railties/lib/rails/commands/rails.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/railties/lib/rails/commands/rails.rb b/railties/lib/rails/commands/rails.rb index 5f34876f1d..9597e2e7e6 100644 --- a/railties/lib/rails/commands/rails.rb +++ b/railties/lib/rails/commands/rails.rb @@ -6,13 +6,14 @@ usage: rails COMMAND [ARGS] The most common rails commands are: - generate Generate new code (short-cut alias: "g") - console Start the Rails console (short-cut alias: "c") - server Start the Rails server (short-cut alias: "s") + generate Generate new code (short-cut alias: "g") + console Start the Rails console (short-cut alias: "c") + server Start the Rails server (short-cut alias: "s") + dbconsole Start a console for the database specified in config/database.yml + (short-cut alias: "db") In addition to those, there are: application Generate the Rails application code - dbconsole Start a console for the database specified in config/database.yml destroy Undo code generated with "generate" benchmarker See how fast a piece of code runs profiler Get profile information from a piece of code @@ -35,13 +36,13 @@ require 'rails/commands/server' Dir.chdir(ROOT_PATH) Rails::Server.start - -when 'application' - require 'rails/commands/application' -when 'dbconsole' +when 'db', 'dbconsole' require 'rails/commands/dbconsole' require APP_PATH Rails::DBConsole.start(Rails::Application) + +when 'application' + require 'rails/commands/application' when 'destroy' require ENV_PATH require 'rails/commands/destroy'