Browse files

gemfile entries can be added to the app builder

  • Loading branch information...
1 parent 90ace1b commit 3f2230b9ece12b93f9bd6da0e1532b8771aad886 @tenderlove tenderlove committed Oct 31, 2013
Showing with 51 additions and 3 deletions.
  1. +16 −3 railties/lib/rails/generators/app_base.rb
  2. +35 −0 railties/test/generators/generator_test.rb
View
19 railties/lib/rails/generators/app_base.rb
@@ -77,22 +77,35 @@ def self.add_shared_options_for(name)
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,
assets_gemfile_entry,
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
View
35 railties/test/generators/generator_test.rb
@@ -14,6 +14,7 @@ def make_builder_class
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 @@ def test_construction
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'])

0 comments on commit 3f2230b

Please sign in to comment.