rails 1.2.6 → 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.

Files changed (148) hide show
  1. data/CHANGELOG +491 -12
  2. data/MIT-LICENSE +1 -1
  3. data/README +17 -25
  4. data/Rakefile +41 -18
  5. data/bin/about +1 -1
  6. data/bin/console +1 -1
  7. data/bin/destroy +1 -1
  8. data/bin/generate +1 -1
  9. data/bin/performance/request +3 -0
  10. data/bin/plugin +1 -1
  11. data/bin/runner +1 -1
  12. data/bin/server +1 -1
  13. data/builtin/rails_info/rails/info.rb +2 -2
  14. data/configs/apache.conf +1 -1
  15. data/configs/databases/mysql.yml +9 -3
  16. data/configs/databases/postgresql.yml +16 -12
  17. data/configs/initializers/inflections.rb +10 -0
  18. data/configs/initializers/mime_types.rb +5 -0
  19. data/configs/routes.rb +23 -11
  20. data/doc/README_FOR_APP +1 -1
  21. data/environments/boot.rb +95 -26
  22. data/environments/development.rb +2 -5
  23. data/environments/environment.rb +24 -25
  24. data/environments/test.rb +4 -1
  25. data/helpers/application.rb +5 -2
  26. data/helpers/test_helper.rb +10 -0
  27. data/html/422.html +30 -0
  28. data/html/500.html +1 -1
  29. data/html/index.html +2 -2
  30. data/html/javascripts/controls.js +484 -354
  31. data/html/javascripts/dragdrop.js +88 -58
  32. data/html/javascripts/effects.js +396 -364
  33. data/html/javascripts/prototype.js +2817 -1107
  34. data/html/robots.txt +5 -1
  35. data/lib/commands/console.rb +12 -5
  36. data/lib/commands/performance/request.rb +6 -0
  37. data/lib/commands/plugin.rb +15 -10
  38. data/lib/commands/process/spawner.rb +14 -4
  39. data/lib/commands/servers/base.rb +12 -0
  40. data/lib/commands/servers/mongrel.rb +5 -1
  41. data/lib/commands/servers/webrick.rb +14 -7
  42. data/lib/console_app.rb +5 -2
  43. data/lib/console_with_helpers.rb +5 -2
  44. data/lib/dispatcher.rb +3 -151
  45. data/lib/fcgi_handler.rb +79 -81
  46. data/lib/initializer.rb +125 -169
  47. data/lib/rails/plugin.rb +84 -0
  48. data/lib/rails/plugin/loader.rb +150 -0
  49. data/lib/rails/plugin/locator.rb +78 -0
  50. data/lib/rails/version.rb +3 -3
  51. data/lib/rails_generator/base.rb +11 -9
  52. data/lib/rails_generator/commands.rb +20 -10
  53. data/lib/rails_generator/generators/applications/app/USAGE +0 -7
  54. data/lib/rails_generator/generators/applications/app/app_generator.rb +25 -6
  55. data/lib/rails_generator/generators/components/controller/USAGE +11 -12
  56. data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -2
  57. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
  58. data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
  59. data/lib/rails_generator/generators/components/integration_test/USAGE +5 -11
  60. data/lib/rails_generator/generators/components/mailer/USAGE +8 -10
  61. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +3 -3
  62. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  63. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
  64. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +8 -24
  65. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  66. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
  67. data/lib/rails_generator/generators/components/migration/USAGE +23 -8
  68. data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
  69. data/lib/rails_generator/generators/components/migration/templates/migration.rb +6 -2
  70. data/lib/rails_generator/generators/components/model/USAGE +15 -14
  71. data/lib/rails_generator/generators/components/model/model_generator.rb +10 -3
  72. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -3
  73. data/lib/rails_generator/generators/components/model/templates/migration.rb +4 -1
  74. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -3
  75. data/lib/rails_generator/generators/components/observer/USAGE +5 -7
  76. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -2
  77. data/lib/rails_generator/generators/components/plugin/USAGE +8 -18
  78. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
  79. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  80. data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
  81. data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
  82. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
  83. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
  84. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
  85. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  86. data/lib/rails_generator/generators/components/resource/resource_generator.rb +13 -15
  87. data/lib/rails_generator/generators/components/resource/templates/controller.rb +1 -1
  88. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +2 -14
  89. data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
  90. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -146
  91. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +64 -37
  92. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -80
  93. data/lib/rails_generator/generators/components/scaffold/templates/{layout.rhtml → layout.html.erb} +0 -0
  94. data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
  95. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_edit.rhtml → scaffold/templates/view_edit.html.erb} +4 -4
  96. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_index.rhtml → scaffold/templates/view_index.html.erb} +4 -4
  97. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_new.rhtml → scaffold/templates/view_new.html.erb} +3 -3
  98. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_show.rhtml → scaffold/templates/view_show.html.erb} +1 -1
  99. data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
  100. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +3 -3
  101. data/lib/rails_generator/lookup.rb +45 -10
  102. data/lib/rails_generator/scripts.rb +6 -3
  103. data/lib/rails_generator/scripts/destroy.rb +23 -0
  104. data/lib/rails_generator/secret_key_generator.rb +160 -0
  105. data/lib/rails_generator/spec.rb +1 -1
  106. data/lib/source_annotation_extractor.rb +62 -0
  107. data/lib/tasks/annotations.rake +23 -0
  108. data/lib/tasks/databases.rake +249 -83
  109. data/lib/tasks/documentation.rake +11 -13
  110. data/lib/tasks/framework.rake +1 -1
  111. data/lib/tasks/rails.rb +1 -1
  112. data/lib/tasks/testing.rake +5 -7
  113. data/lib/test_help.rb +4 -3
  114. data/lib/webrick_server.rb +3 -4
  115. metadata +31 -49
  116. data/bin/breakpointer +0 -3
  117. data/lib/binding_of_caller.rb +0 -85
  118. data/lib/breakpoint.rb +0 -553
  119. data/lib/breakpoint_client.rb +0 -196
  120. data/lib/commands/breakpointer.rb +0 -1
  121. data/lib/rails_generator/generators/components/resource/templates/USAGE +0 -18
  122. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +0 -11
  123. data/lib/rails_generator/generators/components/resource/templates/migration.rb +0 -13
  124. data/lib/rails_generator/generators/components/resource/templates/model.rb +0 -2
  125. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +0 -10
  126. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
  127. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
  128. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
  129. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
  130. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
  131. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
  132. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +0 -29
  133. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +0 -93
  134. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +0 -79
  135. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +0 -11
  136. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +0 -57
  137. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +0 -2
  138. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +0 -17
  139. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +0 -13
  140. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +0 -2
  141. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +0 -74
  142. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +0 -10
  143. data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
  144. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
  145. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
  146. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
  147. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
  148. data/lib/tasks/pre_namespace_aliases.rake +0 -53
@@ -1,30 +1,29 @@
1
1
  Description:
2
- The controller generator creates stubs for a new controller and its views.
2
+ Stubs out a new controller and its views. Pass the controller name, either
3
+ CamelCased or under_scored, and a list of views as arguments.
3
4
 
4
- The generator takes a controller name and a list of views as arguments.
5
- The controller name may be given in CamelCase or under_score and should
6
- not be suffixed with 'Controller'. To create a controller within a
7
- module, specify the controller name as 'module/controller'.
5
+ To create a controller within a module, specify the controller name as a
6
+ path like 'parent_module/controller_name'.
8
7
 
9
- The generator creates a controller class in app/controllers with view
10
- templates in app/views/controller_name, a helper class in app/helpers,
11
- and a functional test suite in test/functional.
8
+ This generates a controller class in app/controllers, view templates in
9
+ app/views/controller_name, a helper class in app/helpers, and a functional
10
+ test suite in test/functional.
12
11
 
13
12
  Example:
14
- ./script/generate controller CreditCard open debit credit close
13
+ `./script/generate controller CreditCard open debit credit close`
15
14
 
16
15
  Credit card controller with URLs like /credit_card/debit.
17
16
  Controller: app/controllers/credit_card_controller.rb
18
- Views: app/views/credit_card/debit.rhtml [...]
17
+ Views: app/views/credit_card/debit.html.erb [...]
19
18
  Helper: app/helpers/credit_card_helper.rb
20
19
  Test: test/functional/credit_card_controller_test.rb
21
20
 
22
21
  Modules Example:
23
- ./script/generate controller 'admin/credit_card' suspend late_fee
22
+ `./script/generate controller 'admin/credit_card' suspend late_fee`
24
23
 
25
24
  Credit card admin controller with URLs /admin/credit_card/suspend.
26
25
  Controller: app/controllers/admin/credit_card_controller.rb
27
- Views: app/views/admin/credit_card/debit.rhtml [...]
26
+ Views: app/views/admin/credit_card/debit.html.erb [...]
28
27
  Helper: app/helpers/admin/credit_card_helper.rb
29
28
  Test: test/functional/admin/credit_card_controller_test.rb
30
29
 
@@ -28,8 +28,8 @@ class ControllerGenerator < Rails::Generator::NamedBase
28
28
 
29
29
  # View template for each action.
30
30
  actions.each do |action|
31
- path = File.join('app/views', class_path, file_name, "#{action}.rhtml")
32
- m.template 'view.rhtml', path,
31
+ path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
32
+ m.template 'view.html.erb', path,
33
33
  :assigns => { :action => action, :path => path }
34
34
  end
35
35
  end
@@ -1,16 +1,6 @@
1
1
  require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
- require '<%= file_path %>_controller'
3
-
4
- # Re-raise errors caught by the controller.
5
- class <%= class_name %>Controller; def rescue_action(e) raise e end; end
6
-
7
- class <%= class_name %>ControllerTest < Test::Unit::TestCase
8
- def setup
9
- @controller = <%= class_name %>Controller.new
10
- @request = ActionController::TestRequest.new
11
- @response = ActionController::TestResponse.new
12
- end
13
2
 
3
+ class <%= class_name %>ControllerTest < ActionController::TestCase
14
4
  # Replace this with your real tests.
15
5
  def test_truth
16
6
  assert true
@@ -1,14 +1,8 @@
1
1
  Description:
2
- The model generator creates a stub for a new integration test.
3
-
4
- The generator takes an integration test name as its argument. The test
5
- name may be given in CamelCase or under_score and should not be suffixed
6
- with 'Test'.
7
-
8
- The generator creates an integration test class in test/integration.
2
+ Stubs out a new integration 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/integration/testname_test.rb
9
5
 
10
6
  Example:
11
- ./script/generate integration_test GeneralStories
12
-
13
- This will create a GeneralStores integration test:
14
- test/integration/general_stories_test.rb
7
+ `./script/generate integration_test GeneralStories` creates a GeneralStories
8
+ integration test in test/integration/general_stories_test.rb
@@ -1,18 +1,16 @@
1
1
  Description:
2
- The mailer generator creates stubs for a new mailer and its views.
2
+ Stubs out a new mailer and its views. Pass the mailer name, either
3
+ CamelCased or under_scored, and an optional list of emails as arguments.
3
4
 
4
- The generator takes a mailer name and a list of views as arguments.
5
- The mailer name may be given in CamelCase or under_score.
6
-
7
- The generator creates a mailer class in app/models with view templates
8
- in app/views/mailer_name, and a test suite with fixtures in test/unit.
5
+ This generates a mailer class in app/models, view templates in
6
+ app/views/mailer_name, a unit test in test/unit, and fixtures in
7
+ test/fixtures.
9
8
 
10
9
  Example:
11
- ./script/generate mailer Notifications signup forgot_password invoice
10
+ `./script/generate mailer Notifications signup forgot_password invoice`
12
11
 
13
- This will create a Notifications mailer class:
12
+ creates a Notifications mailer class, views, test, and fixtures:
14
13
  Mailer: app/models/notifications.rb
15
- Views: app/views/notifications/signup.rhtml [...]
14
+ Views: app/views/notifications/signup.erb [...]
16
15
  Test: test/unit/test/unit/notifications_test.rb
17
16
  Fixtures: test/fixtures/notifications/signup [...]
18
-
@@ -21,12 +21,12 @@ class MailerGenerator < Rails::Generator::NamedBase
21
21
  # View template and fixture for each action.
22
22
  actions.each do |action|
23
23
  relative_path = File.join(file_path, action)
24
- view_path = File.join('app/views', "#{relative_path}.rhtml")
24
+ view_path = File.join('app/views', "#{relative_path}.erb")
25
25
  fixture_path = File.join('test/fixtures', relative_path)
26
26
 
27
- m.template "view.rhtml", view_path,
27
+ m.template "view.erb", view_path,
28
28
  :assigns => { :action => action, :path => view_path }
29
- m.template "fixture.rhtml", fixture_path,
29
+ m.template "fixture.erb", fixture_path,
30
30
  :assigns => { :action => action, :path => view_path }
31
31
  end
32
32
  end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= action %>
2
+
3
+ Find me in <%= path %>
@@ -1,3 +0,0 @@
1
- <%= class_name %>#<%= action %>
2
-
3
- Find me in <%= path %>
@@ -1,21 +1,7 @@
1
1
  require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
2
 
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- FIXTURES_PATH = File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../fixtures'
5
- CHARSET = "utf-8"
6
-
7
- include ActionMailer::Quoting
8
-
9
- def setup
10
- ActionMailer::Base.delivery_method = :test
11
- ActionMailer::Base.perform_deliveries = true
12
- ActionMailer::Base.deliveries = []
13
-
14
- @expected = TMail::Mail.new
15
- @expected.set_content_type "text", "plain", { "charset" => CHARSET }
16
- @expected.mime_version = '1.0'
17
- end
18
-
3
+ class <%= class_name %>Test < ActionMailer::TestCase
4
+ tests <%= class_name %>
19
5
  <% for action in actions -%>
20
6
  def test_<%= action %>
21
7
  @expected.subject = '<%= class_name %>#<%= action %>'
@@ -26,12 +12,10 @@ class <%= class_name %>Test < Test::Unit::TestCase
26
12
  end
27
13
 
28
14
  <% end -%>
29
- private
30
- def read_fixture(action)
31
- IO.readlines("#{FIXTURES_PATH}/<%= file_path %>/#{action}")
32
- end
33
-
34
- def encode(subject)
35
- quoted_printable(subject, CHARSET)
36
- end
15
+ <% if actions.blank? -%>
16
+ # replace this with your real tests
17
+ def test_truth
18
+ assert true
19
+ end
20
+ <% end -%>
37
21
  end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= action %>
2
+
3
+ Find me in <%= path %>
@@ -1,3 +0,0 @@
1
- <%= class_name %>#<%= action %>
2
-
3
- Find me in <%= path %>
@@ -1,14 +1,29 @@
1
1
  Description:
2
- The migration generator creates a stub for a new database migration.
2
+ Stubs out a new database migration. Pass the migration name, either
3
+ CamelCased or under_scored, and an optional list of attribute pairs as arguments.
3
4
 
4
- The generator takes a migration name as its argument. The migration name may be
5
- given in CamelCase or under_score.
5
+ A migration class is generated in db/migrate prefixed by the latest migration number.
6
6
 
7
- The generator creates a migration class in db/migrate prefixed by its number
8
- in the queue.
7
+ You can name your migration in either of these formats to generate add/remove
8
+ column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
9
9
 
10
10
  Example:
11
- ./script/generate migration AddSslFlag
11
+ `./script/generate migration AddSslFlag`
12
12
 
13
- With 4 existing migrations, this will create an AddSslFlag migration in the
14
- file db/migrate/005_add_ssl_flag.rb
13
+ With 4 existing migrations, this creates the AddSslFlag migration in
14
+ db/migrate/005_add_ssl_flag.rb
15
+
16
+ `./script/generate migration AddTitleBodyToPost title:string body:text published:boolean`
17
+
18
+ This will create the AddTitleBodyToPost in db/migrate/005_add_title_body_to_post.rb with
19
+ this in the Up migration:
20
+
21
+ add_column :posts, :title, :string
22
+ add_column :posts, :body, :text
23
+ add_column :posts, :published, :boolean
24
+
25
+ And this in the Down migration:
26
+
27
+ remove_column :posts, :published
28
+ remove_column :posts, :body
29
+ remove_column :posts, :title
@@ -1,7 +1,20 @@
1
- class MigrationGenerator < Rails::Generator::NamedBase
1
+ class MigrationGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
- m.migration_template 'migration.rb', 'db/migrate'
4
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => get_local_assigns
5
5
  end
6
6
  end
7
+
8
+
9
+ private
10
+ def get_local_assigns
11
+ returning(assigns = {}) do
12
+ if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
13
+ assigns[:migration_action] = $1
14
+ assigns[:table_name] = $2.pluralize
15
+ else
16
+ assigns[:attributes] = []
17
+ end
18
+ end
19
+ end
7
20
  end
@@ -1,7 +1,11 @@
1
1
  class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
2
- def self.up
2
+ def self.up<% attributes.each do |attribute| %>
3
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%>
4
+ <%- end %>
3
5
  end
4
6
 
5
- def self.down
7
+ def self.down<% attributes.reverse.each do |attribute| %>
8
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
9
+ <%- end %>
6
10
  end
7
11
  end
@@ -1,26 +1,27 @@
1
1
  Description:
2
- The model generator creates stubs for a new model.
2
+ Stubs out a new model. Pass the model name, either CamelCased or
3
+ under_scored, and an optional list of attribute pairs as arguments.
3
4
 
4
- The generator takes a model name as its argument. The model name may be given in CamelCase or under_score and
5
- should not be suffixed with 'Model'.
5
+ Attribute pairs are column_name:sql_type arguments specifying the
6
+ model's attributes. Timestamps are added by default, so you don't have to
7
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
6
8
 
7
- As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
8
- be used to prepopulate the migration to create the table for the model and give you a set of predefined fixture.
9
- You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
10
- needed to start really working with the resource.
9
+ You don't have to think up every attribute up front, but it helps to
10
+ sketch out a few so you can start working with the model immediately.
11
11
 
12
- The generator creates a model class in app/models, a test suite in test/unit, test fixtures in
13
- test/fixtures/singular_name.yml, and a migration in db/migrate.
12
+ This generates a model class in app/models, a unit test in test/unit,
13
+ a test fixture in test/fixtures/singular_name.yml, and a migration in
14
+ db/migrate.
14
15
 
15
16
  Examples:
16
- ./script/generate model account
17
+ `./script/generate model account`
17
18
 
18
- This will create an Account model:
19
+ creates an Account model, test, fixture, and migration:
19
20
  Model: app/models/account.rb
20
21
  Test: test/unit/account_test.rb
21
22
  Fixtures: test/fixtures/accounts.yml
22
23
  Migration: db/migrate/XXX_add_accounts.rb
23
24
 
24
- ./script/generate model post title:string created_on:date body:text published:boolean
25
-
26
- Creates post model with predefined attributes.
25
+ `./script/generate model post title:string body:text published:boolean`
26
+
27
+ creates a Post model with a string title, text body, and published flag.
@@ -1,5 +1,5 @@
1
1
  class ModelGenerator < Rails::Generator::NamedBase
2
- default_options :skip_migration => false
2
+ default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => false
3
3
 
4
4
  def manifest
5
5
  record do |m|
@@ -14,7 +14,10 @@ class ModelGenerator < Rails::Generator::NamedBase
14
14
  # Model class, unit test, and fixtures.
15
15
  m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16
16
  m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
17
- m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
17
+
18
+ unless options[:skip_fixture]
19
+ m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
20
+ end
18
21
 
19
22
  unless options[:skip_migration]
20
23
  m.migration_template 'migration.rb', 'db/migrate', :assigns => {
@@ -26,13 +29,17 @@ class ModelGenerator < Rails::Generator::NamedBase
26
29
 
27
30
  protected
28
31
  def banner
29
- "Usage: #{$0} generate ModelName [field:type, field:type]"
32
+ "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
30
33
  end
31
34
 
32
35
  def add_options!(opt)
33
36
  opt.separator ''
34
37
  opt.separator 'Options:'
38
+ opt.on("--skip-timestamps",
39
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
35
40
  opt.on("--skip-migration",
36
41
  "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
42
+ opt.on("--skip-fixture",
43
+ "Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v}
37
44
  end
38
45
  end
@@ -1,11 +1,19 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ <% unless attributes.empty? -%>
2
4
  one:
3
- id: 1
4
5
  <% for attribute in attributes -%>
5
6
  <%= attribute.name %>: <%= attribute.default %>
6
7
  <% end -%>
8
+
7
9
  two:
8
- id: 2
9
10
  <% for attribute in attributes -%>
10
11
  <%= attribute.name %>: <%= attribute.default %>
11
- <% end -%>
12
+ <% end -%>
13
+ <% else -%>
14
+ # one:
15
+ # column: value
16
+ #
17
+ # two:
18
+ # column: value
19
+ <% end -%>
@@ -2,7 +2,10 @@ class <%= migration_name %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :<%= table_name %> do |t|
4
4
  <% for attribute in attributes -%>
5
- t.column :<%= attribute.name %>, :<%= attribute.type %>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ <% unless options[:skip_timestamps] %>
8
+ t.timestamps
6
9
  <% end -%>
7
10
  end
8
11
  end
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
2
 
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- fixtures :<%= table_name %>
5
-
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
6
4
  # Replace this with your real tests.
7
5
  def test_truth
8
6
  assert true
@@ -1,15 +1,13 @@
1
1
  Description:
2
- The observer generator creates stubs for a new observer.
2
+ Stubs out a new observer. Pass the observer name, either CamelCased or
3
+ under_scored, as an argument.
3
4
 
4
- The generator takes a observer name as its argument. The observer name may be
5
- given in CamelCase or under_score and should not be suffixed with 'Observer'.
6
-
7
- The generator creates a observer class in app/models and a test suite in
5
+ The generator creates an observer class in app/models and a unit test in
8
6
  test/unit.
9
7
 
10
8
  Example:
11
- ./script/generate observer Account
9
+ `./script/generate observer Account`
12
10
 
13
- This will create an Account observer:
11
+ creates an Account observer and unit test:
14
12
  Observer: app/models/account_observer.rb
15
13
  Test: test/unit/account_observer_test.rb
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
2
 
3
3
  class <%= class_name %>ObserverTest < Test::Unit::TestCase
4
- fixtures :<%= table_name %>
5
-
6
4
  # Replace this with your real tests.
7
5
  def test_truth
8
6
  assert true
@@ -1,19 +1,15 @@
1
1
  Description:
2
- The plugin generator creates stubs for a new plugin.
2
+ Stubs out a new plugin. Pass the plugin name, either CamelCased or
3
+ under_scored, as an argument. Pass --with-generator to add an example
4
+ generator also.
3
5
 
4
- The generator takes a plugin name as its argument. The plugin name may be
5
- given in CamelCase or under_score and should not be suffixed with 'Plugin'.
6
-
7
- The generator creates a plugin directory in vendor/plugins that includes
8
- both init.rb and README files as well as lib, task, and test directories.
9
-
10
- It's also possible to generate stub files for a generator to go with the
11
- plugin by using --with-generator
6
+ This creates a plugin in vendor/plugins including an init.rb and README
7
+ as well as standard lib, task, and test directories.
12
8
 
13
9
  Example:
14
- ./script/generate plugin BrowserFilters
10
+ `./script/generate plugin BrowserFilters`
15
11
 
16
- This will create:
12
+ creates a standard browser_filters plugin:
17
13
  vendor/plugins/browser_filters/README
18
14
  vendor/plugins/browser_filters/init.rb
19
15
  vendor/plugins/browser_filters/install.rb
@@ -23,13 +19,7 @@ Example:
23
19
 
24
20
  ./script/generate plugin BrowserFilters --with-generator
25
21
 
26
- This will create:
27
- vendor/plugins/browser_filters/README
28
- vendor/plugins/browser_filters/init.rb
29
- vendor/plugins/browser_filters/install.rb
30
- vendor/plugins/browser_filters/lib/browser_filters.rb
31
- vendor/plugins/browser_filters/test/browser_filters_test.rb
32
- vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake
22
+ creates a browser_filters generator also:
33
23
  vendor/plugins/browser_filters/generators/browser_filters/browser_filters_generator.rb
34
24
  vendor/plugins/browser_filters/generators/browser_filters/USAGE
35
25
  vendor/plugins/browser_filters/generators/browser_filters/templates/