1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

ensure that the gem markerb entry is not duplicated in the gemfile

This commit is contained in:
Bounmy Stephane 2011-09-14 20:20:20 -07:00
parent dbda19f658
commit a629654a15
2 changed files with 31 additions and 11 deletions

View file

@ -79,23 +79,31 @@ module Devise
end
def inject_makerb_content
if gemfile_exists?
append_file gemfile_path, gemfile_content
if gemfile
append_file gemfile_path, gemfile_content unless gemfile =~ gemfile_content_regexp
else
create_file gemfile_path, gemfile_content
end
end
def gemfile_path
@gemfile_path ||= File.join("Gemfile")
end
def gemfile_exists?
File.exists?(File.join(destination_root, gemfile_path))
@gemfile_path ||= File.join(destination_root, "Gemfile")
end
def gemfile_content
'gem "markerb"'
"gem 'markerb'"
end
def gemfile_content_regexp
/gem ['|"]markerb['|"]/
end
def gemfile
begin
File.read(gemfile_path)
rescue
nil
end
end
end

View file

@ -34,14 +34,26 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
end
test "Assert Gemfile got gem markerb injected" do
File.open(File.join(destination_root, "Gemfile"), 'w') {|f| f.write("gem 'rails'") }
create_gemfile("gem 'rails'")
run_generator %w(--markerb)
assert_file "Gemfile", /gem \"markerb\"/
assert_file "Gemfile", /gem 'markerb'/
assert_file "Gemfile", /gem 'rails'/
end
test "Assert Gemfile got gem markerb injected only if it does not exist" do
gemfile = create_gemfile("gem 'markerb'")
run_generator %w(--markerb)
assert_equal 1, gemfile.scan("gem 'markerb'").length
end
test "Assert Gemfile got created with markerb if no gemfile" do
run_generator %w(--markerb)
assert_file "Gemfile", /gem \"markerb\"/
assert_file "Gemfile", /gem 'markerb'/
end
def create_gemfile(content=nil)
File.open(File.join(destination_root, "Gemfile"), 'w') {|f| f.write(content) }
File.read(File.join(destination_root, "Gemfile"))
end
def assert_files(scope = nil, options={})