]> source.dussan.org Git - redmine.git/commitdiff
Override @#url_for@ in AM to force generation of absolute links (#10251).
authorEtienne Massip <etienne.massip@gmail.com>
Mon, 27 Feb 2012 18:42:03 +0000 (18:42 +0000)
committerEtienne Massip <etienne.massip@gmail.com>
Mon, 27 Feb 2012 18:42:03 +0000 (18:42 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9022 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mailer.rb
app/views/mailer/_issue.html.erb
app/views/mailer/document_added.html.erb
app/views/mailer/issue_edit.html.erb
app/views/mailer/message_posted.html.erb
app/views/mailer/news_added.html.erb
app/views/mailer/news_comment_added.html.erb
app/views/mailer/reminder.html.erb
test/fixtures/journal_details.yml
test/fixtures/journals.yml
test/unit/mailer_test.rb

index 2502ce2e04f02d9ee1f494129481232099f5b2d4..5bb4f7e2cd5303541575648e477482f4522b7919 100644 (file)
@@ -30,6 +30,11 @@ class Mailer < ActionMailer::Base
     { :host => h, :protocol => Setting.protocol }
   end
 
+  def url_for(options)
+    options[:only_path] = false if options.is_a?(Hash)
+    super options
+  end
+
   # Builds a tmail object used to email recipients of the added issue.
   #
   # Example:
index 3d851d4428c99522fc9f322ee2393a8e8135eea8..c649e44c96249efe6ddd001e3a5e65d0bdf0d8d6 100644 (file)
@@ -12,4 +12,4 @@
 <% end %>
 </ul>
 
-<%= textilizable(issue, :description, :only_path => false) %>
+<%= textilizable(issue, :description) %>
index 8606dd784c6a2926ba45525d8d9f2e8e8b1e909d..be18e400d10953c50a49bde5cef97e5ac0e249de 100644 (file)
@@ -1,3 +1,3 @@
 <%= link_to(h(@document.title), @document_url) %> (<%=h @document.category.name %>)<br />
 <br />
-<%= textilizable(@document, :description, :only_path => false) %>
+<%= textilizable(@document, :description) %>
index 07288e379b54b0242f377eeade116f7d65e8dbef..da406f999c95ff0081eb1472c5efc56e670fac32 100644 (file)
@@ -6,6 +6,6 @@
 <% end %>
 </ul>
 
-<%= textilizable(@journal, :notes, :only_path => false) %>
+<%= textilizable(@journal, :notes) %>
 <hr />
 <%= render :partial => "issue.html.erb", :locals => { :issue => @issue, :issue_url => @issue_url } %>
index f43a8cf0f23a47c5e8797bfc5e213b2663e8a745..a8ccd2622140363e2abbaff8f4b070dc6e4e5954 100644 (file)
@@ -1,4 +1,4 @@
 <h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to(h(@message.subject), @message_url) %></h1>
 <em><%=h @message.author %></em>
 
-<%= textilizable(@message, :content, :only_path => false) %>
+<%= textilizable(@message, :content) %>
index 758ebccb8d0a7e1f1d2732e342acb3ea50baa309..9a024c09ef7c8cea64d67379cd9f270a278d7fbf 100644 (file)
@@ -1,4 +1,4 @@
 <h1><%= link_to(h(@news.title), @news_url) %></h1>
 <em><%=h @news.author.name %></em>
 
-<%= textilizable(@news, :description, :only_path => false) %>
+<%= textilizable(@news, :description) %>
index ef2be0f653bda45a18d093114090fca34c5784d1..b96de1489cc4128b265370c0a2a7f247fd6240bf 100644 (file)
@@ -2,4 +2,4 @@
 
 <p><%= l(:text_user_wrote, :value => h(@comment.author)) %></p>
 
-<%= textilizable @comment, :comments, :only_path => false %>
+<%= textilizable @comment, :comments %>
index f011da3e834c6ff28143299f83e341c3df2d4464..cfe8c977dac7bfc57dea9b184fcfb8b2fe57d399 100644 (file)
@@ -2,7 +2,7 @@
 
 <ul>
 <% @issues.each do |issue| -%>
-  <li><%=h issue.project %> - <%=link_to(h("#{issue.tracker} ##{issue.id}"), :controller => 'issues', :action => 'show', :id => issue, :only_path => false)%>: <%=h issue.subject %></li>
+  <li><%=h issue.project %> - <%=link_to(h("#{issue.tracker} ##{issue.id}"), :controller => 'issues', :action => 'show', :id => issue)%>: <%=h issue.subject %></li>
 <% end -%>
 </ul>
 
index 8077d7cde162d55e689117f5eda63eb2e8e7dcd1..710ebd438cb241380f13cd4f2834efbebc1b6897 100644 (file)
@@ -34,3 +34,10 @@ journal_details_005:
   value: New value
   prop_key: 2
   journal_id: 3
+journal_details_006:
+  old_value: nil
+  property: attachment
+  id: 6
+  value: 060719210727_picture.jpg
+  prop_key: 4
+  journal_id: 3
index 5bc81e41cf99ef2917315d4778e45353076fe97e..2156b780c17da5579cba99ef209db664ae8f716c 100644 (file)
@@ -1,5 +1,5 @@
 --- 
-journals_001: 
+journals_001:
   created_on: <%= 2.days.ago.to_date.to_s(:db) %>
   notes: "Journal notes"
   id: 1
@@ -13,21 +13,21 @@ journals_002:
   journalized_type: Issue
   user_id: 2
   journalized_id: 1
-journals_003: 
+journals_003:
   created_on: <%= 1.days.ago.to_date.to_s(:db) %>
-  notes: "A comment with inline image: !picture.jpg!"
+  notes: "A comment with inline image: !picture.jpg! and a reference to #1 and r2."
   id: 3
   journalized_type: Issue
   user_id: 2
   journalized_id: 2
-journals_004: 
+journals_004:
   created_on: <%= 1.days.ago.to_date.to_s(:db) %>
   notes: "A comment with a private version."
   id: 4
   journalized_type: Issue
   user_id: 1
   journalized_id: 6
-journals_005: 
+journals_005:
   id: 5
   created_on: <%= 1.days.ago.to_date.to_s(:db) %>
   notes: "A comment on a private issue."
index 0dec28c3eb42ff6de0544c409c0f2e4710fac90f..344e671f8c41e8fd85a1cead0987eb4b7968590c 100644 (file)
@@ -36,60 +36,80 @@ class MailerTest < ActiveSupport::TestCase
   end
 
   def test_generated_links_in_emails
+    Setting.default_language = 'en'
     Setting.host_name = 'mydomain.foo'
     Setting.protocol = 'https'
 
-    journal = Journal.find(2)
+    journal = Journal.find(3)
     assert Mailer.deliver_issue_edit(journal)
 
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert_not_nil mail
 
     assert_select_email do
       # link to the main ticket
-      assert_select "a[href=?]",
-                    "https://mydomain.foo/issues/1#change-2",
-                    :text => "Bug #1: Can't print recipes"
+      assert_select 'a[href=?]',
+                    'https://mydomain.foo/issues/2#change-3',
+                    :text => 'Feature request #2: Add ingredients categories'
       # link to a referenced ticket
-      assert_select "a[href=?][title=?]",
-                    "https://mydomain.foo/issues/2",
-                    "Add ingredients categories (Assigned)",
-                    :text => "#2"
+      assert_select 'a[href=?][title=?]',
+                    'https://mydomain.foo/issues/1',
+                    'Can\'t print recipes (New)',
+                    :text => '#1'
       # link to a changeset
-      assert_select "a[href=?][title=?]",
-                    "https://mydomain.foo/projects/ecookbook/repository/revisions/2",
-                    "This commit fixes #1, #2 and references #1 &amp; #3",
-                    :text => "r2"
+      assert_select 'a[href=?][title=?]',
+                    'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
+                    'This commit fixes #1, #2 and references #1 &amp; #3',
+                    :text => 'r2'
+      # link to a description diff
+      assert_select 'a[href=?][title=?]',
+                    'https://mydomain.foo/journals/diff/3?detail_id=4',
+                    'View differences',
+                    :text => 'diff'
+      # link to an attachment
+      assert_select 'a[href=?]',
+                    'https://mydomain.foo/attachments/download/4/source.rb',
+                    :text => 'source.rb'
     end
   end
 
   def test_generated_links_with_prefix
+    Setting.default_language = 'en'
     relative_url_root = Redmine::Utils.relative_url_root
     Setting.host_name = 'mydomain.foo/rdm'
     Setting.protocol = 'http'
     Redmine::Utils.relative_url_root = '/rdm'
 
-    journal = Journal.find(2)
+    journal = Journal.find(3)
     assert Mailer.deliver_issue_edit(journal)
 
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert_not_nil mail
 
     assert_select_email do
       # link to the main ticket
-      assert_select "a[href=?]",
-                    "http://mydomain.foo/rdm/issues/1#change-2",
-                    :text => "Bug #1: Can't print recipes"
+      assert_select 'a[href=?]',
+                    'http://mydomain.foo/rdm/issues/2#change-3',
+                    :text => 'Feature request #2: Add ingredients categories'
       # link to a referenced ticket
-      assert_select "a[href=?][title=?]",
-                    "http://mydomain.foo/rdm/issues/2",
-                    "Add ingredients categories (Assigned)",
-                    :text => "#2"
+      assert_select 'a[href=?][title=?]',
+                    'http://mydomain.foo/rdm/issues/1',
+                    'Can\'t print recipes (New)',
+                    :text => '#1'
       # link to a changeset
-      assert_select "a[href=?][title=?]",
-                    "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
-                    "This commit fixes #1, #2 and references #1 &amp; #3",
-                    :text => "r2"
+      assert_select 'a[href=?][title=?]',
+                    'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
+                    'This commit fixes #1, #2 and references #1 &amp; #3',
+                    :text => 'r2'
+      # link to a description diff
+      assert_select 'a[href=?][title=?]',
+                    'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
+                    'View differences',
+                    :text => 'diff'
+      # link to an attachment
+      assert_select 'a[href=?]',
+                    'http://mydomain.foo/rdm/attachments/download/4/source.rb',
+                    :text => 'source.rb'
     end
   ensure
     # restore it
@@ -97,32 +117,42 @@ class MailerTest < ActiveSupport::TestCase
   end
 
   def test_generated_links_with_prefix_and_no_relative_url_root
+    Setting.default_language = 'en'
     relative_url_root = Redmine::Utils.relative_url_root
     Setting.host_name = 'mydomain.foo/rdm'
     Setting.protocol = 'http'
     Redmine::Utils.relative_url_root = nil
 
-    journal = Journal.find(2)
+    journal = Journal.find(3)
     assert Mailer.deliver_issue_edit(journal)
 
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert_not_nil mail
 
     assert_select_email do
       # link to the main ticket
-      assert_select "a[href=?]",
-                    "http://mydomain.foo/rdm/issues/1#change-2",
-                    :text => "Bug #1: Can't print recipes"
+      assert_select 'a[href=?]',
+                    'http://mydomain.foo/rdm/issues/2#change-3',
+                    :text => 'Feature request #2: Add ingredients categories'
       # link to a referenced ticket
-      assert_select "a[href=?][title=?]",
-                    "http://mydomain.foo/rdm/issues/2",
-                    "Add ingredients categories (Assigned)",
-                    :text => "#2"
+      assert_select 'a[href=?][title=?]',
+                    'http://mydomain.foo/rdm/issues/1',
+                    'Can\'t print recipes (New)',
+                    :text => '#1'
       # link to a changeset
-      assert_select "a[href=?][title=?]",
-                    "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
-                    "This commit fixes #1, #2 and references #1 &amp; #3",
-                    :text => "r2"
+      assert_select 'a[href=?][title=?]',
+                    'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
+                    'This commit fixes #1, #2 and references #1 &amp; #3',
+                    :text => 'r2'
+      # link to a description diff
+      assert_select 'a[href=?][title=?]',
+                    'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
+                    'View differences',
+                    :text => 'diff'
+      # link to an attachment
+      assert_select 'a[href=?]',
+                    'http://mydomain.foo/rdm/attachments/download/4/source.rb',
+                    :text => 'source.rb'
     end
   ensure
     # restore it
@@ -132,7 +162,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_email_headers
     issue = Issue.find(1)
     Mailer.deliver_issue_add(issue)
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert_not_nil mail
     assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress')
     assert_equal 'auto-generated', mail.header_string('Auto-Submitted')
@@ -141,8 +171,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_email_headers_should_include_sender
     issue = Issue.find(1)
     Mailer.deliver_issue_add(issue)
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal issue.author.login, mail.header_string('X-Redmine-Sender')
   end
 
@@ -150,7 +179,7 @@ class MailerTest < ActiveSupport::TestCase
     Setting.plain_text_mail = 1
     journal = Journal.find(2)
     Mailer.deliver_issue_edit(journal)
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert_equal "text/plain", mail.content_type
     assert_equal 0, mail.parts.size
     assert !mail.encoded.include?('href')
@@ -160,7 +189,7 @@ class MailerTest < ActiveSupport::TestCase
     Setting.plain_text_mail = 0
     journal = Journal.find(2)
     Mailer.deliver_issue_edit(journal)
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert_equal 2, mail.parts.size
     assert mail.encoded.include?('href')
   end
@@ -169,8 +198,7 @@ class MailerTest < ActiveSupport::TestCase
     with_settings :mail_from => 'redmine@example.net' do
       Mailer.deliver_test(User.find(1))
     end
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal 'redmine@example.net', mail.from_addrs.first.address
   end
 
@@ -178,8 +206,7 @@ class MailerTest < ActiveSupport::TestCase
     with_settings :mail_from => 'Redmine app <redmine@example.net>' do
       Mailer.deliver_test(User.find(1))
     end
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal 'redmine@example.net', mail.from_addrs.first.address
     assert_equal 'Redmine app', mail.from_addrs.first.name
   end
@@ -208,8 +235,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_issue_add_message_id
     issue = Issue.find(1)
     Mailer.deliver_issue_add(issue)
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal Mailer.message_id_for(issue), mail.message_id
     assert_nil mail.references
   end
@@ -217,8 +243,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_issue_edit_message_id
     journal = Journal.find(1)
     Mailer.deliver_issue_edit(journal)
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal Mailer.message_id_for(journal), mail.message_id
     assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s
     assert_select_email do
@@ -231,8 +256,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_message_posted_message_id
     message = Message.find(1)
     Mailer.deliver_message_posted(message)
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal Mailer.message_id_for(message), mail.message_id
     assert_nil mail.references
     assert_select_email do
@@ -246,8 +270,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_reply_posted_message_id
     message = Message.find(3)
     Mailer.deliver_message_posted(message)
-    mail = ActionMailer::Base.deliveries.last
-    assert_not_nil mail
+    mail = last_email
     assert_equal Mailer.message_id_for(message), mail.message_id
     assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s
     assert_select_email do
@@ -425,7 +448,7 @@ class MailerTest < ActiveSupport::TestCase
       token.reload
       ActionMailer::Base.deliveries.clear
       assert Mailer.deliver_register(token)
-      mail = ActionMailer::Base.deliveries.last
+      mail = last_email
       assert_select_email do
         assert_select "a[href=?]",
                       "https://redmine.foo/account/activate?token=#{token.value}",
@@ -445,7 +468,7 @@ class MailerTest < ActiveSupport::TestCase
   def test_reminders
     Mailer.reminders(:days => 42)
     assert_equal 1, ActionMailer::Base.deliveries.size
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert mail.bcc.include?('dlopper@somenet.foo')
     assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
     assert_equal '1 issue(s) due in the next 42 days', mail.subject
@@ -460,7 +483,7 @@ class MailerTest < ActiveSupport::TestCase
 
       Mailer.reminders(:days => 42)
       assert_equal 1, ActionMailer::Base.deliveries.size
-      mail = ActionMailer::Base.deliveries.last
+      mail = last_email
       assert mail.bcc.include?('dlopper@somenet.foo')
       assert !mail.body.include?('Closed issue')
     end
@@ -471,7 +494,7 @@ class MailerTest < ActiveSupport::TestCase
     assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
     Mailer.reminders(:days => 42, :users => ['3'])
     assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert mail.bcc.include?('dlopper@somenet.foo')
     assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
   end
@@ -490,7 +513,7 @@ class MailerTest < ActiveSupport::TestCase
     user = User.find(1)
     user.language = 'fr'
     Mailer.deliver_account_activated(user)
-    mail = ActionMailer::Base.deliveries.last
+    mail = last_email
     assert mail.body.include?('Votre compte')
 
     assert_equal :it, current_language