1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

gemfile entries can be added to the app builder

This commit is contained in:
Aaron Patterson 2013-10-31 14:59:56 -07:00
parent 90ace1b986
commit 3f2230b9ec
2 changed files with 51 additions and 3 deletions

View file

@ -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

View file

@ -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'])