Tests!
This commit is contained in:
parent
6e3d183c40
commit
21d60e359a
12 changed files with 242 additions and 20 deletions
|
@ -1891,15 +1891,6 @@ EOF
|
|||
end
|
||||
assert_response :success
|
||||
|
||||
assert_difference "ChangesetComment.count", 1 do
|
||||
assert_no_difference "ActionMailer::Base.deliveries.size" do
|
||||
post :comment, :id => changesets(:normal_user_subscribed_change).id, :text => "This is a comment"
|
||||
end
|
||||
end
|
||||
assert_response :success
|
||||
|
||||
basic_authorization(users(:second_public_user).email, "test")
|
||||
|
||||
assert_difference "ChangesetComment.count", 1 do
|
||||
assert_difference "ActionMailer::Base.deliveries.size", 1 do
|
||||
post :comment, :id => changesets(:normal_user_subscribed_change).id, :text => "This is a comment"
|
||||
|
@ -1909,6 +1900,27 @@ EOF
|
|||
|
||||
email = ActionMailer::Base.deliveries.first
|
||||
assert_equal 1, email.to.length
|
||||
assert_equal "[OpenStreetMap] test2 has commented on one of your changesets", email.subject
|
||||
assert_equal "test@openstreetmap.org", email.to.first
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
basic_authorization(users(:second_public_user).email, "test")
|
||||
|
||||
assert_difference "ChangesetComment.count", 1 do
|
||||
assert_difference "ActionMailer::Base.deliveries.size", 2 do
|
||||
post :comment, :id => changesets(:normal_user_subscribed_change).id, :text => "This is a comment"
|
||||
end
|
||||
end
|
||||
assert_response :success
|
||||
|
||||
email = ActionMailer::Base.deliveries.first
|
||||
assert_equal 1, email.to.length
|
||||
assert_equal "[OpenStreetMap] pulibc_test2 has commented on one of your changesets", email.subject
|
||||
assert_equal "test@openstreetmap.org", email.to.first
|
||||
|
||||
email = ActionMailer::Base.deliveries.second
|
||||
assert_equal 1, email.to.length
|
||||
assert_equal "[OpenStreetMap] pulibc_test2 has commented on a changeset you are interested in", email.subject
|
||||
assert_equal "test@example.com", email.to.first
|
||||
|
||||
|
|
|
@ -147,6 +147,32 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
|||
assert_equal new_language_code, entry.language_code
|
||||
end
|
||||
|
||||
def test_new_spammy
|
||||
# Generate some spammy content
|
||||
spammy_title = "Spam Spam Spam Spam Spam"
|
||||
spammy_body = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
|
||||
|
||||
# Try creating a spammy diary entry
|
||||
assert_difference "DiaryEntry.count", 1 do
|
||||
post :new, { :commit => "save",
|
||||
:diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" } },
|
||||
{ :user => users(:normal_user).id }
|
||||
end
|
||||
assert_response :redirect
|
||||
assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
|
||||
entry = DiaryEntry.order(:id).last
|
||||
assert_equal users(:normal_user).id, entry.user_id
|
||||
assert_equal spammy_title, entry.title
|
||||
assert_equal spammy_body, entry.body
|
||||
assert_equal "en", entry.language_code
|
||||
assert_equal "suspended", User.find(users(:normal_user).id).status
|
||||
|
||||
# Follow the redirect
|
||||
get :list, { :display_name => users(:normal_user).display_name }, { :user => users(:normal_user).id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to :controller => :user, :action => :suspended
|
||||
end
|
||||
|
||||
def test_edit
|
||||
entry = diary_entries(:normal_user_entry_1)
|
||||
|
||||
|
@ -287,7 +313,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
|||
assert_match /New comment/, email.text_part.decoded
|
||||
assert_match /New comment/, email.html_part.decoded
|
||||
ActionMailer::Base.deliveries.clear
|
||||
comment = DiaryComment.find(5)
|
||||
comment = DiaryComment.order(:id).last
|
||||
assert_equal entry.id, comment.diary_entry_id
|
||||
assert_equal users(:public_user).id, comment.user_id
|
||||
assert_equal "New comment", comment.body
|
||||
|
@ -296,13 +322,51 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
|||
get :view, :display_name => entry.user.display_name, :id => entry.id
|
||||
assert_response :success
|
||||
assert_select ".diary-comment", :count => 1 do
|
||||
assert_select "#comment5", :count => 1 do
|
||||
assert_select "#comment#{comment.id}", :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
|
||||
|
||||
def test_comment_spammy
|
||||
# Find the entry to comment on
|
||||
entry = diary_entries(:normal_user_entry_1)
|
||||
|
||||
# Generate some spammy content
|
||||
spammy_text = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
|
||||
|
||||
# Try creating a spammy comment
|
||||
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 => spammy_text } }, { :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 %r{http://example.com/spam}, email.text_part.decoded
|
||||
assert_match %r{http://example.com/spam}, email.html_part.decoded
|
||||
ActionMailer::Base.deliveries.clear
|
||||
comment = DiaryComment.order(:id).last
|
||||
assert_equal entry.id, comment.diary_entry_id
|
||||
assert_equal users(:public_user).id, comment.user_id
|
||||
assert_equal spammy_text, comment.body
|
||||
assert_equal "suspended", User.find(users(:public_user).id).status
|
||||
|
||||
# Follow the redirect
|
||||
get :list, { :display_name => users(:normal_user).display_name }, { :user => users(:public_user).id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to :controller => :user, :action => :suspended
|
||||
|
||||
# Now view the diary entry, and check the new comment is not present
|
||||
get :view, :display_name => entry.user.display_name, :id => entry.id
|
||||
assert_response :success
|
||||
assert_select ".diary-comment", :count => 0
|
||||
end
|
||||
|
||||
def test_list_all
|
||||
# Try a list of all diary entries
|
||||
get :list
|
||||
|
|
|
@ -281,6 +281,48 @@ class NotesControllerTest < ActionController::TestCase
|
|||
assert_nil js["properties"]["comments"].last["user"]
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
basic_authorization(users(:public_user).email, "test")
|
||||
|
||||
assert_difference "NoteComment.count", 1 do
|
||||
assert_difference "ActionMailer::Base.deliveries.size", 2 do
|
||||
post :comment, :id => notes(:note_with_comments_by_users).id, :text => "This is an additional comment", :format => "json"
|
||||
end
|
||||
end
|
||||
assert_response :success
|
||||
js = ActiveSupport::JSON.decode(@response.body)
|
||||
assert_not_nil js
|
||||
assert_equal "Feature", js["type"]
|
||||
assert_equal notes(:note_with_comments_by_users).id, js["properties"]["id"]
|
||||
assert_equal "open", js["properties"]["status"]
|
||||
assert_equal 4, js["properties"]["comments"].count
|
||||
assert_equal "commented", js["properties"]["comments"].last["action"]
|
||||
assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
|
||||
assert_equal "test2", js["properties"]["comments"].last["user"]
|
||||
|
||||
email = ActionMailer::Base.deliveries.first
|
||||
assert_equal 1, email.to.length
|
||||
assert_equal "[OpenStreetMap] test2 has commented on one of your notes", email.subject
|
||||
assert_equal "test@openstreetmap.org", email.to.first
|
||||
|
||||
email = ActionMailer::Base.deliveries.second
|
||||
assert_equal 1, email.to.length
|
||||
assert_equal "[OpenStreetMap] test2 has commented on a note you are interested in", email.subject
|
||||
assert_equal "public@OpenStreetMap.org", email.to.first
|
||||
|
||||
get :show, :id => notes(:note_with_comments_by_users).id, :format => "json"
|
||||
assert_response :success
|
||||
js = ActiveSupport::JSON.decode(@response.body)
|
||||
assert_not_nil js
|
||||
assert_equal "Feature", js["type"]
|
||||
assert_equal notes(:note_with_comments_by_users).id, js["properties"]["id"]
|
||||
assert_equal "open", js["properties"]["status"]
|
||||
assert_equal 4, js["properties"]["comments"].count
|
||||
assert_equal "commented", js["properties"]["comments"].last["action"]
|
||||
assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
|
||||
assert_equal "test2", js["properties"]["comments"].last["user"]
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
def test_comment_fail
|
||||
|
|
|
@ -199,6 +199,28 @@ class SiteControllerTest < ActionController::TestCase
|
|||
assert_template "index"
|
||||
end
|
||||
|
||||
# Test the right editor gets used when the URL has an override
|
||||
def test_edit_with_override
|
||||
get :edit, { :editor => "id" }, { :user => users(:public_user).id }
|
||||
assert_response :success
|
||||
assert_template "edit"
|
||||
assert_template :partial => "_id", :count => 1
|
||||
|
||||
get :edit, { :editor => "potlatch2" }, { :user => users(:public_user).id }
|
||||
assert_response :success
|
||||
assert_template "edit"
|
||||
assert_template :partial => "_potlatch2", :count => 1
|
||||
|
||||
get :edit, { :editor => "potlatch" }, { :user => users(:public_user).id }
|
||||
assert_response :success
|
||||
assert_template "edit"
|
||||
assert_template :partial => "_potlatch", :count => 1
|
||||
|
||||
get :edit, { :editor => "remote" }, { :user => users(:public_user).id }
|
||||
assert_response :success
|
||||
assert_template "index"
|
||||
end
|
||||
|
||||
# Test editing a specific node
|
||||
def test_edit_with_node
|
||||
user = users(:public_user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue