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.
- data/CHANGELOG +27 -3
- data/Rakefile +70 -10
- data/bin/about +0 -0
- data/bin/console +0 -0
- data/bin/destroy +0 -0
- data/bin/generate +0 -0
- data/bin/performance/benchmarker +0 -0
- data/bin/performance/profiler +0 -0
- data/bin/performance/request +0 -0
- data/bin/plugin +0 -0
- data/bin/process/inspector +0 -0
- data/bin/process/reaper +0 -0
- data/bin/process/spawner +0 -0
- data/bin/runner +0 -0
- data/bin/server +0 -0
- data/config.ru +17 -0
- data/configs/apache.conf +0 -0
- data/configs/databases/ibm_db.yml +62 -0
- data/configs/databases/mysql.yml +3 -0
- data/configs/databases/postgresql.yml +3 -0
- data/configs/databases/sqlite2.yml +3 -0
- data/configs/databases/sqlite3.yml +3 -0
- data/configs/locales/en.yml +5 -0
- data/dispatches/dispatch.fcgi +1 -1
- data/dispatches/dispatch.rb +2 -2
- data/dispatches/gateway.cgi +2 -2
- data/doc/README_FOR_APP +5 -2
- data/doc/guides/html/2_2_release_notes.html +1185 -0
- data/doc/guides/html/actioncontroller_basics.html +1270 -0
- data/doc/guides/html/activerecord_validations_callbacks.html +749 -0
- data/doc/guides/html/association_basics.html +2585 -0
- data/doc/guides/html/authors.html +240 -0
- data/doc/guides/html/benchmarking_and_profiling.html +1018 -0
- data/doc/guides/html/caching_with_rails.html +583 -0
- data/doc/guides/html/command_line.html +434 -0
- data/doc/guides/html/configuring.html +438 -0
- data/doc/guides/html/creating_plugins.html +1594 -0
- data/doc/guides/html/debugging_rails_applications.html +1175 -0
- data/doc/guides/html/finders.html +1090 -0
- data/doc/guides/html/form_helpers.html +638 -0
- data/doc/guides/html/getting_started_with_rails.html +2066 -0
- data/doc/guides/html/index.html +349 -0
- data/doc/guides/html/layouts_and_rendering.html +1406 -0
- data/doc/guides/html/migrations.html +921 -0
- data/doc/guides/html/routing_outside_in.html +2213 -0
- data/doc/guides/html/security.html +1346 -0
- data/doc/guides/html/testing_rails_applications.html +1859 -0
- data/doc/guides/source/2_2_release_notes.txt +435 -0
- data/doc/guides/source/actioncontroller_basics/changelog.txt +5 -0
- data/doc/guides/source/actioncontroller_basics/cookies.txt +34 -0
- data/doc/guides/source/actioncontroller_basics/csrf.txt +32 -0
- data/doc/guides/source/actioncontroller_basics/filters.txt +119 -0
- data/doc/guides/source/actioncontroller_basics/http_auth.txt +24 -0
- data/doc/guides/source/actioncontroller_basics/index.txt +40 -0
- data/doc/guides/source/actioncontroller_basics/introduction.txt +9 -0
- data/doc/guides/source/actioncontroller_basics/methods.txt +39 -0
- data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +14 -0
- data/doc/guides/source/actioncontroller_basics/params.txt +93 -0
- data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +43 -0
- data/doc/guides/source/actioncontroller_basics/rescue.txt +67 -0
- data/doc/guides/source/actioncontroller_basics/session.txt +187 -0
- data/doc/guides/source/actioncontroller_basics/streaming.txt +91 -0
- data/doc/guides/source/actioncontroller_basics/verification.txt +40 -0
- data/doc/guides/source/active_record_basics.txt +181 -0
- data/doc/guides/source/activerecord_validations_callbacks.txt +404 -0
- data/doc/guides/source/association_basics.txt +1840 -0
- data/doc/guides/source/authors.txt +39 -0
- data/doc/guides/source/benchmarking_and_profiling/appendix.txt +95 -0
- data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +105 -0
- data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +185 -0
- data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +27 -0
- data/doc/guides/source/benchmarking_and_profiling/index.txt +242 -0
- data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +179 -0
- data/doc/guides/source/benchmarking_and_profiling/statistics.txt +57 -0
- data/doc/guides/source/caching_with_rails.txt +367 -0
- data/doc/guides/source/command_line.txt +147 -0
- data/doc/guides/source/configuring.txt +225 -0
- data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +191 -0
- data/doc/guides/source/creating_plugins/appendix.txt +46 -0
- data/doc/guides/source/creating_plugins/controllers.txt +59 -0
- data/doc/guides/source/creating_plugins/core_ext.txt +123 -0
- data/doc/guides/source/creating_plugins/custom_route.txt +69 -0
- data/doc/guides/source/creating_plugins/gem.txt +1 -0
- data/doc/guides/source/creating_plugins/generator_method.txt +89 -0
- data/doc/guides/source/creating_plugins/helpers.txt +51 -0
- data/doc/guides/source/creating_plugins/index.txt +52 -0
- data/doc/guides/source/creating_plugins/migration_generator.txt +156 -0
- data/doc/guides/source/creating_plugins/models.txt +76 -0
- data/doc/guides/source/creating_plugins/odds_and_ends.txt +69 -0
- data/doc/guides/source/creating_plugins/test_setup.txt +230 -0
- data/doc/guides/source/debugging_rails_applications.txt +733 -0
- data/doc/guides/source/finders.txt +668 -0
- data/doc/guides/source/form_helpers.txt +345 -0
- data/doc/guides/source/getting_started_with_rails.txt +1256 -0
- data/doc/guides/source/images/belongs_to.png +0 -0
- data/doc/guides/source/images/bullet.gif +0 -0
- data/doc/guides/source/images/csrf.png +0 -0
- data/doc/guides/source/images/habtm.png +0 -0
- data/doc/guides/source/images/has_many.png +0 -0
- data/doc/guides/source/images/has_many_through.png +0 -0
- data/doc/guides/source/images/has_one.png +0 -0
- data/doc/guides/source/images/has_one_through.png +0 -0
- data/doc/guides/source/images/header_backdrop.png +0 -0
- data/doc/guides/source/images/icons/README +5 -0
- data/doc/guides/source/images/icons/callouts/1.png +0 -0
- data/doc/guides/source/images/icons/callouts/10.png +0 -0
- data/doc/guides/source/images/icons/callouts/11.png +0 -0
- data/doc/guides/source/images/icons/callouts/12.png +0 -0
- data/doc/guides/source/images/icons/callouts/13.png +0 -0
- data/doc/guides/source/images/icons/callouts/14.png +0 -0
- data/doc/guides/source/images/icons/callouts/15.png +0 -0
- data/doc/guides/source/images/icons/callouts/2.png +0 -0
- data/doc/guides/source/images/icons/callouts/3.png +0 -0
- data/doc/guides/source/images/icons/callouts/4.png +0 -0
- data/doc/guides/source/images/icons/callouts/5.png +0 -0
- data/doc/guides/source/images/icons/callouts/6.png +0 -0
- data/doc/guides/source/images/icons/callouts/7.png +0 -0
- data/doc/guides/source/images/icons/callouts/8.png +0 -0
- data/doc/guides/source/images/icons/callouts/9.png +0 -0
- data/doc/guides/source/images/icons/caution.png +0 -0
- data/doc/guides/source/images/icons/example.png +0 -0
- data/doc/guides/source/images/icons/home.png +0 -0
- data/doc/guides/source/images/icons/important.png +0 -0
- data/doc/guides/source/images/icons/next.png +0 -0
- data/doc/guides/source/images/icons/note.png +0 -0
- data/doc/guides/source/images/icons/prev.png +0 -0
- data/doc/guides/source/images/icons/tip.png +0 -0
- data/doc/guides/source/images/icons/up.png +0 -0
- data/doc/guides/source/images/icons/warning.png +0 -0
- data/doc/guides/source/images/polymorphic.png +0 -0
- data/doc/guides/source/images/rails_logo_remix.gif +0 -0
- data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
- data/doc/guides/source/images/session_fixation.png +0 -0
- data/doc/guides/source/index.txt +118 -0
- data/doc/guides/source/layouts_and_rendering.txt +982 -0
- data/doc/guides/source/migrations/anatomy_of_a_migration.txt +85 -0
- data/doc/guides/source/migrations/changelog.txt +5 -0
- data/doc/guides/source/migrations/creating_a_migration.txt +109 -0
- data/doc/guides/source/migrations/foreign_keys.txt +8 -0
- data/doc/guides/source/migrations/index.txt +22 -0
- data/doc/guides/source/migrations/rakeing_around.txt +111 -0
- data/doc/guides/source/migrations/scheming.txt +47 -0
- data/doc/guides/source/migrations/using_models_in_migrations.txt +46 -0
- data/doc/guides/source/migrations/writing_a_migration.txt +159 -0
- data/doc/guides/source/routing_outside_in.txt +986 -0
- data/doc/guides/source/security.txt +984 -0
- data/doc/guides/source/stylesheets/base.css +358 -0
- data/doc/guides/source/stylesheets/forms.css +35 -0
- data/doc/guides/source/stylesheets/more.css +82 -0
- data/doc/guides/source/templates/guides.html.erb +97 -0
- data/doc/guides/source/templates/inline.css +165 -0
- data/doc/guides/source/testing_rails_applications.txt +995 -0
- data/environments/boot.rb +2 -2
- data/environments/environment.rb +9 -1
- data/environments/production.rb +3 -1
- data/helpers/performance_test.rb +9 -0
- data/html/500.html +4 -1
- data/html/javascripts/controls.js +72 -72
- data/html/javascripts/dragdrop.js +165 -164
- data/html/javascripts/effects.js +173 -165
- data/html/javascripts/prototype.js +362 -267
- data/lib/commands/console.rb +13 -0
- data/lib/commands/dbconsole.rb +2 -2
- data/lib/commands/ncgi/listener +2 -2
- data/lib/commands/ncgi/tracker +2 -2
- data/lib/commands/plugin.rb +41 -24
- data/lib/commands/process/spawner.rb +4 -4
- data/lib/commands/runner.rb +1 -1
- data/lib/commands/server.rb +11 -1
- data/lib/commands/servers/thin.rb +25 -0
- data/lib/fcgi_handler.rb +1 -3
- data/lib/initializer.rb +162 -39
- data/lib/performance_test_help.rb +5 -0
- data/lib/rails/gem_builder.rb +3 -3
- data/lib/rails/gem_dependency.rb +155 -33
- data/lib/rails/mongrel_server/commands.rb +1 -1
- data/lib/rails/plugin.rb +10 -2
- data/lib/rails/rack.rb +6 -0
- data/lib/rails/rack/logger.rb +28 -0
- data/lib/rails/rack/static.rb +35 -0
- data/lib/rails/vendor_gem_source_index.rb +140 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails_generator/commands.rb +10 -16
- data/lib/rails_generator/generated_attribute.rb +4 -0
- data/lib/rails_generator/generators/applications/app/app_generator.rb +9 -3
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +1 -1
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -1
- data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +1 -1
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +2 -2
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +1 -1
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +2 -3
- data/lib/rails_generator/generators/components/model/model_generator.rb +1 -1
- data/lib/rails_generator/generators/components/model/templates/model.rb +3 -0
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -1
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +1 -1
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +1 -1
- data/lib/rails_generator/generators/components/performance_test/USAGE +8 -0
- data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +16 -0
- data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +9 -0
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +11 -11
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +3 -0
- data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +4 -4
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +2 -2
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +1 -1
- data/lib/rails_generator/generators/components/scaffold/USAGE +9 -5
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +10 -3
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +7 -7
- data/lib/rails_generator/scripts.rb +1 -1
- data/lib/rails_generator/scripts/destroy.rb +6 -7
- data/lib/rails_generator/secret_key_generator.rb +5 -147
- data/lib/tasks/annotations.rake +8 -11
- data/lib/tasks/databases.rake +42 -15
- data/lib/tasks/documentation.rake +15 -0
- data/lib/tasks/framework.rake +5 -1
- data/lib/tasks/gems.rake +24 -8
- data/lib/tasks/misc.rake +3 -4
- data/lib/tasks/testing.rake +25 -4
- data/lib/test_help.rb +1 -2
- data/lib/webrick_server.rb +2 -11
- metadata +165 -9
data/lib/rails/version.rb
CHANGED
@@ -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?
|
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(
|
191
|
-
break unless
|
192
|
-
|
185
|
+
last = nesting.inject(Object) { |last, nest|
|
186
|
+
break unless last.const_defined?(nest)
|
187
|
+
last.const_get(nest)
|
193
188
|
}
|
194
189
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
require 'digest/md5'
|
3
|
-
require '
|
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 =
|
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
|
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)
|
data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb
CHANGED
@@ -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
|
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)
|
@@ -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
|
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
|
-
|
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
|
-
|
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
|
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)
|
@@ -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
|
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)
|
@@ -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
|
@@ -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
|
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',
|
20
|
-
m.template 'MIT-LICENSE',
|
21
|
-
m.template 'Rakefile',
|
22
|
-
m.template 'init.rb',
|
23
|
-
m.template 'install.rb',
|
24
|
-
m.template 'uninstall.rb',
|
25
|
-
m.template 'plugin.rb',
|
26
|
-
m.template 'tasks.rake',
|
27
|
-
m.template 'unit_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}"
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
class <%= class_name %>Test <
|
3
|
+
class <%= class_name %>Test < ActiveSupport::TestCase
|
4
4
|
# Replace this with your real tests.
|
5
|
-
|
6
|
-
|
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(
|
34
|
-
m.class_collisions(
|
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))
|
@@ -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
|
4
|
+
starting point for your RESTful, resource-oriented application.
|
5
5
|
|
6
|
-
Pass the name of the model, either CamelCased or
|
7
|
-
argument, and an optional list of attribute
|
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,
|
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`
|
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(
|
35
|
-
m.class_collisions(
|
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
|
-
|
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
|
-
|
10
|
+
test "should get new" do
|
11
11
|
get :new
|
12
12
|
assert_response :success
|
13
13
|
end
|
14
14
|
|
15
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|