end
# Add the commenter to the subscribers if necessary
- @entry.subscriptions.create(user: @user) unless @entry.subscribers.exists?(@user)
+ @entry.subscriptions.create(user: @user) unless @entry.subscribers.exists?(@user.id)
redirect_to :controller => "diary_entry", :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
else
def subscribe
diary_entry = DiaryEntry.find(params[:id])
- diary_entry.subscriptions.create(user: @user) unless diary_entry.subscribers.exists?(@user)
+ diary_entry.subscriptions.create(user: @user) unless diary_entry.subscribers.exists?(@user.id)
redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
rescue ActiveRecord::RecordNotFound
def unsubscribe
diary_entry = DiaryEntry.find(params[:id])
- diary_entry.subscriptions.where(user: @user).delete_all if diary_entry.subscribers.exists?(@user)
+ diary_entry.subscriptions.where(user: @user).delete_all if diary_entry.subscribers.exists?(@user.id)
redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
rescue ActiveRecord::RecordNotFound
<%= richtext_area :diary_comment, :body, :cols => 80, :rows => 15 %>
<%= submit_tag t('diary_entry.view.save_button') %>
<% end %>
- <% if @user and @entry.subscribers and @entry.subscribers.exists?(@user) %>
+ <% if @user and @entry.subscribers and @entry.subscribers.exists?(@user.id) %>
<div style='position:relative; top: -30px; left: 130px'><%= link_to t('javascripts.changesets.show.unsubscribe'), diary_entry_unsubscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %></div>
<% elsif @user %>
<div style='position:relative; top: -30px; left: 130px'><%= link_to t('javascripts.changesets.show.subscribe'), diary_entry_subscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %></div>
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
end
+ post :subscribe, {:id => entry.id, :display_name => entry.user.display_name}, { :user => users(:normal_user).id}
+
# Now try an invalid comment with an empty body
assert_no_difference "ActionMailer::Base.deliveries.size" do
assert_no_difference "DiaryComment.count" do
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_equal "[OpenStreetMap] #{users(:public_user).display_name} commented on a diary entry", email.subject
assert_match /New comment/, email.text_part.decoded
assert_match /New comment/, email.html_part.decoded
ActionMailer::Base.deliveries.clear
def test_comment_spammy
# Find the entry to comment on
entry = create(:diary_entry, :user_id => users(:normal_user).id)
+ post :subscribe, {:id => entry.id, :display_name => entry.user.display_name}, { :user => users(:normal_user).id}
# Generate some spammy content
spammy_text = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
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_equal "[OpenStreetMap] #{users(:public_user).display_name} commented on a diary entry", email.subject
assert_match %r{http://example.com/spam}, email.text_part.decoded
assert_match %r{http://example.com/spam}, email.html_part.decoded
ActionMailer::Base.deliveries.clear
def test_unsubscribe_success
diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)
- assert_difference "diary_entry.subscribers.count", -1 do
- post :unsubscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:normal_user).id}
- end
- assert_response :redirect
-
post :subscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id}
assert_difference "diary_entry.subscribers.count", -1 do
post :unsubscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id}