rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (76) hide show
  1. data/CHANGELOG +152 -10
  2. data/README +30 -5
  3. data/Rakefile +18 -13
  4. data/bin/rails +1 -11
  5. data/{lib/rails_info.rb → builtin/rails_info/rails/info.rb} +25 -8
  6. data/builtin/{controllers/rails_info_controller.rb → rails_info/rails/info_controller.rb} +2 -2
  7. data/configs/databases/mysql.yml +47 -0
  8. data/configs/databases/oracle.yml +30 -0
  9. data/configs/databases/postgresql.yml +44 -0
  10. data/configs/databases/sqlite2.yml +16 -0
  11. data/configs/databases/sqlite3.yml +16 -0
  12. data/configs/lighttpd.conf +11 -5
  13. data/configs/routes.rb +5 -2
  14. data/environments/development.rb +3 -2
  15. data/environments/environment.rb +5 -8
  16. data/environments/production.rb +1 -2
  17. data/environments/test.rb +1 -1
  18. data/fresh_rakefile +2 -2
  19. data/html/500.html +1 -1
  20. data/html/index.html +3 -3
  21. data/html/javascripts/application.js +2 -0
  22. data/html/javascripts/controls.js +95 -30
  23. data/html/javascripts/dragdrop.js +161 -21
  24. data/html/javascripts/effects.js +310 -211
  25. data/html/javascripts/prototype.js +228 -28
  26. data/lib/code_statistics.rb +1 -1
  27. data/lib/commands/console.rb +3 -1
  28. data/lib/commands/plugin.rb +113 -70
  29. data/lib/commands/process/reaper.rb +1 -1
  30. data/lib/commands/process/spawner.rb +33 -4
  31. data/lib/commands/runner.rb +1 -1
  32. data/lib/commands/server.rb +3 -1
  33. data/lib/commands/servers/lighttpd.rb +41 -9
  34. data/lib/console_app.rb +27 -0
  35. data/lib/console_with_helpers.rb +23 -0
  36. data/lib/dispatcher.rb +8 -8
  37. data/lib/fcgi_handler.rb +22 -4
  38. data/lib/initializer.rb +107 -38
  39. data/lib/rails_generator/commands.rb +17 -7
  40. data/lib/rails_generator/generators/applications/app/app_generator.rb +30 -18
  41. data/lib/rails_generator/generators/components/integration_test/USAGE +14 -0
  42. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
  43. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
  44. data/lib/rails_generator/generators/components/mailer/USAGE +1 -1
  45. data/lib/rails_generator/generators/components/migration/USAGE +1 -1
  46. data/lib/rails_generator/generators/components/model/USAGE +3 -1
  47. data/lib/rails_generator/generators/components/model/model_generator.rb +16 -0
  48. data/lib/rails_generator/generators/components/model/templates/migration.rb +11 -0
  49. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -1
  50. data/lib/rails_generator/generators/components/plugin/USAGE +3 -1
  51. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
  52. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +1 -1
  53. data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
  54. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +1 -1
  55. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +4 -0
  56. data/lib/rails_generator/generators/components/scaffold/templates/style.css +4 -4
  57. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +1 -1
  58. data/lib/rails_generator/generators/components/session_migration/USAGE +1 -1
  59. data/lib/rails_generator/options.rb +2 -2
  60. data/lib/rails_version.rb +1 -1
  61. data/lib/ruby_version_check.rb +17 -0
  62. data/lib/tasks/databases.rake +141 -139
  63. data/lib/tasks/documentation.rake +73 -68
  64. data/lib/tasks/framework.rake +86 -58
  65. data/lib/tasks/log.rake +9 -0
  66. data/lib/tasks/misc.rake +2 -17
  67. data/lib/tasks/pre_namespace_aliases.rake +46 -0
  68. data/lib/tasks/statistics.rake +9 -8
  69. data/lib/tasks/testing.rake +81 -29
  70. data/lib/tasks/tmp.rake +30 -0
  71. data/lib/test_help.rb +1 -0
  72. data/lib/webrick_server.rb +6 -8
  73. metadata +284 -271
  74. data/bin/process/spinner +0 -3
  75. data/configs/database.yml +0 -85
  76. data/lib/tasks/javascripts.rake +0 -6
@@ -61,7 +61,7 @@ module Rails
61
61
  end
62
62
 
63
63
  def existing_migrations(file_name)
64
- Dir.glob("#{@migration_directory}/[0-9]*_#{file_name}.rb")
64
+ Dir.glob("#{@migration_directory}/[0-9]*_*.rb").grep(/[0-9]+_#{file_name}.rb$/)
65
65
  end
66
66
 
67
67
  def migration_exists?(file_name)
@@ -163,11 +163,13 @@ module Rails
163
163
 
164
164
  # Copy a file from source to destination with collision checking.
165
165
  #
166
- # The file_options hash accepts :chmod and :shebang options.
166
+ # The file_options hash accepts :chmod and :shebang and :collision options.
167
167
  # :chmod sets the permissions of the destination file:
168
168
  # file 'config/empty.log', 'log/test.log', :chmod => 0664
169
169
  # :shebang sets the #!/usr/bin/ruby line for scripts
170
170
  # file 'bin/generate.rb', 'script/generate', :chmod => 0755, :shebang => '/usr/bin/env ruby'
171
+ # :collision sets the collision option only for the destination file:
172
+ # file 'settings/server.yml', 'config/server.yml', :collision => :skip
171
173
  #
172
174
  # Collisions are handled by checking whether the destination file
173
175
  # exists and either skipping the file, forcing overwrite, or asking
@@ -188,7 +190,7 @@ module Rails
188
190
 
189
191
  # Make a choice whether to overwrite the file. :force and
190
192
  # :skip already have their mind made up, but give :ask a shot.
191
- choice = case options[:collision].to_sym #|| :ask
193
+ choice = case (file_options[:collision] || options[:collision]).to_sym #|| :ask
192
194
  when :ask then force_file_collision?(relative_destination)
193
195
  when :force then :force
194
196
  when :skip then :skip
@@ -309,8 +311,9 @@ module Rails
309
311
  # When creating a migration, it knows to find the first available file in db/migrate and use the migration.rb template.
310
312
  def migration_template(relative_source, relative_destination, template_options = {})
311
313
  migration_directory relative_destination
312
- raise "Another migration is already named #{file_name}: #{existing_migrations(file_name).first}" if migration_exists?(file_name)
313
- template(relative_source, "#{relative_destination}/#{next_migration_string}_#{file_name}.rb", template_options)
314
+ migration_file_name = template_options[:migration_file_name] || file_name
315
+ raise "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}" if migration_exists?(migration_file_name)
316
+ template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
314
317
  end
315
318
 
316
319
  private
@@ -423,8 +426,15 @@ end_message
423
426
  # When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}".
424
427
  def migration_template(relative_source, relative_destination, template_options = {})
425
428
  migration_directory relative_destination
426
- raise "There is no migration named #{file_name}" unless migration_exists?(file_name)
427
- existing_migrations(file_name).each do |file_path|
429
+
430
+ migration_file_name = template_options[:migration_file_name] || file_name
431
+ unless migration_exists?(migration_file_name)
432
+ puts "There is no migration named #{migration_file_name}"
433
+ return
434
+ end
435
+
436
+
437
+ existing_migrations(migration_file_name).each do |file_path|
428
438
  file(relative_source, file_path, template_options)
429
439
  end
430
440
  end
@@ -4,15 +4,16 @@ class AppGenerator < Rails::Generator::Base
4
4
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
5
5
  Config::CONFIG['ruby_install_name'])
6
6
 
7
- default_options :gem => true, :shebang => DEFAULT_SHEBANG
8
- mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
7
+ DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 )
8
+
9
+ default_options :db => "mysql", :shebang => DEFAULT_SHEBANG
10
+ mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
9
11
 
10
12
  def initialize(runtime_args, runtime_options = {})
11
13
  super
12
14
  usage if args.empty?
15
+ usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
13
16
  @destination_root = args.shift
14
- @socket = MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) }
15
- @socket = '/path/to/your/mysql.sock' if @socket.blank?
16
17
  end
17
18
 
18
19
  def manifest
@@ -34,9 +35,9 @@ class AppGenerator < Rails::Generator::Base
34
35
  m.template "helpers/test_helper.rb", "test/test_helper.rb"
35
36
 
36
37
  # database.yml and .htaccess
37
- m.template "configs/database.yml", "config/database.yml", :assigns => {
38
+ m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
38
39
  :app_name => File.basename(File.expand_path(@destination_root)),
39
- :socket => @socket
40
+ :socket => options[:db] == "mysql" ? mysql_socket_location : nil
40
41
  }
41
42
  m.template "configs/routes.rb", "config/routes.rb"
42
43
  m.template "configs/apache.conf", "public/.htaccess"
@@ -49,7 +50,7 @@ class AppGenerator < Rails::Generator::Base
49
50
  m.file "environments/test.rb", "config/environments/test.rb"
50
51
 
51
52
  # Scripts
52
- %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server plugin ).each do |file|
53
+ %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner runner server plugin ).each do |file|
53
54
  m.file "bin/#{file}", "script/#{file}", script_options
54
55
  end
55
56
 
@@ -63,15 +64,16 @@ class AppGenerator < Rails::Generator::Base
63
64
  m.template "html/#{file}.html", "public/#{file}.html"
64
65
  end
65
66
 
66
- m.template "html/favicon.ico", "public/favicon.ico"
67
- m.template "html/robots.txt", "public/robots.txt"
67
+ m.template "html/favicon.ico", "public/favicon.ico"
68
+ m.template "html/robots.txt", "public/robots.txt"
68
69
  m.file "html/images/rails.png", "public/images/rails.png"
69
70
 
70
71
  # Javascripts
71
- m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js"
72
- m.file "html/javascripts/effects.js", "public/javascripts/effects.js"
73
- m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js"
74
- m.file "html/javascripts/controls.js", "public/javascripts/controls.js"
72
+ m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js"
73
+ m.file "html/javascripts/effects.js", "public/javascripts/effects.js"
74
+ m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js"
75
+ m.file "html/javascripts/controls.js", "public/javascripts/controls.js"
76
+ m.file "html/javascripts/application.js", "public/javascripts/application.js"
75
77
 
76
78
  # Docs
77
79
  m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
@@ -91,11 +93,17 @@ class AppGenerator < Rails::Generator::Base
91
93
  def add_options!(opt)
92
94
  opt.separator ''
93
95
  opt.separator 'Options:'
94
- opt.on("--ruby [#{DEFAULT_SHEBANG}]",
95
- "Path to the Ruby binary of your choice.") { |options[:shebang]| }
96
- opt.on("--without-gems",
97
- "Don't use the Rails gems for your app.",
98
- "WARNING: see note below.") { |options[:gem]| }
96
+ opt.on("-r", "--ruby", String,
97
+ "Path to the Ruby binary of your choice.",
98
+ "Default: #{DEFAULT_SHEBANG}") { |options[:shebang]| }
99
+
100
+ opt.on("-d", "--database=name", String,
101
+ "Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).",
102
+ "Default: mysql") { |options[:db]| }
103
+ end
104
+
105
+ def mysql_socket_location
106
+ RUBY_PLATFORM =~ /mswin32/ ? MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) } : nil
99
107
  end
100
108
 
101
109
 
@@ -120,11 +128,15 @@ class AppGenerator < Rails::Generator::Base
120
128
  script/process
121
129
  test/fixtures
122
130
  test/functional
131
+ test/integration
123
132
  test/mocks/development
124
133
  test/mocks/test
125
134
  test/unit
126
135
  vendor
127
136
  vendor/plugins
137
+ tmp/sessions
138
+ tmp/sockets
139
+ tmp/cache
128
140
  )
129
141
 
130
142
  MYSQL_SOCKET_LOCATIONS = [
@@ -0,0 +1,14 @@
1
+ Description:
2
+ The model generator creates a stub for a new integration test.
3
+
4
+ The generator takes an integration test name as its argument. The test
5
+ name may be given in CamelCase or under_score and should not be suffixed
6
+ with 'Test'.
7
+
8
+ The generator creates an integration test class in test/integration.
9
+
10
+ Example:
11
+ ./script/generate integration_test GeneralStories
12
+
13
+ This will create a GeneralStores integration test:
14
+ test/integration/general_stories_test.rb
@@ -0,0 +1,16 @@
1
+ class IntegrationTestGenerator < Rails::Generator::NamedBase
2
+ default_options :skip_migration => false
3
+
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions class_path, class_name, "#{class_name}Test"
8
+
9
+ # integration test directory
10
+ m.directory File.join('test/integration', class_path)
11
+
12
+ # integration test stub
13
+ m.template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ require "#{File.dirname(__FILE__)}<%= '/..' * class_nesting_depth %>/../test_helper"
2
+
3
+ class <%= class_name %>Test < ActionController::IntegrationTest
4
+ # fixtures :your, :models
5
+
6
+ # Replace this with your real tests.
7
+ def test_truth
8
+ assert true
9
+ end
10
+ end
@@ -13,6 +13,6 @@ Example:
13
13
  This will create a Notifications mailer class:
14
14
  Mailer: app/models/notifications.rb
15
15
  Views: app/views/notifications/signup.rhtml [...]
16
- Test: test/unit/credit_card_controller_test.rb
16
+ Test: test/unit/test/unit/notifications_test.rb
17
17
  Fixtures: test/fixtures/notifications/signup [...]
18
18
 
@@ -11,4 +11,4 @@ Example:
11
11
  ./script/generate migration AddSslFlag
12
12
 
13
13
  With 4 existing migrations, this will create an AddSslFlag migration in the
14
- file db/migrate/5_add_ssl_flag.rb
14
+ file db/migrate/005_add_ssl_flag.rb
@@ -5,7 +5,8 @@ Description:
5
5
  given in CamelCase or under_score and should not be suffixed with 'Model'.
6
6
 
7
7
  The generator creates a model class in app/models, a test suite in
8
- test/unit, and test fixtures in test/fixtures/singular_name.yml.
8
+ test/unit, test fixtures in test/fixtures/singular_name.yml, and a migration
9
+ in db/migrate.
9
10
 
10
11
  Example:
11
12
  ./script/generate model Account
@@ -14,4 +15,5 @@ Example:
14
15
  Model: app/models/account.rb
15
16
  Test: test/unit/account_test.rb
16
17
  Fixtures: test/fixtures/accounts.yml
18
+ Migration: db/migrate/XXX_add_accounts.rb
17
19
 
@@ -1,4 +1,6 @@
1
1
  class ModelGenerator < Rails::Generator::NamedBase
2
+ default_options :skip_migration => false
3
+
2
4
  def manifest
3
5
  record do |m|
4
6
  # Check for class naming collisions.
@@ -13,6 +15,20 @@ class ModelGenerator < Rails::Generator::NamedBase
13
15
  m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
14
16
  m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
15
17
  m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
18
+
19
+ unless options[:skip_migration]
20
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
21
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
22
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
23
+ end
16
24
  end
17
25
  end
26
+
27
+ protected
28
+ def add_options!(opt)
29
+ opt.separator ''
30
+ opt.separator 'Options:'
31
+ opt.on("--skip-migration",
32
+ "Don't generate a migration file for this model") { |options[:skip_migration]| }
33
+ end
18
34
  end
@@ -0,0 +1,11 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ # t.column :name, :string
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :<%= table_name %>
10
+ end
11
+ end
@@ -5,6 +5,6 @@ class <%= class_name %>Test < Test::Unit::TestCase
5
5
 
6
6
  # Replace this with your real tests.
7
7
  def test_truth
8
- assert_kind_of <%= class_name %>, <%= table_name %>(:first)
8
+ assert true
9
9
  end
10
10
  end
@@ -16,6 +16,7 @@ Example:
16
16
  This will create:
17
17
  vendor/plugins/browser_filters/README
18
18
  vendor/plugins/browser_filters/init.rb
19
+ vendor/plugins/browser_filters/install.rb
19
20
  vendor/plugins/browser_filters/lib/browser_filters.rb
20
21
  vendor/plugins/browser_filters/test/browser_filters_test.rb
21
22
  vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake
@@ -25,9 +26,10 @@ Example:
25
26
  This will create:
26
27
  vendor/plugins/browser_filters/README
27
28
  vendor/plugins/browser_filters/init.rb
29
+ vendor/plugins/browser_filters/install.rb
28
30
  vendor/plugins/browser_filters/lib/browser_filters.rb
29
31
  vendor/plugins/browser_filters/test/browser_filters_test.rb
30
32
  vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake
31
33
  vendor/plugins/browser_filters/generators/browser_filters/browser_filters_generator.rb
32
34
  vendor/plugins/browser_filters/generators/browser_filters/USAGE
33
- vendor/plugins/browser_filters/generators/browser_filters/templates/
35
+ vendor/plugins/browser_filters/generators/browser_filters/templates/
@@ -16,6 +16,7 @@ class PluginGenerator < Rails::Generator::NamedBase
16
16
  m.template 'README', "#{plugin_path}/README"
17
17
  m.template 'Rakefile', "#{plugin_path}/Rakefile"
18
18
  m.template 'init.rb', "#{plugin_path}/init.rb"
19
+ m.template 'install.rb', "#{plugin_path}/install.rb"
19
20
  m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb"
20
21
  m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake"
21
22
  m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb"
@@ -16,7 +16,7 @@ desc 'Generate documentation for the <%= file_name %> plugin.'
16
16
  Rake::RDocTask.new(:rdoc) do |rdoc|
17
17
  rdoc.rdoc_dir = 'rdoc'
18
18
  rdoc.title = '<%= class_name %>'
19
- rdoc.options << '--line-numbers --inline-source'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
20
  rdoc.rdoc_files.include('README')
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
@@ -73,7 +73,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
73
73
  m.directory File.join('test/functional', controller_class_path)
74
74
 
75
75
  # Depend on model generator but skip if the model exists.
76
- m.dependency 'model', [singular_name], :collision => :skip
76
+ m.dependency 'model', [singular_name], :collision => :skip, :skip_migration => true
77
77
 
78
78
  # Scaffolded forms.
79
79
  m.complex_template "form.rhtml",
@@ -11,6 +11,10 @@ class <%= controller_class_name %>Controller < ApplicationController
11
11
  end
12
12
 
13
13
  <% end -%>
14
+ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15
+ verify :method => :post, :only => [ :destroy<%= suffix %>, :create<%= suffix %>, :update<%= suffix %> ],
16
+ :redirect_to => { :action => :list<%= suffix %> }
17
+
14
18
  def list<%= suffix %>
15
19
  @<%= singular_name %>_pages, @<%= plural_name %> = paginate :<%= plural_name %>, :per_page => 10
16
20
  end
@@ -22,7 +22,7 @@ a:hover { color: #fff; background-color:#000; }
22
22
  display: table;
23
23
  }
24
24
 
25
- #ErrorExplanation {
25
+ #errorExplanation {
26
26
  width: 400px;
27
27
  border: 2px solid red;
28
28
  padding: 7px;
@@ -31,7 +31,7 @@ a:hover { color: #fff; background-color:#000; }
31
31
  background-color: #f0f0f0;
32
32
  }
33
33
 
34
- #ErrorExplanation h2 {
34
+ #errorExplanation h2 {
35
35
  text-align: left;
36
36
  font-weight: bold;
37
37
  padding: 5px 5px 5px 15px;
@@ -41,13 +41,13 @@ a:hover { color: #fff; background-color:#000; }
41
41
  color: #fff;
42
42
  }
43
43
 
44
- #ErrorExplanation p {
44
+ #errorExplanation p {
45
45
  color: #333;
46
46
  margin-bottom: 0;
47
47
  padding: 5px;
48
48
  }
49
49
 
50
- #ErrorExplanation ul li {
50
+ #errorExplanation ul li {
51
51
  font-size: 12px;
52
52
  list-style: square;
53
53
  }
@@ -14,7 +14,7 @@
14
14
  <%% end %>
15
15
  <td><%%= link_to 'Show', :action => 'show<%= suffix %>', :id => <%= singular_name %> %></td>
16
16
  <td><%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => <%= singular_name %> %></td>
17
- <td><%%= link_to 'Destroy', { :action => 'destroy<%= suffix %>', :id => <%= singular_name %> }, :confirm => 'Are you sure?' %></td>
17
+ <td><%%= link_to 'Destroy', { :action => 'destroy<%= suffix %>', :id => <%= singular_name %> }, :confirm => 'Are you sure?', :post => true %></td>
18
18
  </tr>
19
19
  <%% end %>
20
20
  </table>
@@ -12,4 +12,4 @@ Example:
12
12
  ./script/generate session_migration AddSessionTable
13
13
 
14
14
  With 4 existing migrations, this will create an AddSessionTable migration in the
15
- file db/migrate/5_add_session_table.rb
15
+ file db/migrate/005_add_session_table.rb
@@ -96,8 +96,8 @@ module Rails
96
96
 
97
97
  # Raise a usage error. Override usage_message to provide a blurb
98
98
  # after the option parser summary.
99
- def usage
100
- raise UsageError, "#{@option_parser}\n#{usage_message}"
99
+ def usage(message = usage_message)
100
+ raise UsageError, "#{@option_parser}\n#{message}"
101
101
  end
102
102
 
103
103
  def usage_message
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,17 @@
1
+ min_release = "1.8.2 (2004-12-25)"
2
+ ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
3
+ if ruby_release =~ /1\.8\.3/
4
+ abort <<-end_message
5
+
6
+ Rails does not work with Ruby version 1.8.3.
7
+ Please upgrade to version 1.8.4 or downgrade to 1.8.2.
8
+
9
+ end_message
10
+ elsif ruby_release < min_release
11
+ abort <<-end_message
12
+
13
+ Rails requires Ruby version #{min_release} or later.
14
+ You're running #{ruby_release}; please upgrade to continue.
15
+
16
+ end_message
17
+ end
@@ -1,158 +1,160 @@
1
- desc "Migrate the database according to the migrate scripts in db/migrate (only supported on PG/MySQL). A specific version can be targetted with VERSION=x"
2
- task :migrate => :environment do
3
- ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
4
- Rake::Task[:db_schema_dump].invoke if ActiveRecord::Base.schema_format == :ruby
5
- end
6
-
7
- desc "Load fixtures into the current environment's database"
8
- task :load_fixtures => :environment do
9
- require 'active_record/fixtures'
10
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
11
- Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')).each do |fixture_file|
12
- Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
1
+ namespace :db do
2
+ desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
3
+ task :migrate => :environment do
4
+ ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
5
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
13
6
  end
14
- end
15
7
 
16
- desc "Create a db/schema.rb file that can be portably used against any DB supported by AR."
17
- task :db_schema_dump => :environment do
18
- require 'active_record/schema_dumper'
19
- File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
20
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
21
- end
22
- end
23
-
24
- desc "Import a schema.rb file into the database."
25
- task :db_schema_import => :environment do
26
- file = ENV['SCHEMA'] || "db/schema.rb"
27
- load file
28
- end
8
+ namespace :fixtures do
9
+ desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
10
+ task :load => :environment do
11
+ require 'active_record/fixtures'
12
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
13
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
14
+ Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
15
+ end
16
+ end
17
+ end
29
18
 
30
- desc "Recreate the test database from the current environment's database schema."
31
- task :clone_schema_to_test => :db_schema_dump do
32
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
33
- Rake::Task[:db_schema_import].invoke
34
- end
35
-
36
- desc "Dump the database structure to a SQL file"
37
- task :db_structure_dump => :environment do
38
- abcs = ActiveRecord::Base.configurations
39
- case abcs[RAILS_ENV]["adapter"]
40
- when "mysql", "oci"
41
- ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
42
- File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
43
- when "postgresql"
44
- ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
45
- ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
46
- ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
47
- search_path = abcs[RAILS_ENV]["schema_search_path"]
48
- search_path = "--schema=#{search_path}" if search_path
49
- `pg_dump -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
50
- when "sqlite", "sqlite3"
51
- dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
52
- `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
53
- when "sqlserver"
54
- `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
55
- `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
56
- else
57
- raise "Task not supported by '#{abcs["test"]["adapter"]}'"
58
- end
19
+ namespace :schema do
20
+ desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
21
+ task :dump => :environment do
22
+ require 'active_record/schema_dumper'
23
+ File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
24
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
25
+ end
26
+ end
59
27
 
60
- if ActiveRecord::Base.connection.supports_migrations?
61
- File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
28
+ desc "Load a schema.rb file into the database"
29
+ task :load => :environment do
30
+ file = ENV['SCHEMA'] || "db/schema.rb"
31
+ load(file)
32
+ end
62
33
  end
63
- end
64
34
 
65
- desc "Recreate the test databases from the development structure"
66
- task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
67
- abcs = ActiveRecord::Base.configurations
68
- case abcs["test"]["adapter"]
69
- when "mysql"
70
- ActiveRecord::Base.establish_connection(:test)
71
- ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
72
- IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
73
- ActiveRecord::Base.connection.execute(table)
74
- end
75
- when "postgresql"
76
- ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
77
- ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
78
- ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
79
- `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
80
- when "sqlite", "sqlite3"
81
- dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
82
- `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql`
83
- when "sqlserver"
84
- `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
85
- when "oci"
86
- ActiveRecord::Base.establish_connection(:test)
87
- IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
88
- ActiveRecord::Base.connection.execute(ddl)
35
+ namespace :structure do
36
+ desc "Dump the database structure to a SQL file"
37
+ task :dump => :environment do
38
+ abcs = ActiveRecord::Base.configurations
39
+ case abcs[RAILS_ENV]["adapter"]
40
+ when "mysql", "oci"
41
+ ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
42
+ File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
43
+ when "postgresql"
44
+ ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
45
+ ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
46
+ ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
47
+ search_path = abcs[RAILS_ENV]["schema_search_path"]
48
+ search_path = "--schema=#{search_path}" if search_path
49
+ `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
50
+ when "sqlite", "sqlite3"
51
+ dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
52
+ `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
53
+ when "sqlserver"
54
+ `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
55
+ `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
56
+ else
57
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
89
58
  end
90
- else
91
- raise "Task not supported by '#{abcs["test"]["adapter"]}'"
92
- end
93
- end
94
59
 
95
- desc "Empty the test database"
96
- task :purge_test_database => :environment do
97
- abcs = ActiveRecord::Base.configurations
98
- case abcs["test"]["adapter"]
99
- when "mysql"
100
- ActiveRecord::Base.establish_connection(:test)
101
- ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
102
- when "postgresql"
103
- ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
104
- ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
105
- ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
106
- enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"]
107
- `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
108
- `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
109
- when "sqlite","sqlite3"
110
- dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
111
- File.delete(dbfile) if File.exist?(dbfile)
112
- when "sqlserver"
113
- dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
114
- `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
115
- `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
116
- when "oci"
117
- ActiveRecord::Base.establish_connection(:test)
118
- ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
119
- ActiveRecord::Base.connection.execute(ddl)
60
+ if ActiveRecord::Base.connection.supports_migrations?
61
+ File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
120
62
  end
121
- else
122
- raise "Task not supported by '#{abcs["test"]["adapter"]}'"
63
+ end
123
64
  end
124
- end
125
65
 
126
- def prepare_test_database_task
127
- {:sql => :clone_structure_to_test,
128
- :ruby => :clone_schema_to_test}[ActiveRecord::Base.schema_format]
129
- end
66
+ namespace :test do
67
+ desc "Recreate the test database from the current environment's database schema"
68
+ task :clone => "db:schema:dump" do
69
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
70
+ ActiveRecord::Schema.verbose = false
71
+ Rake::Task["db:schema:load"].invoke
72
+ end
130
73
 
131
- desc 'Prepare the test database and load the schema'
132
- task :prepare_test_database => :environment do
133
- Rake::Task[prepare_test_database_task].invoke
134
- end
74
+
75
+ desc "Recreate the test databases from the development structure"
76
+ task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
77
+ abcs = ActiveRecord::Base.configurations
78
+ case abcs["test"]["adapter"]
79
+ when "mysql"
80
+ ActiveRecord::Base.establish_connection(:test)
81
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
82
+ IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
83
+ ActiveRecord::Base.connection.execute(table)
84
+ end
85
+ when "postgresql"
86
+ ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
87
+ ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
88
+ ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
89
+ `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
90
+ when "sqlite", "sqlite3"
91
+ dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
92
+ `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql`
93
+ when "sqlserver"
94
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
95
+ when "oci"
96
+ ActiveRecord::Base.establish_connection(:test)
97
+ IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
98
+ ActiveRecord::Base.connection.execute(ddl)
99
+ end
100
+ else
101
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
102
+ end
103
+ end
135
104
 
136
- desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore"
137
- task :create_sessions_table => :environment do
138
- raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
105
+ desc "Empty the test database"
106
+ task :purge => :environment do
107
+ abcs = ActiveRecord::Base.configurations
108
+ case abcs["test"]["adapter"]
109
+ when "mysql"
110
+ ActiveRecord::Base.establish_connection(:test)
111
+ ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
112
+ when "postgresql"
113
+ ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
114
+ ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
115
+ ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
116
+ enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"]
117
+ `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
118
+ `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
119
+ when "sqlite","sqlite3"
120
+ dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
121
+ File.delete(dbfile) if File.exist?(dbfile)
122
+ when "sqlserver"
123
+ dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
124
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
125
+ `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
126
+ when "oci"
127
+ ActiveRecord::Base.establish_connection(:test)
128
+ ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
129
+ ActiveRecord::Base.connection.execute(ddl)
130
+ end
131
+ else
132
+ raise "Task not supported by '#{abcs["test"]["adapter"]}'"
133
+ end
134
+ end
139
135
 
140
- ActiveRecord::Base.connection.create_table :sessions do |t|
141
- t.column :session_id, :string
142
- t.column :data, :text
143
- t.column :updated_at, :datetime
136
+ desc 'Prepare the test database and load the schema'
137
+ task :prepare => :environment do
138
+ Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
139
+ end
144
140
  end
145
-
146
- ActiveRecord::Base.connection.add_index :sessions, :session_id
147
- end
148
141
 
149
- desc "Drop the sessions table"
150
- task :drop_sessions_table => :environment do
151
- raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
152
-
153
- ActiveRecord::Base.connection.drop_table :sessions
142
+ namespace :sessions do
143
+ desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore"
144
+ task :create => :environment do
145
+ raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
146
+ require 'rails_generator'
147
+ require 'rails_generator/scripts/generate'
148
+ Rails::Generator::Scripts::Generate.new.run(["session_migration", ENV["MIGRATION"] || "AddSessions"])
149
+ end
150
+
151
+ desc "Clear the sessions table"
152
+ task :clear => :environment do
153
+ ActiveRecord::Base.connection.execute "DELETE FROM sessions"
154
+ end
155
+ end
154
156
  end
155
157
 
156
- desc "Drop and recreate the session table (much faster than 'DELETE * FROM sessions')"
157
- task :purge_sessions_table => [ :drop_sessions_table, :create_sessions_table ] do
158
+ def session_table_name
159
+ ActiveRecord::Base.pluralize_table_names ? :sessions : :session
158
160
  end