Merge branch 'master' into notes
This commit is contained in:
commit
8090e086da
8 changed files with 123 additions and 20 deletions
|
@ -70,6 +70,8 @@ class DiaryEntryController < ApplicationController
|
|||
else
|
||||
render :action => 'view'
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :action => "no_such_entry", :status => :not_found
|
||||
end
|
||||
|
||||
def list
|
||||
|
|
|
@ -100,11 +100,9 @@ class MessageController < ApplicationController
|
|||
notice = t 'message.mark.as_read'
|
||||
end
|
||||
@message.message_read = message_read
|
||||
if @message.save
|
||||
if not request.xhr?
|
||||
flash[:notice] = notice
|
||||
redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
|
||||
end
|
||||
if @message.save and not request.xhr?
|
||||
flash[:notice] = notice
|
||||
redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
@title = t'message.no_such_message.title'
|
||||
|
@ -113,10 +111,10 @@ class MessageController < ApplicationController
|
|||
|
||||
# Delete the message.
|
||||
def delete
|
||||
message = Message.where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).find(params[:message_id])
|
||||
message.from_user_visible = false if message.sender == @user
|
||||
message.to_user_visible = false if message.recipient == @user
|
||||
if message.save
|
||||
@message = Message.where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).find(params[:message_id])
|
||||
@message.from_user_visible = false if @message.sender == @user
|
||||
@message.to_user_visible = false if @message.recipient == @user
|
||||
if @message.save and not request.xhr?
|
||||
flash[:notice] = t 'message.delete.deleted'
|
||||
|
||||
if params[:referer]
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
<td class="inbox-sent"><%= l message_summary.sent_on, :format => :friendly %></td>
|
||||
<td class="inbox-mark-unread"><%= button_to t('message.message_summary.unread_button'), {:controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'unread'}, { :remote => true } %></td>
|
||||
<td class="inbox-mark-read"><%= button_to t('message.message_summary.read_button'), {:controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read'}, { :remote => true } %></td>
|
||||
<td><%= button_to t('message.message_summary.delete_button'), :controller => 'message', :action => 'delete', :message_id => message_summary.id, :referer => request.fullpath %></td>
|
||||
<td><%= button_to t('message.message_summary.delete_button'), {:controller => 'message', :action => 'delete', :message_id => message_summary.id, :referer => request.fullpath}, { :remote => true } %></td>
|
||||
</tr>
|
||||
|
|
5
app/views/message/delete.js.erb
Normal file
5
app/views/message/delete.js.erb
Normal file
|
@ -0,0 +1,5 @@
|
|||
$("#inboxanchor").replaceWith("<%=j render :partial => "layouts/inbox" %>");
|
||||
$("#inbox-count").replaceWith("<%=j render :partial => "message_count" %>");
|
||||
$("#inbox-<%= @message.id %>").fadeOut(800, "linear", function () {
|
||||
$(this).remove();
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Your secret key for verifying the integrity of signed cookies.
|
||||
# If you change this key, all old signed cookies will become invalid!
|
||||
# Make sure the secret is at least 30 characters and all random,
|
||||
# no regular words or you'll be exposed to dictionary attacks.
|
||||
OpenStreetMap::Application.config.secret_token = '67881c9e6670d9b55b43885ea8eab34e32865ce436bdbde73e1967a11a26674906736de0aa1a0d24edf8ebcb653e1735413e6fd24e1201338e397d4a2392c614'
|
|
@ -1264,14 +1264,12 @@ en:
|
|||
wrong_user: "You are logged in as `%{user}' but the message you have asked to reply to was not sent to that user. Please login as the correct user in order to reply."
|
||||
read:
|
||||
title: "Read message"
|
||||
reading_your_messages: "Reading your messages"
|
||||
from: "From"
|
||||
subject: "Subject"
|
||||
date: "Date"
|
||||
reply_button: "Reply"
|
||||
unread_button: "Mark as unread"
|
||||
back_to_inbox: "Back to inbox"
|
||||
reading_your_sent_messages: "Reading your sent messages"
|
||||
to: "To"
|
||||
back_to_outbox: "Back to outbox"
|
||||
wrong_user: "You are logged in as `%{user}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it."
|
||||
|
|
|
@ -7,16 +7,19 @@ exit 0 unless recipient = ARGV[0].match(/^([cm])-(\d+)-(.*)$/)
|
|||
if recipient[1] == "c"
|
||||
comment = DiaryComment.find(recipient[2])
|
||||
digest = comment.digest
|
||||
date = diary_comment.created_at
|
||||
from = comment.diary_entry.user
|
||||
to = comment.user
|
||||
else
|
||||
message = Message.find(recipient[2])
|
||||
digest = message.digest
|
||||
date = message.sent_on
|
||||
from = message.recipient
|
||||
to = message.sender
|
||||
end
|
||||
|
||||
exit 0 unless recipient[3] == digest[0,6]
|
||||
exit 0 if date < 1.month.ago
|
||||
|
||||
message.update_attribute(:message_read, true) if message
|
||||
|
||||
|
|
|
@ -259,11 +259,115 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
def test_create_diary_entry
|
||||
#post :new
|
||||
@request.cookies["_osm_username"] = users(:normal_user).display_name
|
||||
|
||||
# Make sure that you are redirected to the login page when you
|
||||
# are not logged in
|
||||
get :new
|
||||
assert_response :redirect
|
||||
assert_redirected_to :controller => :user, :action => :login, :referer => "/diary/new"
|
||||
|
||||
# Now try again when logged in
|
||||
get :new, {}, {:user => users(:normal_user).id}
|
||||
assert_response :success
|
||||
assert_select "html", :count => 1 do
|
||||
assert_select "head", :count => 1 do
|
||||
assert_select "title", :text => /New Diary Entry/, :count => 1
|
||||
end
|
||||
assert_select "body", :count => 1 do
|
||||
assert_select "div.wrapper", :count => 1 do
|
||||
assert_select "div.content-heading", :count => 1 do
|
||||
assert_select "h1", :text => /New Diary Entry/, :count => 1
|
||||
end
|
||||
assert_select "div#content", :count => 1 do
|
||||
assert_select "form[action='/diary/new'][method=post]", :count => 1 do
|
||||
assert_select "input#diary_entry_title[name='diary_entry[title]']", :count => 1
|
||||
assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => "", :count => 1
|
||||
assert_select "select#diary_entry_language_code", :count => 1
|
||||
assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1
|
||||
assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1
|
||||
assert_select "input[name=commit][type=submit][value=Save]", :count => 1
|
||||
assert_select "input[name=commit][type=submit][value=Edit]", :count => 1
|
||||
assert_select "input[name=commit][type=submit][value=Preview]", :count => 1
|
||||
assert_select "input", :count => 7
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Now try creating a diary entry
|
||||
new_title = "New Title"
|
||||
new_body = "This is a new body for the diary entry"
|
||||
new_latitude = "1.1"
|
||||
new_longitude = "2.2"
|
||||
new_language_code = "en"
|
||||
assert_difference "DiaryEntry.count", 1 do
|
||||
post(:new, {'commit' => 'save',
|
||||
'diary_entry'=>{'title' => new_title, 'body' => new_body, 'latitude' => new_latitude,
|
||||
'longitude' => new_longitude, 'language_code' => new_language_code} },
|
||||
{:user => users(:normal_user).id})
|
||||
end
|
||||
assert_response :redirect
|
||||
assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
|
||||
entry = DiaryEntry.find(4)
|
||||
assert_equal users(:normal_user).id, entry.user_id
|
||||
assert_equal new_title, entry.title
|
||||
assert_equal new_body, entry.body
|
||||
assert_equal new_latitude.to_f, entry.latitude
|
||||
assert_equal new_longitude.to_f, entry.longitude
|
||||
assert_equal new_language_code, entry.language_code
|
||||
end
|
||||
|
||||
def test_creating_diary_comment
|
||||
@request.cookies["_osm_username"] = users(:public_user).display_name
|
||||
entry = diary_entries(:normal_user_entry_1)
|
||||
|
||||
# Make sure that you are denied when you are not logged in
|
||||
post :comment, :display_name => entry.user.display_name, :id => entry.id
|
||||
assert_response :forbidden
|
||||
|
||||
# Verify that you get a not found error, when you pass a bogus id
|
||||
post :comment, {:display_name => entry.user.display_name, :id => 9999}, {:user => users(:public_user).id}
|
||||
assert_response :not_found
|
||||
assert_select "html", :count => 1 do
|
||||
assert_select "body", :count => 1 do
|
||||
assert_select "div.wrapper", :count => 1 do
|
||||
assert_select "div.content-heading", :count => 1 do
|
||||
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Now try again with the right id
|
||||
assert_difference "ActionMailer::Base.deliveries.size", 1 do
|
||||
assert_difference "DiaryComment.count", 1 do
|
||||
post :comment, {:display_name => entry.user.display_name, :id => entry.id, :diary_comment => {:body => "New comment"}}, {:user => users(:public_user).id}
|
||||
end
|
||||
end
|
||||
assert_response :redirect
|
||||
assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
|
||||
email = ActionMailer::Base.deliveries.first
|
||||
assert_equal [ users(:normal_user).email ], email.to
|
||||
assert_equal "[OpenStreetMap] #{users(:public_user).display_name} commented on your diary entry", email.subject
|
||||
assert_match /New comment/, email.text_part.decoded
|
||||
assert_match /New comment/, email.html_part.decoded
|
||||
ActionMailer::Base.deliveries.clear
|
||||
comment = DiaryComment.find(4)
|
||||
assert_equal entry.id, comment.diary_entry_id
|
||||
assert_equal users(:public_user).id, comment.user_id
|
||||
assert_equal "New comment", comment.body
|
||||
|
||||
# Now view the diary entry, and check the new comment is present
|
||||
get :view, :display_name => entry.user.display_name, :id => entry.id
|
||||
assert_response :success
|
||||
assert_select ".diary-comment", :count => 1 do
|
||||
assert_select "#comment4", :count => 1 do
|
||||
assert_select "a[href='/user/#{users(:public_user).display_name}']", :text => users(:public_user).display_name, :count => 1
|
||||
end
|
||||
assert_select ".richtext", :text => /New comment/, :count => 1
|
||||
end
|
||||
end
|
||||
|
||||
# Check that you can get the expected response and template for all available languages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue