From 011cfa794a5f0d67a813b8f7969f4ecec36d74ec Mon Sep 17 00:00:00 2001
From: Andy Allan
Date: Wed, 9 May 2018 11:24:11 +0800
Subject: [PATCH] Use named paths for messages
---
app/models/notifier.rb | 11 +++--------
app/views/diary_entry/_diary_entry.html.erb | 2 +-
app/views/message/_message_summary.html.erb | 8 ++++----
app/views/message/_sent_message_summary.html.erb | 4 ++--
app/views/message/new.html.erb | 4 ++--
app/views/message/read.html.erb | 8 ++++----
app/views/user/_contact.html.erb | 2 +-
app/views/user/view.html.erb | 2 +-
test/controllers/message_controller_test.rb | 1 +
9 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/app/models/notifier.rb b/app/models/notifier.rb
index 4b61b202c..0944c3e1d 100644
--- a/app/models/notifier.rb
+++ b/app/models/notifier.rb
@@ -69,10 +69,8 @@ class Notifier < ActionMailer::Base
@from_user = message.sender.display_name
@text = message.body
@title = message.title
- @readurl = url_for(:controller => "message", :action => "read",
- :message_id => message.id)
- @replyurl = url_for(:controller => "message", :action => "reply",
- :message_id => message.id)
+ @readurl = read_message_url(message)
+ @replyurl = reply_message_url(message)
@author = @from_user
attach_user_avatar(message.sender)
@@ -99,10 +97,7 @@ class Notifier < ActionMailer::Base
:display_name => comment.diary_entry.user.display_name,
:id => comment.diary_entry.id,
:anchor => "newcomment")
- @replyurl = url_for(:controller => "message",
- :action => "new",
- :display_name => comment.user.display_name,
- :title => "Re: #{comment.diary_entry.title}")
+ @replyurl = new_message_url(comment.user, :message => { :title => "Re: #{comment.diary_entry.title}" })
@author = @from_user
diff --git a/app/views/diary_entry/_diary_entry.html.erb b/app/views/diary_entry/_diary_entry.html.erb
index 37e70f06d..802dd31f3 100644
--- a/app/views/diary_entry/_diary_entry.html.erb
+++ b/app/views/diary_entry/_diary_entry.html.erb
@@ -23,7 +23,7 @@
<% if params[:action] == 'list' %>
- <%= link_to t('.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %>
- - <%= link_to t('.reply_link'), :controller => 'message', :action => 'new', :display_name => diary_entry.user.display_name, :message => { :title => "Re: #{diary_entry.title}" } %>
+ - <%= link_to t('.reply_link'), new_message_path(diary_entry.user, :message => { :title => "Re: #{diary_entry.title}" }) %>
- <%= link_to t('.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %>
<% end %>
diff --git a/app/views/message/_message_summary.html.erb b/app/views/message/_message_summary.html.erb
index 43a6a4bbf..e9d8311fc 100644
--- a/app/views/message/_message_summary.html.erb
+++ b/app/views/message/_message_summary.html.erb
@@ -1,8 +1,8 @@
">
<%= link_to h(message_summary.sender.display_name), user_path(message_summary.sender) %> |
- <%= link_to h(message_summary.title), :controller => 'message', :action => 'read', :message_id => message_summary.id %> |
+ <%= link_to h(message_summary.title), read_message_path(message_summary) %> |
<%= l message_summary.sent_on, :format => :friendly %> |
- <%= button_to t('.unread_button'), {:controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'unread'}, { :remote => true } %> |
- <%= button_to t('.read_button'), {:controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read'}, { :remote => true } %> |
- <%= button_to t('.delete_button'), {:controller => 'message', :action => 'delete', :message_id => message_summary.id, :referer => request.fullpath}, { :remote => true } %> |
+ <%= button_to t('.unread_button'), mark_message_path(message_summary, :mark => 'unread'), { :remote => true } %> |
+ <%= button_to t('.read_button'), mark_message_path(message_summary, :mark => 'read'), { :remote => true } %> |
+ <%= button_to t('.delete_button'), delete_message_path(message_summary, :referer => request.fullpath), { :remote => true } %> |
diff --git a/app/views/message/_sent_message_summary.html.erb b/app/views/message/_sent_message_summary.html.erb
index 8b6201247..44eaa0bce 100644
--- a/app/views/message/_sent_message_summary.html.erb
+++ b/app/views/message/_sent_message_summary.html.erb
@@ -1,6 +1,6 @@
<%= link_to h(sent_message_summary.recipient.display_name), user_path(sent_message_summary.recipient) %> |
- <%= link_to h(sent_message_summary.title), :controller => 'message', :action => 'read', :message_id => sent_message_summary.id %> |
+ <%= link_to h(sent_message_summary.title), read_message_path(sent_message_summary) %> |
<%= l sent_message_summary.sent_on, :format => :friendly %> |
- <%= button_to t('.delete_button'), :controller => 'message', :action => 'delete', :message_id => sent_message_summary.id, :referer => request.fullpath %> |
+ <%= button_to t('.delete_button'), delete_message_path(sent_message_summary, :referer => request.fullpath) %> |
diff --git a/app/views/message/new.html.erb b/app/views/message/new.html.erb
index 44e919aa9..73d0ede2a 100644
--- a/app/views/message/new.html.erb
+++ b/app/views/message/new.html.erb
@@ -4,7 +4,7 @@
<%= error_messages_for 'message' %>
-<%= form_for :message, :html => { :class => 'standard-form' }, :url => { :action => "new", :display_name => @message.recipient.display_name } do |f| %>
+<%= form_for :message, :html => { :class => 'standard-form' }, :url => new_message_path(@message.recipient) do |f| %>
<% end %>
diff --git a/app/views/message/read.html.erb b/app/views/message/read.html.erb
index 668094d33..c18b586a4 100644
--- a/app/views/message/read.html.erb
+++ b/app/views/message/read.html.erb
@@ -14,9 +14,9 @@
<%= @message.body.to_html %>
- <%= button_to t('.reply_button'), {:controller => 'message', :action => 'reply', :message_id => @message.id}, :class => 'reply-button' %>
- <%= button_to t('.unread_button'), {:controller => 'message', :action => 'mark', :message_id => @message.id, :mark => 'unread'}, :class => 'mark-unread-button' %>
- <%= button_to t('.delete_button'), {:controller => 'message', :action => 'delete', :message_id => @message.id}, :class => 'delete-button' %>
+ <%= button_to t('.reply_button'), reply_message_path(@message), :class => 'reply-button' %>
+ <%= button_to t('.unread_button'), mark_message_path(@message, :mark => 'unread'), :class => 'mark-unread-button' %>
+ <%= button_to t('.delete_button'), delete_message_path(@message), :class => 'delete-button' %>
<% else %>
@@ -36,5 +36,5 @@
<% end %>
- <%= link_to t('.back'), {:controller => 'message', :action => 'outbox', :display_name => current_user.display_name }, :class => "button deemphasize" %>
+ <%= link_to t('.back'), outbox_path(current_user), :class => "button deemphasize" %>
diff --git a/app/views/user/_contact.html.erb b/app/views/user/_contact.html.erb
index 2697d0302..613283371 100644
--- a/app/views/user/_contact.html.erb
+++ b/app/views/user/_contact.html.erb
@@ -35,7 +35,7 @@
- - <%= link_to t('user.view.send message'), :controller => 'message', :action => 'new', :display_name => contact.display_name %>
+ - <%= link_to t('user.view.send message'), new_message_path(contact) %>
-
<% if current_user.is_friends_with?(contact) %>
<%= link_to t('user.view.remove as friend'), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
diff --git a/app/views/user/view.html.erb b/app/views/user/view.html.erb
index bc70545f5..cc4bbf8a6 100644
--- a/app/views/user/view.html.erb
+++ b/app/views/user/view.html.erb
@@ -63,7 +63,7 @@
-
- <%= link_to t('.send message'), :controller => 'message', :action => 'new', :display_name => @user.display_name %>
+ <%= link_to t('.send message'), new_message_path(@user) %>
-
<%= link_to t('.diary'), :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %>
diff --git a/test/controllers/message_controller_test.rb b/test/controllers/message_controller_test.rb
index 930341f29..3810c57c3 100644
--- a/test/controllers/message_controller_test.rb
+++ b/test/controllers/message_controller_test.rb
@@ -178,6 +178,7 @@ class MessageControllerTest < ActionController::TestCase
assert_equal "[OpenStreetMap] Test Message", e.subject
assert_match /Test message body/, e.text_part.decoded
assert_match /Test message body/, e.html_part.decoded
+ assert_match %r{#{SERVER_URL}/message/read/}, e.text_part.decoded
ActionMailer::Base.deliveries.clear
m = Message.last
assert_equal user.id, m.from_user_id
--
2.39.5