Skip to content

Commit afc1026

Browse files
committed
Still copy application configuration to generator even if they are required earlier. Also tidy up the guide a little bit.
1 parent fdd203f commit afc1026

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

railties/guides/source/generators.textile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,10 @@ config.generators do |g|
322322
g.template_engine :erb
323323
g.test_framework :shoulda, :fixture => false
324324
g.stylesheets false
325-
end
326-
</ruby>
327-
328-
And at the end of the same file:
329325

330-
<ruby>
331-
require 'rails/generators'
332-
Rails::Generators.fallbacks[:shoulda] = :test_unit
326+
# Add a fallback!
327+
g.fallbacks[:should] = :test_unit
328+
end
333329
</ruby>
334330

335331
Now, if create a Comment scaffold, you will see that shoulda generators are being invoked, and at the end, they are just falling back to test unit generators:
@@ -361,7 +357,7 @@ $ rails generate scaffold Comment body:text
361357
create test/unit/helpers/comments_helper_test.rb
362358
</shell>
363359

364-
Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of code duplication.
360+
Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of duplication.
365361

366362
h3. Changelog
367363

railties/lib/rails/commands/destroy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rails/generators'
2+
Rails::Generators.configure!
23

34
if [nil, "-h", "--help"].include?(ARGV.first)
45
Rails::Generators.help 'destroy'

railties/lib/rails/commands/generate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rails/generators'
2+
Rails::Generators.configure!
23

34
if [nil, "-h", "--help"].include?(ARGV.first)
45
Rails::Generators.help 'generate'

railties/lib/rails/generators.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def self.configure!(config = Rails.application.config.generators) #:nodoc:
6868
options.deep_merge! config.options
6969
fallbacks.merge! config.fallbacks
7070
templates_path.concat config.templates
71+
templates_path.uniq!
7172
end
7273

7374
def self.templates_path
@@ -328,10 +329,5 @@ def self.namespaces_to_paths(namespaces) #:nodoc:
328329
paths.uniq!
329330
paths
330331
end
331-
332332
end
333-
end
334-
335-
# If the application was already defined, configure generators,
336-
# otherwise you have to configure it by hand.
337-
Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application
333+
end

railties/test/generators/generators_test_helper.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'abstract_unit'
2+
require 'rails/generators'
3+
require 'rails/generators/test_case'
24

35
module Rails
46
def self.root
@@ -8,8 +10,9 @@ def self.root
810
Rails.application.config.root = Rails.root
911
Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "templates")]
1012

11-
require 'rails/generators'
12-
require 'rails/generators/test_case'
13+
# Call configure to load the settings from
14+
# Rails.application.config.generators to Rails::Generators
15+
Rails::Generators.configure!
1316

1417
require 'active_record'
1518
require 'action_dispatch'

0 commit comments

Comments
 (0)