Skip to content
Browse files

More work on generated mailer templates.

  • Loading branch information...
1 parent f143900 commit 1b3cb54ebae685d4db9eefc99ce68b36d5641751 José Valim and Mikel Lindsaar committed Jan 26, 2010
View
2 railties/lib/generators/erb/mailer/mailer_generator.rb
@@ -12,7 +12,7 @@ def create_view_folder
def create_view_files
actions.each do |action|
@action, @path = action, File.join(file_path, action)
- template "view.erb", File.join("app/views", "#{@path}.erb")
+ template "view.text.erb", File.join("app/views", "#{@path}.text.erb")
end
end
end
View
0 .../generators/erb/mailer/templates/view.erb → ...rators/erb/mailer/templates/view.text.erb
File renamed without changes.
View
4 railties/lib/generators/rails/mailer/templates/mailer.rb
@@ -1,5 +1,5 @@
class <%= class_name %> < ActionMailer::Base
- delivers_from "mail@<%= application_name %>.com"
+ delivers_from "from@example.com"
<% for action in actions -%>
# Subject can be set in your I18n file at config/locales/en.yml
@@ -9,7 +9,7 @@ class <%= class_name %> < ActionMailer::Base
#
def <%= action %>
@greeting = "Hi"
- mail(:to => "")
+ mail(:to => "to@example.com")
end
<% end -%>
end
View
10 railties/lib/generators/test_unit/mailer/templates/functional_test.rb
@@ -3,17 +3,13 @@
class <%= class_name %>Test < ActionMailer::TestCase
<% for action in actions -%>
test "<%= action %>" do
- @actual = <%= class_name %>.<%= action %>
-
@expected.subject = <%= action.to_s.humanize.inspect %>
+ @expected.to = "to@example.com"
+ @expected.from = "from@example.com"
@expected.body = read_fixture("<%= action %>")
@expected.date = Time.now
- assert_difference "<%= class_name %>.deliveries.size" do
- @actual.deliver
- end
-
- assert_equal @expected.encoded, @actual.encoded
+ assert_equal @expected, <%= class_name %>.<%= action %>
end
<% end -%>
View
11 railties/test/generators/mailer_generator_test.rb
@@ -6,11 +6,10 @@ class MailerGeneratorTest < Rails::Generators::TestCase
arguments %w(notifier foo bar)
def test_mailer_skeleton_is_created
- Rails.stubs(:application).returns(Object.new)
run_generator
assert_file "app/mailers/notifier.rb" do |mailer|
assert_match /class Notifier < ActionMailer::Base/, mailer
- assert_match /delivers_from "mail@object.com"/, mailer
+ assert_match /delivers_from "from@example.com"/, mailer
end
end
@@ -36,12 +35,12 @@ def test_invokes_default_test_framework
def test_invokes_default_template_engine
run_generator
- assert_file "app/views/notifier/foo.erb" do |view|
+ assert_file "app/views/notifier/foo.text.erb" do |view|
assert_match /app\/views\/notifier\/foo/, view
assert_match /<%= @greeting %>/, view
end
- assert_file "app/views/notifier/bar.erb" do |view|
+ assert_file "app/views/notifier/bar.text.erb" do |view|
assert_match /app\/views\/notifier\/bar/, view
assert_match /<%= @greeting %>/, view
end
@@ -62,12 +61,12 @@ def test_actions_are_turned_into_methods
assert_file "app/mailers/notifier.rb" do |mailer|
assert_instance_method :foo, mailer do |foo|
- assert_match /mail\(:to => ""\)/, foo
+ assert_match /mail\(:to => "to@example.com"\)/, foo
assert_match /@greeting = "Hi"/, foo
end
assert_instance_method :bar, mailer do |bar|
- assert_match /mail\(:to => ""\)/, bar
+ assert_match /mail\(:to => "to@example.com"\)/, bar
assert_match /@greeting = "Hi"/, bar
end
end
View
8 railties/test/generators/named_base_test.rb
@@ -67,6 +67,14 @@ def test_scaffold_plural_names_as_ruby
assert_name g, 'admin.foos', :controller_i18n_scope
end
+ def test_application_name
+ g = generator ['Admin::Foo']
+ Rails.stubs(:application).returns(Object.new)
+ assert_name g, "object", :application_name
+ Rails.stubs(:application).returns(nil)
+ assert_name g, "application", :application_name
+ end
+
protected
def assert_name(generator, value, method)

0 comments on commit 1b3cb54

Please sign in to comment.
Something went wrong with that request. Please try again.