Skip to content

Commit 99bae4d

Browse files
committed
Merge pull request #95 from mfung/master
Added code to remove tmp dir after test suite is completed, fixes bug #79
2 parents 34e3e2c + 03e0d33 commit 99bae4d

File tree

4 files changed

+46
-30
lines changed

4 files changed

+46
-30
lines changed

lib/generators/haml/mailer/mailer_generator.rb

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,38 @@ class MailerGenerator < ControllerGenerator
66
source_root File.expand_path("../templates", __FILE__)
77

88
def copy_view_files
9-
view_base_path = File.join("app/views", class_path, file_name)
10-
empty_directory view_base_path
9+
if ::Rails.version.to_s >= "4.2.0"
10+
view_base_path = File.join("app/views", class_path, file_name)
11+
empty_directory view_base_path
1112

12-
if self.behavior == :invoke
13-
formats.each do |format|
14-
layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
15-
template filename_with_extensions(:layout, format), layout_path
13+
if self.behavior == :invoke
14+
formats.each do |format|
15+
layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
16+
template filename_with_extensions(:layout, format), layout_path
17+
end
1618
end
17-
end
1819

19-
actions.each do |action|
20-
@action = action
20+
actions.each do |action|
21+
@action = action
2122

22-
formats.each do |format|
23-
@path = File.join(view_base_path, filename_with_extensions(action, format))
24-
template filename_with_extensions(:view, format), @path
23+
formats.each do |format|
24+
@path = File.join(view_base_path, filename_with_extensions(action, format))
25+
template filename_with_extensions(:view, format), @path
26+
end
2527
end
28+
else
29+
super
2630
end
2731
end
2832

2933
protected
34+
def format
35+
:text
36+
end
37+
3038
def formats
3139
[:text, :html]
3240
end
33-
3441
end
3542
end
3643
end

lib/haml-rails.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Railtie < ::Rails::Railtie
5454

5555
rake_tasks do
5656
load 'tasks/erb2haml.rake'
57-
end
57+
end
5858
end
5959
end
6060
end

test/lib/generators/haml/mailer_generator_test.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,35 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
1212
test "should invoke template engine" do
1313
run_generator
1414

15-
assert_file "app/views/layouts/mailer.text.haml" do |view|
16-
assert_match /\= yield/, view
17-
end
15+
if ::Rails.version.to_s >= '4.2'
16+
17+
assert_file "app/views/layouts/mailer.text.haml" do |view|
18+
assert_match /\= yield/, view
19+
end
20+
21+
assert_file "app/views/layouts/mailer.html.haml" do |view|
22+
assert_match /\= yield/, view
23+
end
1824

19-
assert_file "app/views/layouts/mailer.html.haml" do |view|
20-
assert_match /\= yield/, view
25+
assert_file "app/views/notifier/foo.html.haml" do |view|
26+
assert_match %r(app/views/notifier/foo\.html\.haml), view
27+
assert_match /\= @greeting/, view
28+
end
29+
30+
assert_file "app/views/notifier/bar.html.haml" do |view|
31+
assert_match %r(app/views/notifier/bar\.html\.haml), view
32+
assert_match /\= @greeting/, view
33+
end
2134
end
2235

2336
assert_file "app/views/notifier/foo.text.haml" do |view|
2437
assert_match %r(app/views/notifier/foo\.text\.haml), view
2538
assert_match /\= @greeting/, view
2639
end
2740

28-
assert_file "app/views/notifier/foo.html.haml" do |view|
29-
assert_match %r(app/views/notifier/foo\.html\.haml), view
30-
assert_match /\= @greeting/, view
31-
end
32-
3341
assert_file "app/views/notifier/bar.text.haml" do |view|
3442
assert_match %r(app/views/notifier/bar\.text\.haml), view
3543
assert_match /\= @greeting/, view
3644
end
37-
38-
assert_file "app/views/notifier/bar.html.haml" do |view|
39-
assert_match %r(app/views/notifier/bar\.html\.haml), view
40-
assert_match /\= @greeting/, view
41-
end
4245
end
4346
end

test/test_helper.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ def require_generators(generator_list)
7070
end
7171
alias :require_generator :require_generators
7272

73-
require_generators generator_list
73+
require_generators generator_list
74+
75+
# Remove tmp directory when test suite is completed
76+
MiniTest::Unit.after_tests do
77+
tmp_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
78+
FileUtils.rm_r(tmp_dir)
79+
end

0 commit comments

Comments
 (0)