Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a test for commenting on diary entries

  • Loading branch information...
commit 703663c4a2f1db3b0a0dd070e653bbccd7d36c1e 1 parent e29c47b
@tomhughes authored
View
2  app/controllers/diary_entry_controller.rb
@@ -70,6 +70,8 @@ def comment
else
render :action => 'view'
end
+ rescue ActiveRecord::RecordNotFound
+ render :action => "no_such_entry", :status => :not_found
end
def list
View
47 test/functional/diary_entry_controller_test.rb
@@ -320,7 +320,54 @@ def test_create_diary_entry
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
Please sign in to comment.
Something went wrong with that request. Please try again.