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.
- data/CHANGELOG +491 -12
- data/MIT-LICENSE +1 -1
- data/README +17 -25
- data/Rakefile +41 -18
- data/bin/about +1 -1
- data/bin/console +1 -1
- data/bin/destroy +1 -1
- data/bin/generate +1 -1
- data/bin/performance/request +3 -0
- data/bin/plugin +1 -1
- data/bin/runner +1 -1
- data/bin/server +1 -1
- data/builtin/rails_info/rails/info.rb +2 -2
- data/configs/apache.conf +1 -1
- data/configs/databases/mysql.yml +9 -3
- data/configs/databases/postgresql.yml +16 -12
- data/configs/initializers/inflections.rb +10 -0
- data/configs/initializers/mime_types.rb +5 -0
- data/configs/routes.rb +23 -11
- data/doc/README_FOR_APP +1 -1
- data/environments/boot.rb +95 -26
- data/environments/development.rb +2 -5
- data/environments/environment.rb +24 -25
- data/environments/test.rb +4 -1
- data/helpers/application.rb +5 -2
- data/helpers/test_helper.rb +10 -0
- data/html/422.html +30 -0
- data/html/500.html +1 -1
- data/html/index.html +2 -2
- data/html/javascripts/controls.js +484 -354
- data/html/javascripts/dragdrop.js +88 -58
- data/html/javascripts/effects.js +396 -364
- data/html/javascripts/prototype.js +2817 -1107
- data/html/robots.txt +5 -1
- data/lib/commands/console.rb +12 -5
- data/lib/commands/performance/request.rb +6 -0
- data/lib/commands/plugin.rb +15 -10
- data/lib/commands/process/spawner.rb +14 -4
- data/lib/commands/servers/base.rb +12 -0
- data/lib/commands/servers/mongrel.rb +5 -1
- data/lib/commands/servers/webrick.rb +14 -7
- data/lib/console_app.rb +5 -2
- data/lib/console_with_helpers.rb +5 -2
- data/lib/dispatcher.rb +3 -151
- data/lib/fcgi_handler.rb +79 -81
- data/lib/initializer.rb +125 -169
- data/lib/rails/plugin.rb +84 -0
- data/lib/rails/plugin/loader.rb +150 -0
- data/lib/rails/plugin/locator.rb +78 -0
- data/lib/rails/version.rb +3 -3
- data/lib/rails_generator/base.rb +11 -9
- data/lib/rails_generator/commands.rb +20 -10
- data/lib/rails_generator/generators/applications/app/USAGE +0 -7
- data/lib/rails_generator/generators/applications/app/app_generator.rb +25 -6
- data/lib/rails_generator/generators/components/controller/USAGE +11 -12
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -2
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
- data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
- data/lib/rails_generator/generators/components/integration_test/USAGE +5 -11
- data/lib/rails_generator/generators/components/mailer/USAGE +8 -10
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +3 -3
- data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +8 -24
- data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
- data/lib/rails_generator/generators/components/migration/USAGE +23 -8
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +6 -2
- data/lib/rails_generator/generators/components/model/USAGE +15 -14
- data/lib/rails_generator/generators/components/model/model_generator.rb +10 -3
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -3
- data/lib/rails_generator/generators/components/model/templates/migration.rb +4 -1
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -3
- data/lib/rails_generator/generators/components/observer/USAGE +5 -7
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -2
- data/lib/rails_generator/generators/components/plugin/USAGE +8 -18
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
- data/lib/rails_generator/generators/components/resource/USAGE +23 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +13 -15
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +1 -1
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +2 -14
- data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -146
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +64 -37
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -80
- data/lib/rails_generator/generators/components/scaffold/templates/{layout.rhtml → layout.html.erb} +0 -0
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_edit.rhtml → scaffold/templates/view_edit.html.erb} +4 -4
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_index.rhtml → scaffold/templates/view_index.html.erb} +4 -4
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_new.rhtml → scaffold/templates/view_new.html.erb} +3 -3
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_show.rhtml → scaffold/templates/view_show.html.erb} +1 -1
- data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +3 -3
- data/lib/rails_generator/lookup.rb +45 -10
- data/lib/rails_generator/scripts.rb +6 -3
- data/lib/rails_generator/scripts/destroy.rb +23 -0
- data/lib/rails_generator/secret_key_generator.rb +160 -0
- data/lib/rails_generator/spec.rb +1 -1
- data/lib/source_annotation_extractor.rb +62 -0
- data/lib/tasks/annotations.rake +23 -0
- data/lib/tasks/databases.rake +249 -83
- data/lib/tasks/documentation.rake +11 -13
- data/lib/tasks/framework.rake +1 -1
- data/lib/tasks/rails.rb +1 -1
- data/lib/tasks/testing.rake +5 -7
- data/lib/test_help.rb +4 -3
- data/lib/webrick_server.rb +3 -4
- metadata +31 -49
- data/bin/breakpointer +0 -3
- data/lib/binding_of_caller.rb +0 -85
- data/lib/breakpoint.rb +0 -553
- data/lib/breakpoint_client.rb +0 -196
- data/lib/commands/breakpointer.rb +0 -1
- data/lib/rails_generator/generators/components/resource/templates/USAGE +0 -18
- data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +0 -11
- data/lib/rails_generator/generators/components/resource/templates/migration.rb +0 -13
- data/lib/rails_generator/generators/components/resource/templates/model.rb +0 -2
- data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +0 -10
- data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
- data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
- data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
- data/lib/rails_generator/generators/components/scaffold_resource/USAGE +0 -29
- data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +0 -93
- data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +0 -79
- data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +0 -11
- data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +0 -57
- data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +0 -2
- data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +0 -17
- data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +0 -13
- data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +0 -2
- data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +0 -74
- data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +0 -10
- data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
- data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
- data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
- data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
- data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
- data/lib/tasks/pre_namespace_aliases.rake +0 -53
@@ -1,30 +1,29 @@
|
|
1
1
|
Description:
|
2
|
-
|
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
|
-
|
5
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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.
|
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
|
-
|
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.
|
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}.
|
32
|
-
m.template 'view.
|
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
|
data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb}
RENAMED
File without changes
|
@@ -1,14 +1,8 @@
|
|
1
1
|
Description:
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
5
|
-
|
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
|
-
|
10
|
+
`./script/generate mailer Notifications signup forgot_password invoice`
|
12
11
|
|
13
|
-
|
12
|
+
creates a Notifications mailer class, views, test, and fixtures:
|
14
13
|
Mailer: app/models/notifications.rb
|
15
|
-
Views: app/views/notifications/signup.
|
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}.
|
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.
|
27
|
+
m.template "view.erb", view_path,
|
28
28
|
:assigns => { :action => action, :path => view_path }
|
29
|
-
m.template "fixture.
|
29
|
+
m.template "fixture.erb", fixture_path,
|
30
30
|
:assigns => { :action => action, :path => view_path }
|
31
31
|
end
|
32
32
|
end
|
@@ -1,21 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
|
2
2
|
|
3
|
-
class <%= class_name %>Test <
|
4
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
@@ -1,14 +1,29 @@
|
|
1
1
|
Description:
|
2
|
-
|
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
|
-
|
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
|
-
|
8
|
-
|
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
|
-
|
11
|
+
`./script/generate migration AddSslFlag`
|
12
12
|
|
13
|
-
With 4 existing migrations, this
|
14
|
-
|
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
|
-
|
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
|
-
|
5
|
-
|
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
|
-
|
8
|
-
|
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
|
-
|
13
|
-
test/fixtures/singular_name.yml, and a migration in
|
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
|
-
|
17
|
+
`./script/generate model account`
|
17
18
|
|
18
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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}
|
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
|
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 <
|
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
|
-
|
2
|
+
Stubs out a new observer. Pass the observer name, either CamelCased or
|
3
|
+
under_scored, as an argument.
|
3
4
|
|
4
|
-
The generator
|
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
|
-
|
9
|
+
`./script/generate observer Account`
|
12
10
|
|
13
|
-
|
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,19 +1,15 @@
|
|
1
1
|
Description:
|
2
|
-
|
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
|
-
|
5
|
-
|
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
|
-
|
10
|
+
`./script/generate plugin BrowserFilters`
|
15
11
|
|
16
|
-
|
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
|
-
|
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/
|