<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>merb-mailer/spec/mailers/views/test_mail_controller/generates_absolute_url.text.erb</filename>
    </added>
    <added>
      <filename>merb-mailer/spec/mailers/views/test_mail_controller/generates_relative_url.text.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -6,21 +6,21 @@ module Merb
   # * Create a MailController subclass with actions and templates.
   # * Call the MailController from another Controller via the send_mail method.
   #
-  # First, create a file in app/mailers that subclasses Merb::MailController. 
+  # First, create a file in app/mailers that subclasses Merb::MailController.
   # The actions in this controller will do nothing but render mail.
   #
   #   # app/mailers/article_mailer.rb
   #   class ArticleMailer &lt; Merb::MailController
-  # 
+  #
   #     def notify
   #       @user = params[:user]
   #       render_mail
   #     end
-  # 
+  #
   #   end
   #
-  # You also can access the params hash for values passed with the 
-  # Controller.send_mail method. See also the documentation for 
+  # You also can access the params hash for values passed with the
+  # Controller.send_mail method. See also the documentation for
   # render_mail to see all the ways it can be called.
   #
   # Create a template in a subdirectory of app/mailers/views that corresponds
@@ -28,10 +28,10 @@ module Merb
   #
   #   # app/mailers/views/article_mailer/notify.text.erb
   #   Hey, &lt;%= @user.name %&gt;,
-  #   
+  #
   #   We're running a sale on dog bones!
   #
-  # Finally, call the Controller.send_mail method from a standard 
+  # Finally, call the Controller.send_mail method from a standard
   # Merb controller.
   #
   #   class Articles &lt; Application
@@ -47,13 +47,13 @@ module Merb
   #       render
   #     end
   #
-  #   end  
+  #   end
   #
   # Note: If you don't pass a fourth argument to Controller.send_mail,
   # the controller's params will be sent to the MailController subclass
-  # as params. However, you can explicitly send a hash of objects that 
-  # will populate the params hash instead. In either case, you must 
-  # set instance variables in the MailController's actions if you 
+  # as params. However, you can explicitly send a hash of objects that
+  # will populate the params hash instead. In either case, you must
+  # set instance variables in the MailController's actions if you
   # want to use them in the MailController's views.
   #
   # The MailController class is very powerful. You can:
@@ -91,15 +91,15 @@ module Merb
     def _template_location(action, type = nil, controller = controller_name)
       &quot;#{controller}/#{action}.#{type}&quot;
     end
-    
-    # The location to look for a template and mime-type. This is overridden 
-    # from AbstractController, which defines a version of this that does not 
+
+    # The location to look for a template and mime-type. This is overridden
+    # from AbstractController, which defines a version of this that does not
     # involve mime-types.
     #
     # ==== Parameters
-    # template&lt;String&gt;:: 
+    # template&lt;String&gt;::
     #    The absolute path to a template - without mime and template extension.
-    #    The mime-type extension is optional - it will be appended from the 
+    #    The mime-type extension is optional - it will be appended from the
     #    current content type if it hasn't been added already.
     # type&lt;~to_s&gt;::
     #    The mime-type of the template that will be rendered. Defaults to nil.
@@ -126,7 +126,7 @@ module Merb
     #
     # ==== Parameters
     # klass&lt;Class&gt;::
-    #   The Merb::MailController inheriting from the base class.  
+    #   The Merb::MailController inheriting from the base class.
     def self.inherited(klass)
       super
       klass._template_root = Merb.dir_for(:mailer) / &quot;views&quot; unless self._template_root
@@ -172,7 +172,7 @@ module Merb
     # &quot;foo&quot;, this is identical to render_mail :foo.
     #
     #   render_mail :foo
-    # 
+    #
     # checks for foo.html.ext and foo.text.ext and applies them as appropriate.
     #
     #   render_mail :action =&gt; {:html =&gt; :foo, :text =&gt; :bar}
@@ -213,13 +213,13 @@ module Merb
       @_missing_templates = false # used to make sure that at least one template was found
       # If the options are not a hash, normalize to an action hash
       options = {:action =&gt; {:html =&gt; options, :text =&gt; options}} if !options.is_a?(Hash)
-  
+
       # Take care of the options
       opts_hash = {}
       opts = options.dup
       actions = opts.delete(:action) if opts[:action].is_a?(Hash)
       templates = opts.delete(:template) if opts[:template].is_a?(Hash)
-  
+
       # Prepare the options hash for each format
       # We need to delete anything relating to the other format here
       # before we try to render the template.
@@ -228,7 +228,7 @@ module Merb
         opts_hash[fmt] ||= actions[fmt] if actions &amp;&amp; actions[fmt]
         opts_hash[:template] = templates[fmt] if templates &amp;&amp; templates[fmt]
       end
-        
+
       # Send the result to the mailer
       { :html =&gt; &quot;rawhtml=&quot;, :text =&gt; &quot;text=&quot;}.each do |fmt,meth|
         begin
@@ -252,14 +252,21 @@ module Merb
 
     # Mimic the behavior of absolute_url in AbstractController
     # but use @base_controller.request
-    def absolute_url(name, rparams={})
-      req = @base_controller.request
-      uri =  req.protocol + req.host + url(name, rparams)
+    def url(name, *args)
+      self.base_controller.request.generate_url(name, *args)
+    end
+
+    alias_method :relative_url, :url
+
+    # Mimic the behavior of absolute_url in AbstractController
+    # but use @base_controller.request
+    def absolute_url(name, *args)
+      self.base_controller.request.generate_absolute_url(name, *args)
     end
 
     # Attaches a file or multiple files to an email. You call this from a
     # method in your MailController (including a before filter).
-    # 
+    #
     # ==== Parameters
     # file_or_files&lt;File, Array[File]&gt;:: File(s) to attach.
     # filename&lt;String&gt;::
@@ -271,17 +278,17 @@ module Merb
     # ==== Examples
     #   attach File.open(&quot;foo&quot;)
     #   attach [File.open(&quot;foo&quot;), File.open(&quot;bar&quot;)]
-    # 
+    #
     # If you are passing an array of files, you should use an array of the
     # allowed parameters:
-    # 
+    #
     #   attach [[File.open(&quot;foo&quot;), &quot;bar&quot;, &quot;text/html&quot;], [File.open(&quot;baz&quot;),
     #     &quot;bat&quot;, &quot;text/css&quot;]
-    # 
+    #
     #  which would attach two files (&quot;foo&quot; and &quot;baz&quot; in the filesystem) as
     # &quot;bar&quot; and &quot;bat&quot; respectively. It would also set the mime-type as
     # &quot;text/html&quot; and &quot;text/css&quot; respectively.
-    def attach( file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil, 
+    def attach( file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil,
       type = nil, headers = nil)
       @mailer.attach(file_or_files, filename, type, headers)
     end
@@ -305,7 +312,7 @@ module Merb
       @mailer         = self.class._mailer_klass.new(mail_params)
       @mail           = @mailer.mail
       @method         = method
-  
+
       # dispatch and render use params[:action], so set it
       self.action_name = method
 </diff>
      <filename>merb-mailer/lib/merb-mailer/mail_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,8 @@
 require File.dirname(__FILE__) + '/spec_helper'
 
 Spec::Runner.configure do |config|
-  config.include Merb::Test::RequestHelper  
+  config.include Merb::Test::RequestHelper
+  config.include Merb::Test::ControllerHelper
 end
 
 class Merb::Mailer
@@ -48,19 +49,32 @@ class TestMailController &lt; Merb::MailController
   def ninth
     render_mail
   end
-  
+
   def tenth
     render_mail
   end
   
+  def generates_relative_url
+    render_mail
+  end
+
+  def generates_absolute_url
+    render_mail
+  end
+end
+
+
+Merb::Router.prepare do
+  match(&quot;/subprojects/:subproject&quot;).
+    to(:controller =&gt; &quot;test_controller&quot;, :action =&gt; &quot;whatever&quot;).
+    name(:merb_subproject)
 end
 
+
 class TestController &lt; Merb::Controller
-  
   def one
     send_mail TestMailController, :ninth, {:from =&gt; &quot;foo@bar.com&quot;, :to =&gt; &quot;foo@bar.com&quot;}, {:x =&gt; &quot;ONE_CONTROLLER&quot;}
   end
-  
 end
 
 describe &quot;A Merb Mail controller&quot; do
@@ -138,37 +152,20 @@ describe &quot;A Merb Mail controller&quot; do
     Merb.logger.should_receive(:error).once
     deliver :tenth
   end
-  
-end
 
-# describe &quot;Merb::MailController with url generation&quot; do
-#   
-#   it_should_behave_like &quot;class with general url generation&quot;
-#   it_should_behave_like &quot;non routeable controller with url mixin&quot;
-#   
-#   def new_url_controller(route, params = {:action =&gt; 'show', :controller =&gt; 'Test'})
-#     request = OpenStruct.new
-#     request.route = route
-#     request.params = params
-#     response = OpenStruct.new
-#     response.read = &quot;&quot;
-#     
-#     @controller = Merb::Controller.build(request, response)
-#     TestMailController.new(params, @controller)
-#   end
-#   
-#   it &quot;should raise an error if no controller is specified and the base controller is not set&quot; do
-#     c = new_url_controller(@default_route, {})    
-#     lambda do
-#       the_url = c.url(:action =&gt; &quot;bar&quot;)
-#     end.should raise_error
-#   end
-#   
-#   it &quot;should use the base controller when it is set to generate a url when no :controller option is specified&quot; do
-#     c = new_url_controller(@defualt_route, :controller =&gt; &quot;foo&quot;)
-#     lambda do
-#       the_url = c.url(:action =&gt; &quot;bar&quot;)
-#       the_url.should == &quot;/foo/bar&quot;
-#     end.should_not raise_error    
-#   end
-# end
+  it &quot;delegates relative url generation to base controller&quot; do
+    controller = TestController.new(fake_request)
+    TestMailController.new({ :subproject =&gt; &quot;core&quot; }, controller).
+      dispatch_and_deliver :generates_relative_url, :from =&gt; &quot;foo@bar.com&quot;, :to =&gt; &quot;foo@bar.com&quot;
+    
+    Merb::Mailer.deliveries.last.text.should == &quot;TEXT\n/subprojects/core\nENDTEXT&quot;
+  end
+
+  it &quot;delegates relative url generation to base controller&quot; do
+    controller = TestController.new(fake_request)
+    TestMailController.new({ :subproject =&gt; &quot;extlib&quot; }, controller).
+      dispatch_and_deliver :generates_absolute_url, :from =&gt; &quot;foo@bar.com&quot;, :to =&gt; &quot;foo@bar.com&quot;
+    
+    Merb::Mailer.deliveries.last.text.should == &quot;TEXT\nhttp://merbivore.com/subprojects/extlib\nENDTEXT&quot;
+  end
+end</diff>
      <filename>merb-mailer/spec/mail_controller_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6a480e81ca9dc765cf90506abd607ff3c0e6e6c2</id>
    </parent>
  </parents>
  <author>
    <name>Michael S. Klishin</name>
    <email>michael@novemberain.com</email>
  </author>
  <url>http://github.com/wycats/merb-more/commit/caa348607393a55ffd586ab880f49d91acb1c772</url>
  <id>caa348607393a55ffd586ab880f49d91acb1c772</id>
  <committed-date>2008-09-25T03:54:51-07:00</committed-date>
  <authored-date>2008-09-25T03:50:29-07:00</authored-date>
  <message>Make url generation work properly in mail controllers.

* Add 2 spec examples for absolute and relative urls generation.
* Implement url and absolute_url that really mimic AbstractController behavior.</message>
  <tree>614036efa1781d5be6302543bdbcc5307446bc7f</tree>
  <committer>
    <name>Michael S. Klishin</name>
    <email>michael@novemberain.com</email>
  </committer>
</commit>
