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
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -169,35 +169,29 @@ HELP
169
169
  # Ruby or Rails. In the future, expand to check other namespaces
170
170
  # such as the rest of the user's app.
171
171
  def class_collisions(*class_names)
172
-
173
- # Initialize some check varibles
174
- last_class = Object
175
- current_class = nil
176
- name = nil
177
-
172
+ path = class_names.shift
178
173
  class_names.flatten.each do |class_name|
179
174
  # Convert to string to allow symbol arguments.
180
175
  class_name = class_name.to_s
181
176
 
182
177
  # Skip empty strings.
183
- class_name.strip.empty? ? next : current_class = class_name
178
+ next if class_name.strip.empty?
184
179
 
185
180
  # Split the class from its module nesting.
186
181
  nesting = class_name.split('::')
187
182
  name = nesting.pop
188
183
 
189
184
  # Extract the last Module in the nesting.
190
- last = nesting.inject(last_class) { |last, nest|
191
- break unless last_class.const_defined?(nest)
192
- last_class = last_class.const_get(nest)
185
+ last = nesting.inject(Object) { |last, nest|
186
+ break unless last.const_defined?(nest)
187
+ last.const_get(nest)
193
188
  }
194
189
 
195
- end
196
- # If the last Module exists, check whether the given
197
- # class exists and raise a collision if so.
198
-
199
- if last_class and last_class.const_defined?(name.camelize)
200
- raise_class_collision(current_class)
190
+ # If the last Module exists, check whether the given
191
+ # class exists and raise a collision if so.
192
+ if last and last.const_defined?(name.camelize)
193
+ raise_class_collision(class_name)
194
+ end
201
195
  end
202
196
  end
203
197
 
@@ -37,6 +37,10 @@ module Rails
37
37
  ""
38
38
  end
39
39
  end
40
+
41
+ def reference?
42
+ [ :references, :belongs_to ].include?(self.type)
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -1,12 +1,12 @@
1
1
  require 'rbconfig'
2
2
  require 'digest/md5'
3
- require 'rails_generator/secret_key_generator'
3
+ require 'active_support/secure_random'
4
4
 
5
5
  class AppGenerator < Rails::Generator::Base
6
6
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
7
7
  Config::CONFIG['ruby_install_name'])
8
8
 
9
- DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase)
9
+ DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db)
10
10
  DEFAULT_DATABASE = 'sqlite3'
11
11
 
12
12
  default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
@@ -36,7 +36,7 @@ class AppGenerator < Rails::Generator::Base
36
36
  md5 << @app_name
37
37
 
38
38
  # Do our best to generate a secure secret key for CookieStore
39
- secret = Rails::SecretKeyGenerator.new(@app_name).generate_secret
39
+ secret = ActiveSupport::SecureRandom.hex(64)
40
40
 
41
41
  record do |m|
42
42
  # Root directory and all subdirectories.
@@ -51,6 +51,7 @@ class AppGenerator < Rails::Generator::Base
51
51
  m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest }
52
52
  m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
53
53
  m.template "helpers/test_helper.rb", "test/test_helper.rb"
54
+ m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb"
54
55
 
55
56
  # database.yml and routes.rb
56
57
  m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
@@ -64,6 +65,9 @@ class AppGenerator < Rails::Generator::Base
64
65
  m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
65
66
  m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb"
66
67
 
68
+ # Locale
69
+ m.template "configs/locales/en.yml", "config/locales/en.yml"
70
+
67
71
  # Environments
68
72
  m.file "environments/boot.rb", "config/boot.rb"
69
73
  m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret }
@@ -142,6 +146,7 @@ class AppGenerator < Rails::Generator::Base
142
146
  app/views/layouts
143
147
  config/environments
144
148
  config/initializers
149
+ config/locales
145
150
  db
146
151
  doc
147
152
  lib
@@ -155,6 +160,7 @@ class AppGenerator < Rails::Generator::Base
155
160
  test/fixtures
156
161
  test/functional
157
162
  test/integration
163
+ test/performance
158
164
  test/unit
159
165
  vendor
160
166
  vendor/plugins
@@ -2,7 +2,7 @@ class ControllerGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  # Check for class naming collisions.
5
- m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
5
+ m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
6
6
 
7
7
  # Controller, helper, views, and test directories.
8
8
  m.directory File.join('app/controllers', class_path)
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class <%= class_name %>ControllerTest < ActionController::TestCase
4
4
  # Replace this with your real tests.
5
- def test_truth
5
+ test "the truth" do
6
6
  assert true
7
7
  end
8
8
  end
@@ -4,7 +4,7 @@ class IntegrationTestGenerator < Rails::Generator::NamedBase
4
4
  def manifest
5
5
  record do |m|
6
6
  # Check for class naming collisions.
7
- m.class_collisions class_path, class_name, "#{class_name}Test"
7
+ m.class_collisions class_name, "#{class_name}Test"
8
8
 
9
9
  # integration test directory
10
10
  m.directory File.join('test/integration', class_path)
@@ -1,10 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class <%= class_name %>Test < ActionController::IntegrationTest
4
- # fixtures :your, :models
4
+ fixtures :all
5
5
 
6
6
  # Replace this with your real tests.
7
- def test_truth
7
+ test "the truth" do
8
8
  assert true
9
9
  end
10
10
  end
@@ -2,7 +2,7 @@ class MailerGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  # Check for class naming collisions.
5
- m.class_collisions class_path, class_name, "#{class_name}Test"
5
+ m.class_collisions class_name, "#{class_name}Test"
6
6
 
7
7
  # Mailer, view, test, and fixture directories.
8
8
  m.directory File.join('app/models', class_path)
@@ -1,9 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class <%= class_name %>Test < ActionMailer::TestCase
4
- tests <%= class_name %>
5
4
  <% for action in actions -%>
6
- def test_<%= action %>
5
+ test "<%= action %>" do
7
6
  @expected.subject = '<%= class_name %>#<%= action %>'
8
7
  @expected.body = read_fixture('<%= action %>')
9
8
  @expected.date = Time.now
@@ -14,7 +13,7 @@ class <%= class_name %>Test < ActionMailer::TestCase
14
13
  <% end -%>
15
14
  <% if actions.blank? -%>
16
15
  # replace this with your real tests
17
- def test_truth
16
+ test "the truth" do
18
17
  assert true
19
18
  end
20
19
  <% end -%>
@@ -4,7 +4,7 @@ class ModelGenerator < Rails::Generator::NamedBase
4
4
  def manifest
5
5
  record do |m|
6
6
  # Check for class naming collisions.
7
- m.class_collisions class_path, class_name, "#{class_name}Test"
7
+ m.class_collisions class_name, "#{class_name}Test"
8
8
 
9
9
  # Model, test, and fixture directories.
10
10
  m.directory File.join('app/models', class_path)
@@ -1,2 +1,5 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
+ <% attributes.select(&:reference?).each do |attribute| -%>
3
+ belongs_to :<%= attribute.name %>
4
+ <% end -%>
2
5
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class <%= class_name %>Test < ActiveSupport::TestCase
4
4
  # Replace this with your real tests.
5
- def test_truth
5
+ test "the truth" do
6
6
  assert true
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ class ObserverGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  # Check for class naming collisions.
5
- m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
5
+ m.class_collisions "#{class_name}Observer", "#{class_name}ObserverTest"
6
6
 
7
7
  # Observer, and test directories.
8
8
  m.directory File.join('app/models', class_path)
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class <%= class_name %>ObserverTest < ActiveSupport::TestCase
4
4
  # Replace this with your real tests.
5
- def test_truth
5
+ test "the truth" do
6
6
  assert true
7
7
  end
8
8
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Stubs out a new performance test. Pass the name of the test, either
3
+ CamelCased or under_scored, as an argument. The new test class is
4
+ generated in test/performance/testname_test.rb
5
+
6
+ Example:
7
+ `./script/generate performance_test GeneralStories` creates a GeneralStories
8
+ performance test in test/performance/general_stories_test.rb
@@ -0,0 +1,16 @@
1
+ class PerformanceTestGenerator < 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_name, "#{class_name}Test"
8
+
9
+ # performance test directory
10
+ m.directory File.join('test/performance', class_path)
11
+
12
+ # performance test stub
13
+ m.template 'performance_test.rb', File.join('test/performance', class_path, "#{file_name}_test.rb")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ class <%= class_name %>Test < ActionController::PerformanceTest
5
+ # Replace this with your real tests.
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -10,22 +10,22 @@ class PluginGenerator < Rails::Generator::NamedBase
10
10
  def manifest
11
11
  record do |m|
12
12
  # Check for class naming collisions.
13
- m.class_collisions class_path, class_name
13
+ m.class_collisions class_name
14
14
 
15
15
  m.directory "#{plugin_path}/lib"
16
16
  m.directory "#{plugin_path}/tasks"
17
17
  m.directory "#{plugin_path}/test"
18
18
 
19
- m.template 'README', "#{plugin_path}/README"
20
- m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE"
21
- m.template 'Rakefile', "#{plugin_path}/Rakefile"
22
- m.template 'init.rb', "#{plugin_path}/init.rb"
23
- m.template 'install.rb', "#{plugin_path}/install.rb"
24
- m.template 'uninstall.rb', "#{plugin_path}/uninstall.rb"
25
- m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb"
26
- m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake"
27
- m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb"
28
-
19
+ m.template 'README', "#{plugin_path}/README"
20
+ m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE"
21
+ m.template 'Rakefile', "#{plugin_path}/Rakefile"
22
+ m.template 'init.rb', "#{plugin_path}/init.rb"
23
+ m.template 'install.rb', "#{plugin_path}/install.rb"
24
+ m.template 'uninstall.rb', "#{plugin_path}/uninstall.rb"
25
+ m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb"
26
+ m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake"
27
+ m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb"
28
+ m.template 'test_helper.rb', "#{plugin_path}/test/test_helper.rb"
29
29
  if @with_generator
30
30
  m.directory "#{plugin_path}/generators"
31
31
  m.directory "#{plugin_path}/generators/#{file_name}"
@@ -8,6 +8,7 @@ task :default => :test
8
8
  desc 'Test the <%= file_name %> plugin.'
9
9
  Rake::TestTask.new(:test) do |t|
10
10
  t.libs << 'lib'
11
+ t.libs << 'test'
11
12
  t.pattern = 'test/**/*_test.rb'
12
13
  t.verbose = true
13
14
  end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
@@ -1,8 +1,8 @@
1
- require 'test/unit'
1
+ require 'test_helper'
2
2
 
3
- class <%= class_name %>Test < Test::Unit::TestCase
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
4
  # Replace this with your real tests.
5
- def test_this_plugin
6
- flunk
5
+ test "the truth" do
6
+ assert true
7
7
  end
8
8
  end
@@ -30,8 +30,8 @@ class ResourceGenerator < Rails::Generator::NamedBase
30
30
  def manifest
31
31
  record do |m|
32
32
  # Check for class naming collisions.
33
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
34
- m.class_collisions(class_path, "#{class_name}")
33
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
34
+ m.class_collisions(class_name)
35
35
 
36
36
  # Controller, helper, views, and test directories.
37
37
  m.directory(File.join('app/models', class_path))
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
4
  # Replace this with your real tests.
5
- def test_truth
5
+ test "the truth" do
6
6
  assert true
7
7
  end
8
8
  end
@@ -1,10 +1,11 @@
1
1
  Description:
2
2
  Scaffolds an entire resource, from model and migration to controller and
3
3
  views, along with a full test suite. The resource is ready to use as a
4
- starting point for your restful, resource-oriented application.
4
+ starting point for your RESTful, resource-oriented application.
5
5
 
6
- Pass the name of the model, either CamelCased or under_scored, as the first
7
- argument, and an optional list of attribute pairs.
6
+ Pass the name of the model (in singular form), either CamelCased or
7
+ under_scored, as the first argument, and an optional list of attribute
8
+ pairs.
8
9
 
9
10
  Attribute pairs are column_name:sql_type arguments specifying the
10
11
  model's attributes. Timestamps are added by default, so you don't have to
@@ -13,13 +14,16 @@ Description:
13
14
  You don't have to think up every attribute up front, but it helps to
14
15
  sketch out a few so you can start working with the resource immediately.
15
16
 
16
- For example, `scaffold post title:string body:text published:boolean`
17
+ For example, 'scaffold post title:string body:text published:boolean'
17
18
  gives you a model with those three attributes, a controller that handles
18
19
  the create/show/update/destroy, forms to create and edit your posts, and
19
20
  an index that lists them all, as well as a map.resources :posts
20
21
  declaration in config/routes.rb.
21
22
 
23
+ If you want to remove all the generated files, run
24
+ 'script/destroy scaffold ModelName'.
25
+
22
26
  Examples:
23
- `./script/generate scaffold post` # no attributes, view will be anemic
27
+ `./script/generate scaffold post`
24
28
  `./script/generate scaffold post title:string body:text published:boolean`
25
29
  `./script/generate scaffold purchase order_id:integer amount:decimal`
@@ -1,5 +1,5 @@
1
1
  class ScaffoldGenerator < Rails::Generator::NamedBase
2
- default_options :skip_timestamps => false, :skip_migration => false
2
+ default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false
3
3
 
4
4
  attr_reader :controller_name,
5
5
  :controller_class_path,
@@ -16,6 +16,11 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
16
16
  def initialize(runtime_args, runtime_options = {})
17
17
  super
18
18
 
19
+ if @name == @name.pluralize && !options[:force_plural]
20
+ logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
21
+ @name = @name.singularize
22
+ end
23
+
19
24
  @controller_name = @name.pluralize
20
25
 
21
26
  base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
@@ -31,8 +36,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
31
36
  def manifest
32
37
  record do |m|
33
38
  # Check for class naming collisions.
34
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
35
- m.class_collisions(class_path, "#{class_name}")
39
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
40
+ m.class_collisions(class_name)
36
41
 
37
42
  # Controller, helper, views, test and stylesheets directories.
38
43
  m.directory(File.join('app/models', class_path))
@@ -81,6 +86,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
81
86
  "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
82
87
  opt.on("--skip-migration",
83
88
  "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
89
+ opt.on("--force-plural",
90
+ "Forces the generation of a plural ModelName") { |v| options[:force_plural] = v }
84
91
  end
85
92
 
86
93
  def scaffold_views
@@ -1,18 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
- def test_should_get_index
4
+ test "should get index" do
5
5
  get :index
6
6
  assert_response :success
7
7
  assert_not_nil assigns(:<%= table_name %>)
8
8
  end
9
9
 
10
- def test_should_get_new
10
+ test "should get new" do
11
11
  get :new
12
12
  assert_response :success
13
13
  end
14
14
 
15
- def test_should_create_<%= file_name %>
15
+ test "should create <%= file_name %>" do
16
16
  assert_difference('<%= class_name %>.count') do
17
17
  post :create, :<%= file_name %> => { }
18
18
  end
@@ -20,22 +20,22 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
20
20
  assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
21
21
  end
22
22
 
23
- def test_should_show_<%= file_name %>
23
+ test "should show <%= file_name %>" do
24
24
  get :show, :id => <%= table_name %>(:one).id
25
25
  assert_response :success
26
26
  end
27
27
 
28
- def test_should_get_edit
28
+ test "should get edit" do
29
29
  get :edit, :id => <%= table_name %>(:one).id
30
30
  assert_response :success
31
31
  end
32
32
 
33
- def test_should_update_<%= file_name %>
33
+ test "should update <%= file_name %>" do
34
34
  put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
35
35
  assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
36
36
  end
37
37
 
38
- def test_should_destroy_<%= file_name %>
38
+ test "should destroy <%= file_name %>" do
39
39
  assert_difference('<%= class_name %>.count', -1) do
40
40
  delete :destroy, :id => <%= table_name %>(:one).id
41
41
  end