aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-06-02 12:36:36 -0300
committerEmilio Tagua <miloops@gmail.com>2009-06-02 12:36:36 -0300
commitfd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90 (patch)
tree89f6b8eeae81ba9e9f3c43667b234b64a776e649 /railties/lib
parent5255a81b808c2c947d58df979e6436b1fe1d8157 (diff)
parent196f780e30fcece25e4d09c12f9b9f7374ebed29 (diff)
downloadrails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.tar.gz
rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.tar.bz2
rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.zip
Merge commit 'rails/master'
Conflicts: activerecord/lib/active_record.rb
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/commands/server.rb8
-rw-r--r--railties/lib/initializer.rb16
-rw-r--r--railties/lib/rails_generator/generators/components/model_subclass/USAGE13
-rw-r--r--railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb32
-rw-r--r--railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb3
-rw-r--r--railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb8
-rw-r--r--railties/lib/tasks/databases.rake26
7 files changed, 93 insertions, 13 deletions
diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb
index 91ac7752ef..01dd33fa8c 100644
--- a/railties/lib/commands/server.rb
+++ b/railties/lib/commands/server.rb
@@ -22,17 +22,17 @@ options = {
ARGV.clone.options do |opts|
opts.on("-p", "--port=port", Integer,
- "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
+ "Runs Rails on the specified port.", "Default: #{options[:Port]}") { |v| options[:Port] = v }
opts.on("-b", "--binding=ip", String,
- "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
+ "Binds Rails to the specified ip.", "Default: #{options[:Host]}") { |v| options[:Host] = v }
opts.on("-c", "--config=file", String,
"Use custom rackup configuration file") { |v| options[:config] = v }
opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true }
opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
opts.on("-e", "--environment=name", String,
"Specifies the environment to run this server under (test/development/production).",
- "Default: development") { |v| options[:environment] = v }
- opts.on("-P", "--path=/path", String, "Runs Rails app mounted at a specific path.", "Default: /") { |v| options[:path] = v }
+ "Default: #{options[:environment]}") { |v| options[:environment] = v }
+ opts.on("-P", "--path=/path", String, "Runs Rails app mounted at a specific path.", "Default: #{options[:path]}") { |v| options[:path] = v }
opts.separator ""
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 3c0d5940ea..7273cea0c5 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -426,10 +426,14 @@ Run `rake gems:install` to install the missing gems.
# should override this behaviour and set the relevant +default_charset+
# on ActionController::Base.
#
- # For Ruby 1.9, this does nothing. Specify the default encoding in the Ruby
- # shebang line if you don't want UTF-8.
+ # For Ruby 1.9, UTF-8 is the default internal and external encoding.
def initialize_encoding
- $KCODE='u' if RUBY_VERSION < '1.9'
+ if RUBY_VERSION < '1.9'
+ $KCODE='u'
+ else
+ Encoding.default_internal = Encoding::UTF_8
+ Encoding.default_external = Encoding::UTF_8
+ end
end
# This initialization routine does nothing unless <tt>:active_record</tt>
@@ -445,7 +449,8 @@ Run `rake gems:install` to install the missing gems.
def initialize_database_middleware
if configuration.frameworks.include?(:active_record)
- if ActionController::Base.session_store == ActiveRecord::SessionStore
+ if configuration.frameworks.include?(:action_controller) &&
+ ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache
else
@@ -886,7 +891,7 @@ Run `rake gems:install` to install the missing gems.
# Enable threaded mode. Allows concurrent requests to controller actions and
# multiple database connections. Also disables automatic dependency loading
- # after boot, and disables reloading code on every request, as these are
+ # after boot, and disables reloading code on every request, as these are
# fundamentally incompatible with thread safety.
def threadsafe!
self.preload_frameworks = true
@@ -1129,3 +1134,4 @@ class Rails::OrderedOptions < Array #:nodoc:
return false
end
end
+
diff --git a/railties/lib/rails_generator/generators/components/model_subclass/USAGE b/railties/lib/rails_generator/generators/components/model_subclass/USAGE
new file mode 100644
index 0000000000..a4b558a401
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/model_subclass/USAGE
@@ -0,0 +1,13 @@
+Description:
+ Create a model subclass of parent, used for Single Table Inheritance.
+
+ Both subclass and parent name can be either CamelCased or under_scored.
+
+ This generates a model class in app/models and a unit test in test/unit.
+
+Examples:
+ `./script/generate model_subclass admin user`
+
+ creates an Admin model, which will inheritate from User model, test:
+ Model: app/models/admin.rb
+ Test: test/unit/admin_test.rb
diff --git a/railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb b/railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb
new file mode 100644
index 0000000000..e8ac3da2cd
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb
@@ -0,0 +1,32 @@
+class ModelSubclassGenerator < Rails::Generator::NamedBase
+ default_options :skip_unit_test => false
+
+ def manifest
+ record do |m|
+ # Check for class naming collisions.
+ m.class_collisions class_name, "#{class_name}Test"
+
+ # Model and test directories.
+ m.directory File.join('app/models', class_path)
+ m.directory File.join('test/unit', class_path)
+
+ # Model class and unit test
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb"), :assigns => assigns
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"), :assigns => assigns
+
+ end
+ end
+
+ protected
+ def banner
+ "Usage: #{$0} #{spec.name} Subclass Parent"
+ end
+
+ def assigns
+ {:parent_class_name => parent_class_name}
+ end
+
+ def parent_class_name
+ @args.first.try(:camelize) || usage
+ end
+end
diff --git a/railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb b/railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb
new file mode 100644
index 0000000000..d0037b322b
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb
@@ -0,0 +1,3 @@
+class <%= class_name %> < <%= parent_class_name %>
+
+end \ No newline at end of file
diff --git a/railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb
new file mode 100644
index 0000000000..3e0bc29d3a
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class <%= class_name %>Test < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake
index cdab5d8bb0..0e256737f9 100644
--- a/railties/lib/tasks/databases.rake
+++ b/railties/lib/tasks/databases.rake
@@ -56,12 +56,28 @@ namespace :db do
when 'mysql'
@charset = ENV['CHARSET'] || 'utf8'
@collation = ENV['COLLATION'] || 'utf8_general_ci'
+ creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
begin
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
- ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation))
+ ActiveRecord::Base.connection.create_database(config['database'], creation_options)
ActiveRecord::Base.establish_connection(config)
- rescue
- $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation} (if you set the charset manually, make sure you have a matching collation)"
+ rescue Mysql::Error => sqlerr
+ if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR
+ print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
+ root_password = $stdin.gets.strip
+ grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
+ "TO '#{config['username']}'@'localhost' " \
+ "IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;"
+ ActiveRecord::Base.establish_connection(config.merge(
+ 'database' => nil, 'username' => 'root', 'password' => root_password))
+ ActiveRecord::Base.connection.create_database(config['database'], creation_options)
+ ActiveRecord::Base.connection.execute grant_statement
+ ActiveRecord::Base.establish_connection(config)
+ else
+ $stderr.puts sqlerr.error
+ $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}"
+ $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
+ end
end
when 'postgresql'
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
@@ -282,7 +298,9 @@ namespace :db do
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
search_path = abcs[RAILS_ENV]["schema_search_path"]
- search_path = "--schema=#{search_path}" if search_path
+ unless search_path.blank?
+ search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
+ end
`pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
raise "Error dumping database" if $?.exitstatus == 1
when "sqlite", "sqlite3"