rails 2.1.2 → 2.2.2

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 (221) hide show
  1. data/CHANGELOG +27 -3
  2. data/Rakefile +70 -10
  3. data/bin/about +0 -0
  4. data/bin/console +0 -0
  5. data/bin/destroy +0 -0
  6. data/bin/generate +0 -0
  7. data/bin/performance/benchmarker +0 -0
  8. data/bin/performance/profiler +0 -0
  9. data/bin/performance/request +0 -0
  10. data/bin/plugin +0 -0
  11. data/bin/process/inspector +0 -0
  12. data/bin/process/reaper +0 -0
  13. data/bin/process/spawner +0 -0
  14. data/bin/runner +0 -0
  15. data/bin/server +0 -0
  16. data/config.ru +17 -0
  17. data/configs/apache.conf +0 -0
  18. data/configs/databases/ibm_db.yml +62 -0
  19. data/configs/databases/mysql.yml +3 -0
  20. data/configs/databases/postgresql.yml +3 -0
  21. data/configs/databases/sqlite2.yml +3 -0
  22. data/configs/databases/sqlite3.yml +3 -0
  23. data/configs/locales/en.yml +5 -0
  24. data/dispatches/dispatch.fcgi +1 -1
  25. data/dispatches/dispatch.rb +2 -2
  26. data/dispatches/gateway.cgi +2 -2
  27. data/doc/README_FOR_APP +5 -2
  28. data/doc/guides/html/2_2_release_notes.html +1185 -0
  29. data/doc/guides/html/actioncontroller_basics.html +1270 -0
  30. data/doc/guides/html/activerecord_validations_callbacks.html +749 -0
  31. data/doc/guides/html/association_basics.html +2585 -0
  32. data/doc/guides/html/authors.html +240 -0
  33. data/doc/guides/html/benchmarking_and_profiling.html +1018 -0
  34. data/doc/guides/html/caching_with_rails.html +583 -0
  35. data/doc/guides/html/command_line.html +434 -0
  36. data/doc/guides/html/configuring.html +438 -0
  37. data/doc/guides/html/creating_plugins.html +1594 -0
  38. data/doc/guides/html/debugging_rails_applications.html +1175 -0
  39. data/doc/guides/html/finders.html +1090 -0
  40. data/doc/guides/html/form_helpers.html +638 -0
  41. data/doc/guides/html/getting_started_with_rails.html +2066 -0
  42. data/doc/guides/html/index.html +349 -0
  43. data/doc/guides/html/layouts_and_rendering.html +1406 -0
  44. data/doc/guides/html/migrations.html +921 -0
  45. data/doc/guides/html/routing_outside_in.html +2213 -0
  46. data/doc/guides/html/security.html +1346 -0
  47. data/doc/guides/html/testing_rails_applications.html +1859 -0
  48. data/doc/guides/source/2_2_release_notes.txt +435 -0
  49. data/doc/guides/source/actioncontroller_basics/changelog.txt +5 -0
  50. data/doc/guides/source/actioncontroller_basics/cookies.txt +34 -0
  51. data/doc/guides/source/actioncontroller_basics/csrf.txt +32 -0
  52. data/doc/guides/source/actioncontroller_basics/filters.txt +119 -0
  53. data/doc/guides/source/actioncontroller_basics/http_auth.txt +24 -0
  54. data/doc/guides/source/actioncontroller_basics/index.txt +40 -0
  55. data/doc/guides/source/actioncontroller_basics/introduction.txt +9 -0
  56. data/doc/guides/source/actioncontroller_basics/methods.txt +39 -0
  57. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +14 -0
  58. data/doc/guides/source/actioncontroller_basics/params.txt +93 -0
  59. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +43 -0
  60. data/doc/guides/source/actioncontroller_basics/rescue.txt +67 -0
  61. data/doc/guides/source/actioncontroller_basics/session.txt +187 -0
  62. data/doc/guides/source/actioncontroller_basics/streaming.txt +91 -0
  63. data/doc/guides/source/actioncontroller_basics/verification.txt +40 -0
  64. data/doc/guides/source/active_record_basics.txt +181 -0
  65. data/doc/guides/source/activerecord_validations_callbacks.txt +404 -0
  66. data/doc/guides/source/association_basics.txt +1840 -0
  67. data/doc/guides/source/authors.txt +39 -0
  68. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +95 -0
  69. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +105 -0
  70. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +185 -0
  71. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +27 -0
  72. data/doc/guides/source/benchmarking_and_profiling/index.txt +242 -0
  73. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +179 -0
  74. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +57 -0
  75. data/doc/guides/source/caching_with_rails.txt +367 -0
  76. data/doc/guides/source/command_line.txt +147 -0
  77. data/doc/guides/source/configuring.txt +225 -0
  78. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +191 -0
  79. data/doc/guides/source/creating_plugins/appendix.txt +46 -0
  80. data/doc/guides/source/creating_plugins/controllers.txt +59 -0
  81. data/doc/guides/source/creating_plugins/core_ext.txt +123 -0
  82. data/doc/guides/source/creating_plugins/custom_route.txt +69 -0
  83. data/doc/guides/source/creating_plugins/gem.txt +1 -0
  84. data/doc/guides/source/creating_plugins/generator_method.txt +89 -0
  85. data/doc/guides/source/creating_plugins/helpers.txt +51 -0
  86. data/doc/guides/source/creating_plugins/index.txt +52 -0
  87. data/doc/guides/source/creating_plugins/migration_generator.txt +156 -0
  88. data/doc/guides/source/creating_plugins/models.txt +76 -0
  89. data/doc/guides/source/creating_plugins/odds_and_ends.txt +69 -0
  90. data/doc/guides/source/creating_plugins/test_setup.txt +230 -0
  91. data/doc/guides/source/debugging_rails_applications.txt +733 -0
  92. data/doc/guides/source/finders.txt +668 -0
  93. data/doc/guides/source/form_helpers.txt +345 -0
  94. data/doc/guides/source/getting_started_with_rails.txt +1256 -0
  95. data/doc/guides/source/images/belongs_to.png +0 -0
  96. data/doc/guides/source/images/bullet.gif +0 -0
  97. data/doc/guides/source/images/csrf.png +0 -0
  98. data/doc/guides/source/images/habtm.png +0 -0
  99. data/doc/guides/source/images/has_many.png +0 -0
  100. data/doc/guides/source/images/has_many_through.png +0 -0
  101. data/doc/guides/source/images/has_one.png +0 -0
  102. data/doc/guides/source/images/has_one_through.png +0 -0
  103. data/doc/guides/source/images/header_backdrop.png +0 -0
  104. data/doc/guides/source/images/icons/README +5 -0
  105. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  106. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  107. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  108. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  109. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  110. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  111. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  112. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  113. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  114. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  115. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  116. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  117. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  118. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  119. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  120. data/doc/guides/source/images/icons/caution.png +0 -0
  121. data/doc/guides/source/images/icons/example.png +0 -0
  122. data/doc/guides/source/images/icons/home.png +0 -0
  123. data/doc/guides/source/images/icons/important.png +0 -0
  124. data/doc/guides/source/images/icons/next.png +0 -0
  125. data/doc/guides/source/images/icons/note.png +0 -0
  126. data/doc/guides/source/images/icons/prev.png +0 -0
  127. data/doc/guides/source/images/icons/tip.png +0 -0
  128. data/doc/guides/source/images/icons/up.png +0 -0
  129. data/doc/guides/source/images/icons/warning.png +0 -0
  130. data/doc/guides/source/images/polymorphic.png +0 -0
  131. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  132. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  133. data/doc/guides/source/images/session_fixation.png +0 -0
  134. data/doc/guides/source/index.txt +118 -0
  135. data/doc/guides/source/layouts_and_rendering.txt +982 -0
  136. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +85 -0
  137. data/doc/guides/source/migrations/changelog.txt +5 -0
  138. data/doc/guides/source/migrations/creating_a_migration.txt +109 -0
  139. data/doc/guides/source/migrations/foreign_keys.txt +8 -0
  140. data/doc/guides/source/migrations/index.txt +22 -0
  141. data/doc/guides/source/migrations/rakeing_around.txt +111 -0
  142. data/doc/guides/source/migrations/scheming.txt +47 -0
  143. data/doc/guides/source/migrations/using_models_in_migrations.txt +46 -0
  144. data/doc/guides/source/migrations/writing_a_migration.txt +159 -0
  145. data/doc/guides/source/routing_outside_in.txt +986 -0
  146. data/doc/guides/source/security.txt +984 -0
  147. data/doc/guides/source/stylesheets/base.css +358 -0
  148. data/doc/guides/source/stylesheets/forms.css +35 -0
  149. data/doc/guides/source/stylesheets/more.css +82 -0
  150. data/doc/guides/source/templates/guides.html.erb +97 -0
  151. data/doc/guides/source/templates/inline.css +165 -0
  152. data/doc/guides/source/testing_rails_applications.txt +995 -0
  153. data/environments/boot.rb +2 -2
  154. data/environments/environment.rb +9 -1
  155. data/environments/production.rb +3 -1
  156. data/helpers/performance_test.rb +9 -0
  157. data/html/500.html +4 -1
  158. data/html/javascripts/controls.js +72 -72
  159. data/html/javascripts/dragdrop.js +165 -164
  160. data/html/javascripts/effects.js +173 -165
  161. data/html/javascripts/prototype.js +362 -267
  162. data/lib/commands/console.rb +13 -0
  163. data/lib/commands/dbconsole.rb +2 -2
  164. data/lib/commands/ncgi/listener +2 -2
  165. data/lib/commands/ncgi/tracker +2 -2
  166. data/lib/commands/plugin.rb +41 -24
  167. data/lib/commands/process/spawner.rb +4 -4
  168. data/lib/commands/runner.rb +1 -1
  169. data/lib/commands/server.rb +11 -1
  170. data/lib/commands/servers/thin.rb +25 -0
  171. data/lib/fcgi_handler.rb +1 -3
  172. data/lib/initializer.rb +162 -39
  173. data/lib/performance_test_help.rb +5 -0
  174. data/lib/rails/gem_builder.rb +3 -3
  175. data/lib/rails/gem_dependency.rb +155 -33
  176. data/lib/rails/mongrel_server/commands.rb +1 -1
  177. data/lib/rails/plugin.rb +10 -2
  178. data/lib/rails/rack.rb +6 -0
  179. data/lib/rails/rack/logger.rb +28 -0
  180. data/lib/rails/rack/static.rb +35 -0
  181. data/lib/rails/vendor_gem_source_index.rb +140 -0
  182. data/lib/rails/version.rb +1 -1
  183. data/lib/rails_generator/commands.rb +10 -16
  184. data/lib/rails_generator/generated_attribute.rb +4 -0
  185. data/lib/rails_generator/generators/applications/app/app_generator.rb +9 -3
  186. data/lib/rails_generator/generators/components/controller/controller_generator.rb +1 -1
  187. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -1
  188. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +1 -1
  189. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +2 -2
  190. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +1 -1
  191. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +2 -3
  192. data/lib/rails_generator/generators/components/model/model_generator.rb +1 -1
  193. data/lib/rails_generator/generators/components/model/templates/model.rb +3 -0
  194. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -1
  195. data/lib/rails_generator/generators/components/observer/observer_generator.rb +1 -1
  196. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +1 -1
  197. data/lib/rails_generator/generators/components/performance_test/USAGE +8 -0
  198. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +16 -0
  199. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +9 -0
  200. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +11 -11
  201. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +1 -0
  202. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +3 -0
  203. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +4 -4
  204. data/lib/rails_generator/generators/components/resource/resource_generator.rb +2 -2
  205. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +1 -1
  206. data/lib/rails_generator/generators/components/scaffold/USAGE +9 -5
  207. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +10 -3
  208. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +7 -7
  209. data/lib/rails_generator/scripts.rb +1 -1
  210. data/lib/rails_generator/scripts/destroy.rb +6 -7
  211. data/lib/rails_generator/secret_key_generator.rb +5 -147
  212. data/lib/tasks/annotations.rake +8 -11
  213. data/lib/tasks/databases.rake +42 -15
  214. data/lib/tasks/documentation.rake +15 -0
  215. data/lib/tasks/framework.rake +5 -1
  216. data/lib/tasks/gems.rake +24 -8
  217. data/lib/tasks/misc.rake +3 -4
  218. data/lib/tasks/testing.rake +25 -4
  219. data/lib/test_help.rb +1 -2
  220. data/lib/webrick_server.rb +2 -11
  221. metadata +165 -9
@@ -45,7 +45,7 @@ module Rails
45
45
  usage = "\nInstalled Generators\n"
46
46
  Rails::Generator::Base.sources.inject([]) do |mem, source|
47
47
  # Using an association list instead of a hash to preserve order,
48
- # for esthetic reasons more than anything else.
48
+ # for aesthetic reasons more than anything else.
49
49
  label = source.label.to_s.capitalize
50
50
  pair = mem.assoc(label)
51
51
  mem << (pair = [label, []]) if pair.nil?
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../scripts'
3
3
  module Rails::Generator::Scripts
4
4
  class Destroy < Base
5
5
  mandatory_options :command => :destroy
6
-
6
+
7
7
  protected
8
8
  def usage_message
9
9
  usage = "\nInstalled Generators\n"
@@ -15,14 +15,13 @@ module Rails::Generator::Scripts
15
15
 
16
16
  usage << <<end_blurb
17
17
 
18
- This script will destroy all files created by the corresponding
19
- script/generate command. For instance, script/destroy migration CreatePost
20
- will delete the appropriate ###_create_post.rb file in db/migrate, while
21
- script/destroy scaffold Post will delete the posts controller and
18
+ script/generate command. For instance, 'script/destroy migration CreatePost'
19
+ will delete the appropriate XXX_create_post.rb migration file in db/migrate,
20
+ while 'script/destroy scaffold Post' will delete the posts controller and
22
21
  views, post model and migration, all associated tests, and the map.resources
23
22
  :posts line in config/routes.rb.
24
-
25
- For instructions on finding new generators, run script/generate
23
+
24
+ For instructions on finding new generators, run script/generate.
26
25
  end_blurb
27
26
  return usage
28
27
  end
@@ -5,160 +5,18 @@ module Rails
5
5
  #
6
6
  # generator = Rails::SecretKeyGenerator("some unique identifier, such as the application name")
7
7
  # generator.generate_secret # => "f3f1be90053fa851... (some long string)"
8
+ #
9
+ # This class is *deprecated* in Rails 2.2 in favor of ActiveSupport::SecureRandom.
10
+ # It is currently a wrapper around ActiveSupport::SecureRandom.
8
11
  class SecretKeyGenerator
9
- GENERATORS = [ :secure_random, :win32_api, :urandom, :openssl, :prng ].freeze
10
-
11
12
  def initialize(identifier)
12
- @identifier = identifier
13
13
  end
14
14
 
15
15
  # Generate a random secret key with the best possible method available on
16
16
  # the current platform.
17
17
  def generate_secret
18
- generator = GENERATORS.find do |g|
19
- self.class.send("supports_#{g}?")
20
- end
21
- send("generate_secret_with_#{generator}")
22
- end
23
-
24
- # Generate a random secret key by using the Win32 API. Raises LoadError
25
- # if the current platform cannot make use of the Win32 API. Raises
26
- # SystemCallError if some other error occured.
27
- def generate_secret_with_win32_api
28
- # Following code is based on David Garamond's GUID library for Ruby.
29
- require 'Win32API'
30
-
31
- crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext",
32
- 'PPPII', 'L')
33
- crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom",
34
- 'LIP', 'L')
35
- crypt_release_context = Win32API.new("advapi32", "CryptReleaseContext",
36
- 'LI', 'L')
37
- prov_rsa_full = 1
38
- crypt_verifycontext = 0xF0000000
39
-
40
- hProvStr = " " * 4
41
- if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full,
42
- crypt_verifycontext) == 0
43
- raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}"
44
- end
45
- hProv, = hProvStr.unpack('L')
46
- bytes = " " * 64
47
- if crypt_gen_random.call(hProv, bytes.size, bytes) == 0
48
- raise SystemCallError, "CryptGenRandom failed: #{lastWin32ErrorMessage}"
49
- end
50
- if crypt_release_context.call(hProv, 0) == 0
51
- raise SystemCallError, "CryptReleaseContext failed: #{lastWin32ErrorMessage}"
52
- end
53
- bytes.unpack("H*")[0]
54
- end
55
-
56
- # Generate a random secret key with Ruby 1.9's SecureRandom module.
57
- # Raises LoadError if the current Ruby version does not support
58
- # SecureRandom.
59
- def generate_secret_with_secure_random
60
- require 'securerandom'
61
- return SecureRandom.hex(64)
62
- end
63
-
64
- # Generate a random secret key with OpenSSL. If OpenSSL is not
65
- # already loaded, then this method will attempt to load it.
66
- # LoadError will be raised if that fails.
67
- def generate_secret_with_openssl
68
- require 'openssl'
69
- if !File.exist?("/dev/urandom")
70
- # OpenSSL transparently seeds the random number generator with
71
- # data from /dev/urandom. On platforms where that is not
72
- # available, such as Windows, we have to provide OpenSSL with
73
- # our own seed. Unfortunately there's no way to provide a
74
- # secure seed without OS support, so we'll have to do with
75
- # rand() and Time.now.usec().
76
- OpenSSL::Random.seed(rand(0).to_s + Time.now.usec.to_s)
77
- end
78
- data = OpenSSL::BN.rand(2048, -1, false).to_s
79
-
80
- if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00908000
81
- OpenSSL::Digest::SHA512.new(data).hexdigest
82
- else
83
- generate_secret_with_prng
84
- end
18
+ ActiveSupport::SecureRandom.hex(64)
85
19
  end
86
-
87
- # Generate a random secret key with /dev/urandom.
88
- # Raises SystemCallError on failure.
89
- def generate_secret_with_urandom
90
- return File.read("/dev/urandom", 64).unpack("H*")[0]
91
- end
92
-
93
- # Generate a random secret key with Ruby's pseudo random number generator,
94
- # as well as some environment information.
95
- #
96
- # This is the least cryptographically secure way to generate a secret key,
97
- # and should be avoided whenever possible.
98
- def generate_secret_with_prng
99
- require 'digest/sha2'
100
- sha = Digest::SHA2.new(512)
101
- now = Time.now
102
- sha << now.to_s
103
- sha << String(now.usec)
104
- sha << String(rand(0))
105
- sha << String($$)
106
- sha << @identifier
107
- return sha.hexdigest
108
- end
109
-
110
- private
111
- def lastWin32ErrorMessage
112
- # Following code is based on David Garamond's GUID library for Ruby.
113
- get_last_error = Win32API.new("kernel32", "GetLastError", '', 'L')
114
- format_message = Win32API.new("kernel32", "FormatMessageA",
115
- 'LPLLPLPPPPPPPP', 'L')
116
- format_message_ignore_inserts = 0x00000200
117
- format_message_from_system = 0x00001000
118
-
119
- code = get_last_error.call
120
- msg = "\0" * 1024
121
- len = format_message.call(format_message_ignore_inserts +
122
- format_message_from_system, 0,
123
- code, 0, msg, 1024, nil, nil,
124
- nil, nil, nil, nil, nil, nil)
125
- msg[0, len].tr("\r", '').chomp
126
- end
127
-
128
- def self.supports_secure_random?
129
- begin
130
- require 'securerandom'
131
- true
132
- rescue LoadError
133
- false
134
- end
135
- end
136
-
137
- def self.supports_win32_api?
138
- return false unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
139
- begin
140
- require 'Win32API'
141
- true
142
- rescue LoadError
143
- false
144
- end
145
- end
146
-
147
- def self.supports_urandom?
148
- File.exist?('/dev/urandom')
149
- end
150
-
151
- def self.supports_openssl?
152
- begin
153
- require 'openssl'
154
- true
155
- rescue LoadError
156
- false
157
- end
158
- end
159
-
160
- def self.supports_prng?
161
- true
162
- end
20
+ deprecate :generate_secret=>"You should use ActiveSupport::SecureRandom.hex(64)"
163
21
  end
164
22
  end
@@ -6,18 +6,15 @@ task :notes do
6
6
  end
7
7
 
8
8
  namespace :notes do
9
- desc "Enumerate all OPTIMIZE annotations"
10
- task :optimize do
11
- SourceAnnotationExtractor.enumerate "OPTIMIZE"
9
+ ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
10
+ desc "Enumerate all #{annotation} annotations"
11
+ task annotation.downcase.intern do
12
+ SourceAnnotationExtractor.enumerate annotation
13
+ end
12
14
  end
13
15
 
14
- desc "Enumerate all FIXME annotations"
15
- task :fixme do
16
- SourceAnnotationExtractor.enumerate "FIXME"
17
- end
18
-
19
- desc "Enumerate all TODO annotations"
20
- task :todo do
21
- SourceAnnotationExtractor.enumerate "TODO"
16
+ desc "Enumerate a custom annotation, specify with ANNOTATION=WTFHAX"
17
+ task :custom do
18
+ SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
22
19
  end
23
20
  end
@@ -28,8 +28,24 @@ namespace :db do
28
28
 
29
29
  def create_database(config)
30
30
  begin
31
- ActiveRecord::Base.establish_connection(config)
32
- ActiveRecord::Base.connection
31
+ if config['adapter'] =~ /sqlite/
32
+ if File.exist?(config['database'])
33
+ $stderr.puts "#{config['database']} already exists"
34
+ else
35
+ begin
36
+ # Create the SQLite database
37
+ ActiveRecord::Base.establish_connection(config)
38
+ ActiveRecord::Base.connection
39
+ rescue
40
+ $stderr.puts $!, *($!.backtrace)
41
+ $stderr.puts "Couldn't create database for #{config.inspect}"
42
+ end
43
+ end
44
+ return # Skip the else clause of begin/rescue
45
+ else
46
+ ActiveRecord::Base.establish_connection(config)
47
+ ActiveRecord::Base.connection
48
+ end
33
49
  rescue
34
50
  case config['adapter']
35
51
  when 'mysql'
@@ -52,10 +68,6 @@ namespace :db do
52
68
  $stderr.puts $!, *($!.backtrace)
53
69
  $stderr.puts "Couldn't create database for #{config.inspect}"
54
70
  end
55
- when 'sqlite'
56
- `sqlite "#{config['database']}"`
57
- when 'sqlite3'
58
- `sqlite3 "#{config['database']}"`
59
71
  end
60
72
  else
61
73
  $stderr.puts "#{config['database']} already exists"
@@ -101,8 +113,16 @@ namespace :db do
101
113
  end
102
114
 
103
115
  namespace :migrate do
104
- desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x'
105
- task :redo => [ 'db:rollback', 'db:migrate' ]
116
+ desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
117
+ task :redo => :environment do
118
+ if ENV["VERSION"]
119
+ Rake::Task["db:migrate:down"].invoke
120
+ Rake::Task["db:migrate:up"].invoke
121
+ else
122
+ Rake::Task["db:rollback"].invoke
123
+ Rake::Task["db:migrate"].invoke
124
+ end
125
+ end
106
126
 
107
127
  desc 'Resets your database using your migrations for the current environment'
108
128
  task :reset => ["db:drop", "db:create", "db:migrate"]
@@ -141,6 +161,9 @@ namespace :db do
141
161
  when 'mysql'
142
162
  ActiveRecord::Base.establish_connection(config)
143
163
  puts ActiveRecord::Base.connection.charset
164
+ when 'postgresql'
165
+ ActiveRecord::Base.establish_connection(config)
166
+ puts ActiveRecord::Base.connection.encoding
144
167
  else
145
168
  puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
146
169
  end
@@ -179,16 +202,19 @@ namespace :db do
179
202
  end
180
203
 
181
204
  namespace :fixtures do
182
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
205
+ desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
183
206
  task :load => :environment do
184
207
  require 'active_record/fixtures'
185
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
186
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
187
- Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
208
+ ActiveRecord::Base.establish_connection(Rails.env)
209
+ base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
210
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
211
+
212
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
213
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
188
214
  end
189
215
  end
190
216
 
191
- desc "Search for a fixture given a LABEL or ID."
217
+ desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
192
218
  task :identify => :environment do
193
219
  require "active_record/fixtures"
194
220
 
@@ -197,7 +223,8 @@ namespace :db do
197
223
 
198
224
  puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label
199
225
 
200
- Dir["#{RAILS_ROOT}/test/fixtures/**/*.yml"].each do |file|
226
+ base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
227
+ Dir["#{base_dir}/**/*.yml"].each do |file|
201
228
  if data = YAML::load(ERB.new(IO.read(file)).result)
202
229
  data.keys.each do |key|
203
230
  key_id = Fixtures.identify(key)
@@ -314,7 +341,7 @@ namespace :db do
314
341
  case abcs["test"]["adapter"]
315
342
  when "mysql"
316
343
  ActiveRecord::Base.establish_connection(:test)
317
- ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
344
+ ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"], abcs["test"])
318
345
  when "postgresql"
319
346
  ActiveRecord::Base.clear_active_connections!
320
347
  drop_database(abcs['test'])
@@ -52,9 +52,23 @@ namespace :doc do
52
52
  rm_rf 'doc/plugins' rescue nil
53
53
  end
54
54
 
55
+ desc "Generate Rails guides"
56
+ task :guides do
57
+ source = File.join(RAILTIES_PATH, "doc/guides")
58
+ destination = File.join(RAILS_ROOT, "doc/guides")
59
+ FileUtils.rm_r(destination) if File.directory?(destination)
60
+ FileUtils.mkdir(destination)
61
+
62
+ FileUtils.cp_r File.join(source, 'html/.'), File.join(destination)
63
+ # Copy images and css files to html directory. These dirs are in .gitigore and shouldn't be source controlled.
64
+ FileUtils.cp_r File.join(source, 'source/images'), File.join(destination)
65
+ FileUtils.cp_r File.join(source, 'source/stylesheets'), File.join(destination, 'stylesheets')
66
+ end
67
+
55
68
  namespace :plugins do
56
69
  # Define doc tasks for each plugin
57
70
  plugins.each do |plugin|
71
+ desc "Generate documentation for the #{plugin} plugin"
58
72
  task(plugin => :environment) do
59
73
  plugin_base = "vendor/plugins/#{plugin}"
60
74
  options = []
@@ -62,6 +76,7 @@ namespace :doc do
62
76
  options << "-o doc/plugins/#{plugin}"
63
77
  options << "--title '#{plugin.titlecase} Plugin Documentation'"
64
78
  options << '--line-numbers' << '--inline-source'
79
+ options << '--charset' << 'utf-8'
65
80
  options << '-T html'
66
81
 
67
82
  files.include("#{plugin_base}/lib/**/*.rb")
@@ -5,7 +5,6 @@ namespace :rails do
5
5
  deps = %w(actionpack activerecord actionmailer activesupport activeresource)
6
6
  require 'rubygems'
7
7
  require 'rubygems/gem_runner'
8
- Gem.manage_gems
9
8
 
10
9
  rails = (version = ENV['VERSION']) ?
11
10
  Gem.cache.find_name('rails', "= #{version}").first :
@@ -43,9 +42,12 @@ namespace :rails do
43
42
  require 'open-uri'
44
43
  version = ENV["RELEASE"] || "edge"
45
44
  target = "rails_#{version}.zip"
45
+ commits = "http://github.com/api/v1/yaml/rails/rails/commits/master"
46
46
  url = "http://dev.rubyonrails.org/archives/#{target}"
47
47
 
48
48
  chdir 'vendor' do
49
+ latest_revision = YAML.load(open(commits))["commits"].first["id"]
50
+
49
51
  puts "Downloading Rails from #{url}"
50
52
  File.open('rails.zip', 'wb') do |dst|
51
53
  open url do |src|
@@ -61,6 +63,8 @@ namespace :rails do
61
63
  %w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
62
64
  rm_f goner
63
65
  end
66
+
67
+ touch "rails/REVISION_#{latest_revision}"
64
68
  end
65
69
 
66
70
  puts 'Updating current scripts, javascripts, and configuration settings'
@@ -1,12 +1,18 @@
1
1
  desc "List the gems that this rails application depends on"
2
2
  task :gems => 'gems:base' do
3
3
  Rails.configuration.gems.each do |gem|
4
- code = gem.loaded? ? (gem.frozen? ? "F" : "I") : " "
5
- puts "[#{code}] #{gem.name} #{gem.requirement.to_s}"
4
+ print_gem_status(gem)
6
5
  end
7
6
  puts
8
7
  puts "I = Installed"
9
8
  puts "F = Frozen"
9
+ puts "R = Framework (loaded before rails starts)"
10
+ end
11
+
12
+ def print_gem_status(gem, indent=1)
13
+ code = gem.loaded? ? (gem.frozen? ? (gem.framework_gem? ? "R" : "F") : "I") : " "
14
+ puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}"
15
+ gem.dependencies.each { |g| print_gem_status(g, indent+1)} if gem.loaded?
10
16
  end
11
17
 
12
18
  namespace :gems do
@@ -19,7 +25,7 @@ namespace :gems do
19
25
  task :build do
20
26
  $rails_gem_installer = true
21
27
  require 'rails/gem_builder'
22
- Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*')].each do |gem_dir|
28
+ Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |gem_dir|
23
29
  spec_file = File.join(gem_dir, '.specification')
24
30
  next unless File.exists?(spec_file)
25
31
  specification = YAML::load_file(spec_file)
@@ -28,7 +34,7 @@ namespace :gems do
28
34
  puts "Built gem: '#{gem_dir}'"
29
35
  end
30
36
  end
31
-
37
+
32
38
  desc "Installs all required gems for this application."
33
39
  task :install => :base do
34
40
  require 'rubygems'
@@ -42,10 +48,10 @@ namespace :gems do
42
48
  require 'rubygems/gem_runner'
43
49
  Rails.configuration.gems.each do |gem|
44
50
  next unless !gem.frozen? && (ENV['GEM'].blank? || ENV['GEM'] == gem.name)
45
- gem.unpack_to(File.join(RAILS_ROOT, 'vendor', 'gems')) if gem.loaded?
51
+ gem.unpack_to(Rails::GemDependency.unpacked_path) if gem.loaded?
46
52
  end
47
53
  end
48
-
54
+
49
55
  namespace :unpack do
50
56
  desc "Unpacks the specified gems and its dependencies into vendor/gems"
51
57
  task :dependencies => :unpack do
@@ -54,11 +60,21 @@ namespace :gems do
54
60
  Rails.configuration.gems.each do |gem|
55
61
  next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name
56
62
  gem.dependencies.each do |dependency|
57
- dependency.add_load_paths # double check that we have not already unpacked
58
63
  next if dependency.frozen?
59
- dependency.unpack_to(File.join(RAILS_ROOT, 'vendor', 'gems'))
64
+ dependency.unpack_to(Rails::GemDependency.unpacked_path)
60
65
  end
61
66
  end
62
67
  end
63
68
  end
69
+
70
+ desc "Regenerate gem specifications in correct format."
71
+ task :refresh_specs => :base do
72
+ require 'rubygems'
73
+ require 'rubygems/gem_runner'
74
+ Rails::VendorGemSourceIndex.silence_spec_warnings = true
75
+ Rails.configuration.gems.each do |gem|
76
+ next unless gem.frozen? && (ENV['GEM'].blank? || ENV['GEM'] == gem.name)
77
+ gem.refresh_spec(Rails::GemDependency.unpacked_path) if gem.loaded?
78
+ end
79
+ end
64
80
  end