rails 1.0.0 → 2.0.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.
- data/CHANGELOG +1020 -10
- data/MIT-LICENSE +1 -1
- data/README +110 -60
- data/Rakefile +74 -139
- data/bin/about +1 -1
- data/bin/console +1 -1
- data/bin/destroy +1 -1
- data/bin/generate +1 -1
- data/bin/performance/request +3 -0
- data/bin/plugin +1 -1
- data/bin/process/{spinner → inspector} +1 -1
- data/bin/rails +10 -12
- data/bin/runner +1 -1
- data/bin/server +1 -1
- data/{lib/rails_info.rb → builtin/rails_info/rails/info.rb} +33 -14
- data/builtin/rails_info/rails/info_controller.rb +9 -0
- data/builtin/rails_info/rails/info_helper.rb +2 -0
- data/builtin/rails_info/rails_info_controller.rb +2 -0
- data/configs/apache.conf +1 -1
- data/configs/databases/frontbase.yml +28 -0
- data/configs/databases/mysql.yml +54 -0
- data/configs/databases/oracle.yml +39 -0
- data/configs/databases/postgresql.yml +48 -0
- data/configs/databases/sqlite2.yml +16 -0
- data/configs/databases/sqlite3.yml +19 -0
- data/configs/initializers/inflections.rb +10 -0
- data/configs/initializers/mime_types.rb +5 -0
- data/configs/lighttpd.conf +29 -15
- data/configs/routes.rb +27 -11
- data/doc/README_FOR_APP +1 -1
- data/environments/boot.rb +103 -14
- data/environments/development.rb +5 -6
- data/environments/environment.rb +36 -30
- data/environments/production.rb +2 -3
- data/environments/test.rb +5 -2
- data/fresh_rakefile +2 -2
- data/helpers/application.rb +8 -2
- data/helpers/test_helper.rb +10 -0
- data/html/404.html +27 -5
- data/html/422.html +30 -0
- data/html/500.html +27 -5
- data/html/index.html +6 -6
- data/html/javascripts/application.js +2 -0
- data/html/javascripts/controls.js +532 -319
- data/html/javascripts/dragdrop.js +521 -133
- data/html/javascripts/effects.js +708 -442
- data/html/javascripts/prototype.js +3393 -953
- data/html/robots.txt +5 -1
- data/lib/code_statistics.rb +2 -2
- data/lib/commands/console.rb +18 -9
- data/lib/commands/performance/profiler.rb +25 -9
- data/lib/commands/performance/request.rb +6 -0
- data/lib/commands/plugin.rb +196 -96
- data/lib/commands/process/inspector.rb +68 -0
- data/lib/commands/process/reaper.rb +90 -71
- data/lib/commands/process/spawner.rb +188 -21
- data/lib/commands/process/spinner.rb +3 -3
- data/lib/commands/runner.rb +28 -7
- data/lib/commands/server.rb +20 -9
- data/lib/commands/servers/base.rb +31 -0
- data/lib/commands/servers/lighttpd.rb +60 -26
- data/lib/commands/servers/mongrel.rb +69 -0
- data/lib/commands/servers/webrick.rb +18 -11
- data/lib/console_app.rb +30 -0
- data/lib/console_sandbox.rb +2 -2
- data/lib/console_with_helpers.rb +26 -0
- data/lib/dispatcher.rb +3 -78
- data/lib/fcgi_handler.rb +98 -64
- data/lib/initializer.rb +323 -194
- data/lib/rails/plugin/loader.rb +150 -0
- data/lib/rails/plugin/locator.rb +78 -0
- data/lib/rails/plugin.rb +84 -0
- data/lib/{rails_version.rb → rails/version.rb} +1 -1
- data/lib/rails_generator/base.rb +85 -25
- data/lib/rails_generator/commands.rb +122 -40
- data/lib/rails_generator/generated_attribute.rb +42 -0
- data/lib/rails_generator/generators/applications/app/USAGE +0 -7
- data/lib/rails_generator/generators/applications/app/app_generator.rb +67 -28
- data/lib/rails_generator/generators/components/controller/USAGE +11 -12
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -3
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
- data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
- data/lib/rails_generator/generators/components/integration_test/USAGE +8 -0
- data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
- data/lib/rails_generator/generators/components/mailer/USAGE +9 -11
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +10 -8
- data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +9 -25
- data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
- data/lib/rails_generator/generators/components/migration/USAGE +23 -8
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +7 -3
- data/lib/rails_generator/generators/components/model/USAGE +21 -11
- data/lib/rails_generator/generators/components/model/model_generator.rb +28 -1
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +18 -4
- data/lib/rails_generator/generators/components/model/templates/migration.rb +16 -0
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +2 -4
- data/lib/rails_generator/generators/components/observer/USAGE +13 -0
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
- data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/plugin/USAGE +10 -18
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +6 -0
- data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
- data/lib/rails_generator/generators/components/resource/USAGE +23 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +74 -0
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +8 -0
- data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -137
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +65 -34
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -76
- data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +17 -0
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +5 -5
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +19 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +24 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +18 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +10 -0
- data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
- data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +7 -1
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +8 -7
- data/lib/rails_generator/lookup.rb +46 -12
- data/lib/rails_generator/options.rb +11 -8
- data/lib/rails_generator/scripts/destroy.rb +23 -0
- data/lib/rails_generator/scripts.rb +7 -4
- data/lib/rails_generator/secret_key_generator.rb +160 -0
- data/lib/rails_generator/spec.rb +1 -1
- data/lib/rails_generator.rb +1 -1
- data/lib/railties_path.rb +1 -1
- data/lib/ruby_version_check.rb +17 -0
- data/lib/source_annotation_extractor.rb +62 -0
- data/lib/tasks/annotations.rake +23 -0
- data/lib/tasks/databases.rake +328 -133
- data/lib/tasks/documentation.rake +72 -68
- data/lib/tasks/framework.rake +99 -58
- data/lib/tasks/log.rake +9 -0
- data/lib/tasks/misc.rake +2 -17
- data/lib/tasks/rails.rb +2 -2
- data/lib/tasks/routes.rake +17 -0
- data/lib/tasks/statistics.rake +10 -8
- data/lib/tasks/testing.rake +99 -31
- data/lib/tasks/tmp.rake +37 -0
- data/lib/test_help.rb +8 -5
- data/lib/webrick_server.rb +11 -16
- metadata +312 -272
- data/bin/breakpointer +0 -3
- data/builtin/controllers/rails_info_controller.rb +0 -11
- data/configs/database.yml +0 -85
- data/lib/binding_of_caller.rb +0 -85
- data/lib/breakpoint.rb +0 -523
- data/lib/breakpoint_client.rb +0 -196
- data/lib/commands/breakpointer.rb +0 -1
- data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
- data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
- data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +0 -13
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
- data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
- data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
- data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
- data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
- data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
- data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
- data/lib/tasks/javascripts.rake +0 -6
data/lib/tasks/databases.rake
CHANGED
@@ -1,158 +1,353 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
namespace :db do
|
2
|
+
namespace :create do
|
3
|
+
desc 'Create all the local databases defined in config/database.yml'
|
4
|
+
task :all => :environment do
|
5
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
6
|
+
# Skip entries that don't have a database key, such as the first entry here:
|
7
|
+
#
|
8
|
+
# defaults: &defaults
|
9
|
+
# adapter: mysql
|
10
|
+
# username: root
|
11
|
+
# password:
|
12
|
+
# host: localhost
|
13
|
+
#
|
14
|
+
# development:
|
15
|
+
# database: blog_development
|
16
|
+
# <<: *defaults
|
17
|
+
next unless config['database']
|
18
|
+
# Only connect to local databases
|
19
|
+
if config['host'] == 'localhost' || config['host'].blank?
|
20
|
+
create_database(config)
|
21
|
+
else
|
22
|
+
p "This task only creates local databases. #{config['database']} is on a remote host."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
6
27
|
|
7
|
-
desc
|
8
|
-
task :
|
9
|
-
|
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, '.*'))
|
28
|
+
desc 'Create the database defined in config/database.yml for the current RAILS_ENV'
|
29
|
+
task :create => :environment do
|
30
|
+
create_database(ActiveRecord::Base.configurations[RAILS_ENV])
|
13
31
|
end
|
14
|
-
end
|
15
32
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
33
|
+
def create_database(config)
|
34
|
+
begin
|
35
|
+
ActiveRecord::Base.establish_connection(config)
|
36
|
+
ActiveRecord::Base.connection
|
37
|
+
rescue
|
38
|
+
case config['adapter']
|
39
|
+
when 'mysql'
|
40
|
+
@charset = ENV['CHARSET'] || 'utf8'
|
41
|
+
@collation = ENV['COLLATION'] || 'utf8_general_ci'
|
42
|
+
begin
|
43
|
+
ActiveRecord::Base.establish_connection(config.merge({'database' => nil}))
|
44
|
+
ActiveRecord::Base.connection.create_database(config['database'], {:charset => @charset, :collation => @collation})
|
45
|
+
ActiveRecord::Base.establish_connection(config)
|
46
|
+
rescue
|
47
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
48
|
+
end
|
49
|
+
when 'postgresql'
|
50
|
+
`createdb "#{config['database']}" -E utf8`
|
51
|
+
when 'sqlite'
|
52
|
+
`sqlite "#{config['database']}"`
|
53
|
+
when 'sqlite3'
|
54
|
+
`sqlite3 "#{config['database']}"`
|
55
|
+
end
|
56
|
+
else
|
57
|
+
p "#{config['database']} already exists"
|
58
|
+
end
|
21
59
|
end
|
22
|
-
end
|
23
60
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
61
|
+
namespace :drop do
|
62
|
+
desc 'Drops all the local databases defined in config/database.yml'
|
63
|
+
task :all => :environment do
|
64
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
65
|
+
# Skip entries that don't have a database key
|
66
|
+
next unless config['database']
|
67
|
+
# Only connect to local databases
|
68
|
+
if config['host'] == 'localhost' || config['host'].blank?
|
69
|
+
drop_database(config)
|
70
|
+
else
|
71
|
+
p "This task only drops local databases. #{config['database']} is on a remote host."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
29
76
|
|
30
|
-
desc
|
31
|
-
task :
|
32
|
-
|
33
|
-
|
34
|
-
end
|
77
|
+
desc 'Drops the database for the current RAILS_ENV'
|
78
|
+
task :drop => :environment do
|
79
|
+
drop_database(ActiveRecord::Base.configurations[RAILS_ENV || 'development'])
|
80
|
+
end
|
35
81
|
|
36
|
-
desc "
|
37
|
-
task :
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
59
|
-
|
60
|
-
if ActiveRecord::Base.connection.supports_migrations?
|
61
|
-
File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
82
|
+
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
83
|
+
task :migrate => :environment do
|
84
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
85
|
+
ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
86
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
62
87
|
end
|
63
|
-
end
|
64
88
|
|
65
|
-
desc
|
66
|
-
task :
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
89
|
+
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
90
|
+
task :rollback => :environment do
|
91
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
92
|
+
version = ActiveRecord::Migrator.current_version - step
|
93
|
+
ActiveRecord::Migrator.migrate('db/migrate/', version)
|
94
|
+
end
|
95
|
+
|
96
|
+
desc 'Drops and recreates the database from db/schema.rb for the current environment.'
|
97
|
+
task :reset => ['db:drop', 'db:create', 'db:schema:load']
|
98
|
+
|
99
|
+
desc "Retrieves the charset for the current environment's database"
|
100
|
+
task :charset => :environment do
|
101
|
+
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
|
102
|
+
case config['adapter']
|
103
|
+
when 'mysql'
|
104
|
+
ActiveRecord::Base.establish_connection(config)
|
105
|
+
puts ActiveRecord::Base.connection.charset
|
106
|
+
else
|
107
|
+
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
desc "Retrieves the collation for the current environment's database"
|
112
|
+
task :collation => :environment do
|
113
|
+
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
|
114
|
+
case config['adapter']
|
115
|
+
when 'mysql'
|
116
|
+
ActiveRecord::Base.establish_connection(config)
|
117
|
+
puts ActiveRecord::Base.connection.collation
|
118
|
+
else
|
119
|
+
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
desc "Retrieves the current schema version number"
|
124
|
+
task :version => :environment do
|
125
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
126
|
+
end
|
127
|
+
|
128
|
+
desc "Raises an error if there are pending migrations"
|
129
|
+
task :abort_if_pending_migrations => :environment do
|
130
|
+
pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
|
131
|
+
|
132
|
+
if pending_migrations.any?
|
133
|
+
puts "You have #{pending_migrations.size} pending migrations:"
|
134
|
+
pending_migrations.each do |pending_migration|
|
135
|
+
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
74
136
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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)
|
137
|
+
abort "Run `rake db:migrate` to update your database then try again."
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
namespace :fixtures do
|
142
|
+
desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
143
|
+
task :load => :environment do
|
144
|
+
require 'active_record/fixtures'
|
145
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
146
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
147
|
+
Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
|
89
148
|
end
|
90
|
-
|
91
|
-
|
149
|
+
end
|
150
|
+
|
151
|
+
desc "Search for a fixture given a LABEL or ID."
|
152
|
+
task :identify => :environment do
|
153
|
+
require "active_record/fixtures"
|
154
|
+
|
155
|
+
label, id = ENV["LABEL"], ENV["ID"]
|
156
|
+
raise "LABEL or ID required" if label.blank? && id.blank?
|
157
|
+
|
158
|
+
puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label
|
159
|
+
|
160
|
+
Dir["#{RAILS_ROOT}/test/fixtures/**/*.yml"].each do |file|
|
161
|
+
if data = YAML::load(ERB.new(IO.read(file)).result)
|
162
|
+
data.keys.each do |key|
|
163
|
+
key_id = Fixtures.identify(key)
|
164
|
+
|
165
|
+
if key == label || key_id == id.to_i
|
166
|
+
puts "#{file}: #{key} (#{key_id})"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
92
172
|
end
|
93
|
-
end
|
94
173
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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)
|
174
|
+
namespace :schema do
|
175
|
+
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
|
176
|
+
task :dump => :environment do
|
177
|
+
require 'active_record/schema_dumper'
|
178
|
+
File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
|
179
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
120
180
|
end
|
121
|
-
|
122
|
-
|
181
|
+
end
|
182
|
+
|
183
|
+
desc "Load a schema.rb file into the database"
|
184
|
+
task :load => :environment do
|
185
|
+
file = ENV['SCHEMA'] || "db/schema.rb"
|
186
|
+
load(file)
|
187
|
+
end
|
123
188
|
end
|
124
|
-
end
|
125
189
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
190
|
+
namespace :structure do
|
191
|
+
desc "Dump the database structure to a SQL file"
|
192
|
+
task :dump => :environment do
|
193
|
+
abcs = ActiveRecord::Base.configurations
|
194
|
+
case abcs[RAILS_ENV]["adapter"]
|
195
|
+
when "mysql", "oci", "oracle"
|
196
|
+
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
|
197
|
+
File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
198
|
+
when "postgresql"
|
199
|
+
ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
|
200
|
+
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
|
201
|
+
ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
|
202
|
+
search_path = abcs[RAILS_ENV]["schema_search_path"]
|
203
|
+
search_path = "--schema=#{search_path}" if search_path
|
204
|
+
`pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
|
205
|
+
raise "Error dumping database" if $?.exitstatus == 1
|
206
|
+
when "sqlite", "sqlite3"
|
207
|
+
dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
|
208
|
+
`#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
|
209
|
+
when "sqlserver"
|
210
|
+
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
|
211
|
+
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
|
212
|
+
when "firebird"
|
213
|
+
set_firebird_env(abcs[RAILS_ENV])
|
214
|
+
db_string = firebird_db_string(abcs[RAILS_ENV])
|
215
|
+
sh "isql -a #{db_string} > db/#{RAILS_ENV}_structure.sql"
|
216
|
+
else
|
217
|
+
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
218
|
+
end
|
219
|
+
|
220
|
+
if ActiveRecord::Base.connection.supports_migrations?
|
221
|
+
File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
namespace :test do
|
227
|
+
desc "Recreate the test database from the current environment's database schema"
|
228
|
+
task :clone => %w(db:schema:dump db:test:purge) do
|
229
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
|
230
|
+
ActiveRecord::Schema.verbose = false
|
231
|
+
Rake::Task["db:schema:load"].invoke
|
232
|
+
end
|
130
233
|
|
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
|
135
234
|
|
136
|
-
desc "
|
137
|
-
task :
|
138
|
-
|
235
|
+
desc "Recreate the test databases from the development structure"
|
236
|
+
task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
|
237
|
+
abcs = ActiveRecord::Base.configurations
|
238
|
+
case abcs["test"]["adapter"]
|
239
|
+
when "mysql"
|
240
|
+
ActiveRecord::Base.establish_connection(:test)
|
241
|
+
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
242
|
+
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
|
243
|
+
ActiveRecord::Base.connection.execute(table)
|
244
|
+
end
|
245
|
+
when "postgresql"
|
246
|
+
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
|
247
|
+
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
|
248
|
+
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
|
249
|
+
`psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
|
250
|
+
when "sqlite", "sqlite3"
|
251
|
+
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
|
252
|
+
`#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql`
|
253
|
+
when "sqlserver"
|
254
|
+
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
|
255
|
+
when "oci", "oracle"
|
256
|
+
ActiveRecord::Base.establish_connection(:test)
|
257
|
+
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
|
258
|
+
ActiveRecord::Base.connection.execute(ddl)
|
259
|
+
end
|
260
|
+
when "firebird"
|
261
|
+
set_firebird_env(abcs["test"])
|
262
|
+
db_string = firebird_db_string(abcs["test"])
|
263
|
+
sh "isql -i db/#{RAILS_ENV}_structure.sql #{db_string}"
|
264
|
+
else
|
265
|
+
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
desc "Empty the test database"
|
270
|
+
task :purge => :environment do
|
271
|
+
abcs = ActiveRecord::Base.configurations
|
272
|
+
case abcs["test"]["adapter"]
|
273
|
+
when "mysql"
|
274
|
+
ActiveRecord::Base.establish_connection(:test)
|
275
|
+
ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
|
276
|
+
when "postgresql"
|
277
|
+
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
|
278
|
+
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
|
279
|
+
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
|
280
|
+
enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"]
|
281
|
+
|
282
|
+
ActiveRecord::Base.clear_active_connections!
|
283
|
+
`dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
|
284
|
+
`createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
|
285
|
+
when "sqlite","sqlite3"
|
286
|
+
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
|
287
|
+
File.delete(dbfile) if File.exist?(dbfile)
|
288
|
+
when "sqlserver"
|
289
|
+
dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
|
290
|
+
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
|
291
|
+
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
|
292
|
+
when "oci", "oracle"
|
293
|
+
ActiveRecord::Base.establish_connection(:test)
|
294
|
+
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
|
295
|
+
ActiveRecord::Base.connection.execute(ddl)
|
296
|
+
end
|
297
|
+
when "firebird"
|
298
|
+
ActiveRecord::Base.establish_connection(:test)
|
299
|
+
ActiveRecord::Base.connection.recreate_database!
|
300
|
+
else
|
301
|
+
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
302
|
+
end
|
303
|
+
end
|
139
304
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
305
|
+
desc 'Prepare the test database and load the schema'
|
306
|
+
task :prepare => %w(environment db:abort_if_pending_migrations) do
|
307
|
+
if defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
|
308
|
+
Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
|
309
|
+
end
|
310
|
+
end
|
144
311
|
end
|
145
|
-
|
146
|
-
|
312
|
+
|
313
|
+
namespace :sessions do
|
314
|
+
desc "Creates a sessions migration for use with CGI::Session::ActiveRecordStore"
|
315
|
+
task :create => :environment do
|
316
|
+
raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
|
317
|
+
require 'rails_generator'
|
318
|
+
require 'rails_generator/scripts/generate'
|
319
|
+
Rails::Generator::Scripts::Generate.new.run(["session_migration", ENV["MIGRATION"] || "CreateSessions"])
|
320
|
+
end
|
321
|
+
|
322
|
+
desc "Clear the sessions table"
|
323
|
+
task :clear => :environment do
|
324
|
+
session_table = 'session'
|
325
|
+
session_table = Inflector.pluralize(session_table) if ActiveRecord::Base.pluralize_table_names
|
326
|
+
ActiveRecord::Base.connection.execute "DELETE FROM #{session_table}"
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def drop_database(config)
|
332
|
+
case config['adapter']
|
333
|
+
when 'mysql'
|
334
|
+
ActiveRecord::Base.connection.drop_database config['database']
|
335
|
+
when /^sqlite/
|
336
|
+
FileUtils.rm_f(File.join(RAILS_ROOT, config['database']))
|
337
|
+
when 'postgresql'
|
338
|
+
`dropdb "#{config['database']}"`
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def session_table_name
|
343
|
+
ActiveRecord::Base.pluralize_table_names ? :sessions : :session
|
147
344
|
end
|
148
345
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
ActiveRecord::Base.connection.drop_table :sessions
|
346
|
+
def set_firebird_env(config)
|
347
|
+
ENV["ISC_USER"] = config["username"].to_s if config["username"]
|
348
|
+
ENV["ISC_PASSWORD"] = config["password"].to_s if config["password"]
|
154
349
|
end
|
155
350
|
|
156
|
-
|
157
|
-
|
351
|
+
def firebird_db_string(config)
|
352
|
+
FireRuby::Database.db_string_for(config.symbolize_keys)
|
158
353
|
end
|
@@ -1,76 +1,80 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
namespace :doc do
|
2
|
+
desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb"
|
3
|
+
Rake::RDocTask.new("app") { |rdoc|
|
4
|
+
rdoc.rdoc_dir = 'doc/app'
|
5
|
+
rdoc.template = ENV['template'] if ENV['template']
|
6
|
+
rdoc.title = "Rails Application Documentation"
|
7
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
8
|
+
rdoc.options << '--charset' << 'utf-8'
|
9
|
+
rdoc.rdoc_files.include('doc/README_FOR_APP')
|
10
|
+
rdoc.rdoc_files.include('app/**/*.rb')
|
11
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
12
|
+
}
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
options
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
desc "Generate documentation for the Rails framework"
|
15
|
+
Rake::RDocTask.new("rails") { |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'doc/api'
|
17
|
+
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
18
|
+
rdoc.title = "Rails Framework Documentation"
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG')
|
22
|
+
rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE')
|
23
|
+
rdoc.rdoc_files.include('vendor/rails/railties/README')
|
24
|
+
rdoc.rdoc_files.include('vendor/rails/railties/lib/{*.rb,commands/*.rb,rails_generator/*.rb}')
|
25
|
+
rdoc.rdoc_files.include('vendor/rails/activerecord/README')
|
26
|
+
rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG')
|
27
|
+
rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb')
|
28
|
+
rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*')
|
29
|
+
rdoc.rdoc_files.include('vendor/rails/activeresource/README')
|
30
|
+
rdoc.rdoc_files.include('vendor/rails/activeresource/CHANGELOG')
|
31
|
+
rdoc.rdoc_files.include('vendor/rails/activeresource/lib/active_resource.rb')
|
32
|
+
rdoc.rdoc_files.include('vendor/rails/activeresource/lib/active_resource/*')
|
33
|
+
rdoc.rdoc_files.include('vendor/rails/actionpack/README')
|
34
|
+
rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG')
|
35
|
+
rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb')
|
36
|
+
rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb')
|
37
|
+
rdoc.rdoc_files.include('vendor/rails/actionmailer/README')
|
38
|
+
rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG')
|
39
|
+
rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb')
|
40
|
+
rdoc.rdoc_files.include('vendor/rails/activesupport/README')
|
41
|
+
rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG')
|
42
|
+
rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb')
|
43
|
+
}
|
21
44
|
|
22
|
-
|
23
|
-
if File.exists?("#{plugin_base}/README")
|
24
|
-
files.include("#{plugin_base}/README")
|
25
|
-
options << "--main '#{plugin_base}/README'"
|
26
|
-
end
|
27
|
-
files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG")
|
45
|
+
plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
|
28
46
|
|
29
|
-
|
47
|
+
desc "Generate documentation for all installed plugins"
|
48
|
+
task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" }
|
30
49
|
|
31
|
-
|
50
|
+
desc "Remove plugin documentation"
|
51
|
+
task :clobber_plugins do
|
52
|
+
rm_rf 'doc/plugins' rescue nil
|
32
53
|
end
|
33
|
-
end
|
34
54
|
|
35
|
-
|
36
|
-
|
55
|
+
namespace :plugins do
|
56
|
+
# Define doc tasks for each plugin
|
57
|
+
plugins.each do |plugin|
|
58
|
+
task(plugin => :environment) do
|
59
|
+
plugin_base = "vendor/plugins/#{plugin}"
|
60
|
+
options = []
|
61
|
+
files = Rake::FileList.new
|
62
|
+
options << "-o doc/plugins/#{plugin}"
|
63
|
+
options << "--title '#{plugin.titlecase} Plugin Documentation'"
|
64
|
+
options << '--line-numbers' << '--inline-source'
|
65
|
+
options << '-T html'
|
37
66
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
67
|
+
files.include("#{plugin_base}/lib/**/*.rb")
|
68
|
+
if File.exists?("#{plugin_base}/README")
|
69
|
+
files.include("#{plugin_base}/README")
|
70
|
+
options << "--main '#{plugin_base}/README'"
|
71
|
+
end
|
72
|
+
files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG")
|
73
|
+
|
74
|
+
options << files.to_s
|
42
75
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
rdoc.options << '--line-numbers --inline-source'
|
49
|
-
rdoc.rdoc_files.include('README')
|
50
|
-
rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG')
|
51
|
-
rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE')
|
52
|
-
rdoc.rdoc_files.include('vendor/rails/activerecord/README')
|
53
|
-
rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG')
|
54
|
-
rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb')
|
55
|
-
rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*')
|
56
|
-
rdoc.rdoc_files.include('vendor/rails/actionpack/README')
|
57
|
-
rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG')
|
58
|
-
rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb')
|
59
|
-
rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb')
|
60
|
-
rdoc.rdoc_files.include('vendor/rails/actionmailer/README')
|
61
|
-
rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG')
|
62
|
-
rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb')
|
63
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/README')
|
64
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/CHANGELOG')
|
65
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service.rb')
|
66
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/*.rb')
|
67
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/api/*.rb')
|
68
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/client/*.rb')
|
69
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/container/*.rb')
|
70
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/dispatcher/*.rb')
|
71
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/protocol/*.rb')
|
72
|
-
rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/support/*.rb')
|
73
|
-
rdoc.rdoc_files.include('vendor/rails/activesupport/README')
|
74
|
-
rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG')
|
75
|
-
rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb')
|
76
|
-
}
|
76
|
+
sh %(rdoc #{options * ' '})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|