diff options
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 19 | ||||
-rw-r--r-- | railties/test/generators/generator_test.rb | 35 |
2 files changed, 51 insertions, 3 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index aee5712643..35c6ce1cf8 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -77,14 +77,26 @@ module Rails end def initialize(*args) - @original_wd = Dir.pwd - @gem_filter = lambda { |gem| true } + @original_wd = Dir.pwd + @gem_filter = lambda { |gem| true } + @extra_entries = [] super convert_database_option_for_jruby end protected + def gemfile_entry(name, version = nil, github: nil, path: nil) + if github + @extra_entries << GemfileEntry.github(name, github) + elsif path + @extra_entries << GemfileEntry.path(name, path) + else + @extra_entries << GemfileEntry.version(name, version) + end + self + end + def gemfile_entries [ rails_gemfile_entry, database_gemfile_entry, @@ -92,7 +104,8 @@ module Rails javascript_gemfile_entry, jbuilder_gemfile_entry, webconsole_gemfile_entry, - sdoc_gemfile_entry].flatten.find_all(&@gem_filter) + sdoc_gemfile_entry, + @extra_entries].flatten.find_all(&@gem_filter) end def add_gem_entry_filter diff --git a/railties/test/generators/generator_test.rb b/railties/test/generators/generator_test.rb index 7600a40ae9..dd4868585b 100644 --- a/railties/test/generators/generator_test.rb +++ b/railties/test/generators/generator_test.rb @@ -14,6 +14,7 @@ module Rails def gemfile_entries; super; end def invoke_all; super; self; end def add_gem_entry_filter; super; end + def gemfile_entry(*args); super; end }) end end @@ -23,6 +24,40 @@ module Rails assert klass.start(['new', 'blah']) end + def test_add_gem + klass = make_builder_class + generator = klass.start(['new', 'blah']) + generator.gemfile_entry 'tenderlove' + assert_includes generator.gemfile_entries.map(&:name), 'tenderlove' + end + + def test_add_gem_with_version + klass = make_builder_class + generator = klass.start(['new', 'blah']) + generator.gemfile_entry 'tenderlove', '2.0.0' + assert generator.gemfile_entries.find { |gfe| + gfe.name == 'tenderlove' && gfe.version == '2.0.0' + } + end + + def test_add_github_gem + klass = make_builder_class + generator = klass.start(['new', 'blah']) + generator.gemfile_entry 'tenderlove', github: 'hello world' + assert generator.gemfile_entries.find { |gfe| + gfe.name == 'tenderlove' && gfe.options[:github] == 'hello world' + } + end + + def test_add_path_gem + klass = make_builder_class + generator = klass.start(['new', 'blah']) + generator.gemfile_entry 'tenderlove', path: 'hello world' + assert generator.gemfile_entries.find { |gfe| + gfe.name == 'tenderlove' && gfe.options[:path] == 'hello world' + } + end + def test_filter klass = make_builder_class generator = klass.start(['new', 'blah']) |