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

removed Gemfile's injection

by default : Markerb define then markerb email views generated otherwise
erb
This commit is contained in:
Bounmy Stephane 2011-09-30 22:41:02 -07:00
parent a629654a15
commit 76bff0d4de
2 changed files with 12 additions and 50 deletions

View file

@ -77,34 +77,6 @@ module Devise
def target_path
"app/views/#{scope || :devise}/mailer"
end
def inject_makerb_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(destination_root, "Gemfile")
end
def gemfile_content
"gem 'markerb'"
end
def gemfile_content_regexp
/gem ['|"]markerb['|"]/
end
def gemfile
begin
File.read(gemfile_path)
rescue
nil
end
end
end
class ViewsGenerator < Rails::Generators::Base
@ -119,7 +91,7 @@ module Devise
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
:default => :erb,
:default => defined?(Markerb) ? :markerb : :erb,
:type => :boolean
end
end

View file

@ -28,32 +28,22 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
assert_file "app/views/users/confirmations/new.html.erb", :template_engine => /simple_form_for/
end
test "Assert views with simple form if defined" do
run_generator
assert_files nil, :template_engine => /simple_form_for/
assert_file "app/views/devise/confirmations/new.html.erb", :template_engine => /simple_form_for/
end
test "Assert views with markerb" do
run_generator %w(--markerb)
assert_files nil, :mail_template_engine => "markerb"
end
test "Assert Gemfile got gem markerb injected" do
create_gemfile("gem 'rails'")
run_generator %w(--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'/
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"))
test "Assert views with markerb by if Markerb is defined" do
class Markerb ;; end
run_generator
pending "Doesn't work: defined?(Markerb) returns nil in Devise::Generators::ViewsGenerator"
# assert_files nil, :mail_template_engine => "markerb"
end
def assert_files(scope = nil, options={})