]> git.openstreetmap.org Git - rails.git/commitdiff
Use `assert_content` instead of `assert page.has_content?`
authorAndy Allan <git@gravitystorm.co.uk>
Thu, 6 Jan 2022 13:16:47 +0000 (13:16 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Thu, 6 Jan 2022 13:16:47 +0000 (13:16 +0000)
The assert_content comes from capybara, and gives a much more helpful
error message if the test fails.

test/system/confirmation_resend_test.rb
test/system/diary_entry_test.rb
test/system/issues_test.rb
test/system/preferences_test.rb
test/system/report_diary_comment_test.rb
test/system/report_diary_entry_test.rb
test/system/report_note_test.rb
test/system/report_user_test.rb
test/system/user_logout_test.rb
test/system/user_signup_test.rb

index 6bbde09e0a2dfd86dc5a084245a8d269d30bc498..f615a6321d55caee39e93079f6c5da1102e53e39 100644 (file)
@@ -20,7 +20,7 @@ class ConfirmationResendSystemTest < ApplicationSystemTestCase
   test "flash message should not contain raw html" do
     visit user_confirm_resend_path(@user)
 
-    assert page.has_content?("sent a new confirmation")
-    assert_not page.has_content?("<p>")
+    assert_content "sent a new confirmation"
+    assert_no_content "<p>"
   end
 end
index d60812e4ccf277fb7bacdf88045118f6d318252b..58992dafc66a1ed267d416fbe708f39777d7ff6c 100644 (file)
@@ -12,7 +12,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
 
     click_on "Send a message to the author"
 
-    assert page.has_content? "Send a new message"
+    assert_content "Send a new message"
     assert_equal "Re: #{@diary_entry.title}", page.find_field("Subject").value
   end
 
@@ -22,7 +22,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
     sign_in_as(create(:user))
     visit diary_entries_path
 
-    assert_not page.has_content? @deleted_entry.title
+    assert_no_content @deleted_entry.title
   end
 
   test "deleted diary entries should be shown to administrators for review" do
@@ -31,7 +31,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
     sign_in_as(create(:administrator_user))
     visit diary_entries_path
 
-    assert page.has_content? @deleted_entry.title
+    assert_content @deleted_entry.title
   end
 
   test "deleted diary entries should not be shown to admins when the user is also deleted" do
@@ -41,7 +41,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
     sign_in_as(create(:administrator_user))
     visit diary_entries_path
 
-    assert_not page.has_content? @deleted_entry.title
+    assert_no_content @deleted_entry.title
   end
 
   test "deleted diary comments should be hidden for regular users" do
@@ -50,7 +50,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
     sign_in_as(create(:user))
     visit diary_entry_path(@diary_entry.user, @diary_entry)
 
-    assert_not page.has_content? @deleted_comment.body
+    assert_no_content @deleted_comment.body
   end
 
   test "deleted diary comments should be shown to administrators" do
@@ -59,6 +59,6 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
     sign_in_as(create(:administrator_user))
     visit diary_entry_path(@diary_entry.user, @diary_entry)
 
-    assert page.has_content? @deleted_comment.body
+    assert_content @deleted_comment.body
   end
 end
index 55e8b1b26a4a81c5577629149be35d876dc0e287..6a7094151ec245a038233d3304249485338dded3 100644 (file)
@@ -5,21 +5,21 @@ class IssuesTest < ApplicationSystemTestCase
 
   def test_view_issues_not_logged_in
     visit issues_path
-    assert page.has_content?(I18n.t("sessions.new.title"))
+    assert_content I18n.t("sessions.new.title")
   end
 
   def test_view_issues_normal_user
     sign_in_as(create(:user))
 
     visit issues_path
-    assert page.has_content?("Forbidden")
+    assert_content "Forbidden"
   end
 
   def test_view_no_issues
     sign_in_as(create(:moderator_user))
 
     visit issues_path
-    assert page.has_content?(I18n.t("issues.index.issues_not_found"))
+    assert_content I18n.t("issues.index.issues_not_found")
   end
 
   def test_view_issues
@@ -27,7 +27,7 @@ class IssuesTest < ApplicationSystemTestCase
     issues = create_list(:issue, 3, :assigned_role => "moderator")
 
     visit issues_path
-    assert page.has_content?(issues.first.reported_user.display_name)
+    assert_content issues.first.reported_user.display_name
   end
 
   def test_view_issues_with_no_reported_user
@@ -36,10 +36,10 @@ class IssuesTest < ApplicationSystemTestCase
     issue = create(:issue, :reportable => anonymous_note, :assigned_role => "moderator")
 
     visit issues_path
-    assert page.has_content?(reportable_title(anonymous_note))
+    assert_content reportable_title(anonymous_note)
 
     visit issue_path(issue)
-    assert page.has_content?(reportable_title(anonymous_note))
+    assert_content reportable_title(anonymous_note)
   end
 
   def test_search_issues_by_user
@@ -53,22 +53,22 @@ class IssuesTest < ApplicationSystemTestCase
     visit issues_path
     fill_in "search_by_user", :with => good_user.display_name
     click_on "Search"
-    assert_not page.has_content?(I18n.t("issues.index.user_not_found"))
-    assert page.has_content?(I18n.t("issues.index.issues_not_found"))
+    assert_no_content I18n.t("issues.index.user_not_found")
+    assert_content I18n.t("issues.index.issues_not_found")
 
     # User doesn't exist
     visit issues_path
     fill_in "search_by_user", :with => "Nonexistent User"
     click_on "Search"
-    assert page.has_content?(I18n.t("issues.index.user_not_found"))
-    assert page.has_content?(I18n.t("issues.index.issues_not_found"))
+    assert_content I18n.t("issues.index.user_not_found")
+    assert_content I18n.t("issues.index.issues_not_found")
 
     # Find Issue against bad_user
     visit issues_path
     fill_in "search_by_user", :with => bad_user.display_name
     click_on "Search"
-    assert_not page.has_content?(I18n.t("issues.index.user_not_found"))
-    assert_not page.has_content?(I18n.t("issues.index.issues_not_found"))
+    assert_no_content I18n.t("issues.index.user_not_found")
+    assert_no_content I18n.t("issues.index.issues_not_found")
   end
 
   def test_commenting
@@ -79,8 +79,8 @@ class IssuesTest < ApplicationSystemTestCase
 
     fill_in :issue_comment_body, :with => "test comment"
     click_on "Add Comment"
-    assert page.has_content?(I18n.t("issue_comments.create.comment_created"))
-    assert page.has_content?("test comment")
+    assert_content I18n.t("issue_comments.create.comment_created")
+    assert_content "test comment"
 
     issue.reload
     assert_equal("test comment", issue.comments.first.body)
index 6a4d2397f774b72fe5da38f6f929b1d8fb3a7dae..59a7209f5b4d3728fbb8f3049e4db4a03f0326f4 100644 (file)
@@ -7,7 +7,7 @@ class PreferencesTest < ApplicationSystemTestCase
     visit edit_preferences_path
     click_on "Update Preferences"
 
-    assert page.has_content?("Preferences updated")
+    assert_content "Preferences updated"
   end
 
   def test_flash_message_shows_in_new_language
@@ -17,6 +17,6 @@ class PreferencesTest < ApplicationSystemTestCase
     fill_in "Preferred Languages", :with => "fr"
     click_on "Update Preferences"
 
-    assert page.has_content?("Préférences mises à jour")
+    assert_content "Préférences mises à jour"
   end
 end
index a8027de790c2c29bffcf639e96a1604a65385af5..3504ab061fdeb5c4270036efa49807b1a9c9427f 100644 (file)
@@ -9,19 +9,19 @@ class ReportDiaryCommentTest < ApplicationSystemTestCase
 
   def test_no_link_when_not_logged_in
     visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
-    assert page.has_content?(@comment.body)
+    assert_content @comment.body
 
-    assert_not page.has_content?(I18n.t("diary_entries.diary_comment.report"))
+    assert_no_content I18n.t("diary_entries.diary_comment.report")
   end
 
   def test_it_works
     sign_in_as(create(:user))
     visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
-    assert page.has_content? @diary_entry.title
+    assert_content @diary_entry.title
 
     click_on I18n.t("diary_entries.diary_comment.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.diary_comment.spam_label")
     fill_in "report_details", :with => "This comment is spam"
@@ -29,7 +29,7 @@ class ReportDiaryCommentTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal @comment, Issue.last.reportable
     assert_equal "administrator", Issue.last.assigned_role
index 11a8c2e9194119921b11f2e0a205d2493040747a..0800e1541aa5da7e49570894f2ff477cac5922bc 100644 (file)
@@ -8,19 +8,19 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
 
   def test_no_link_when_not_logged_in
     visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
-    assert page.has_content?(@diary_entry.title)
+    assert_content @diary_entry.title
 
-    assert_not page.has_content?(I18n.t("diary_entries.diary_entry.report"))
+    assert_no_content I18n.t("diary_entries.diary_entry.report")
   end
 
   def test_it_works
     sign_in_as(create(:user))
     visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
-    assert page.has_content? @diary_entry.title
+    assert_content @diary_entry.title
 
     click_on I18n.t("diary_entries.diary_entry.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.diary_entry.spam_label")
     fill_in "report_details", :with => "This is advertising"
@@ -28,7 +28,7 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal @diary_entry, Issue.last.reportable
     assert_equal "administrator", Issue.last.assigned_role
@@ -40,11 +40,11 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
 
     sign_in_as(create(:user))
     visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
-    assert page.has_content? @diary_entry.title
+    assert_content @diary_entry.title
 
     click_on I18n.t("diary_entries.diary_entry.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.diary_entry.spam_label")
     fill_in "report_details", :with => "This is advertising"
@@ -60,6 +60,6 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
   def test_missing_report_params
     sign_in_as(create(:user))
     visit new_report_path
-    assert page.has_content? I18n.t("reports.new.missing_params")
+    assert_content I18n.t("reports.new.missing_params")
   end
 end
index e45a4e702bbb1a1735e2a3c13e9324de560c6d52..2f407ca60d0dbd700b83941dfe8a3a8ee6e2f971 100644 (file)
@@ -4,9 +4,9 @@ class ReportNoteTest < ApplicationSystemTestCase
   def test_no_link_when_not_logged_in
     note = create(:note_with_comments)
     visit browse_note_path(note)
-    assert page.has_content?(note.comments.first.body)
+    assert_content note.comments.first.body
 
-    assert_not page.has_content?(I18n.t("browse.note.report"))
+    assert_no_content I18n.t("browse.note.report")
   end
 
   def test_can_report_anonymous_notes
@@ -15,8 +15,8 @@ class ReportNoteTest < ApplicationSystemTestCase
     visit browse_note_path(note)
 
     click_on I18n.t("browse.note.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.note.spam_label")
     fill_in "report_details", :with => "This is spam"
@@ -24,7 +24,7 @@ class ReportNoteTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal note, Issue.last.reportable
     assert_equal "moderator", Issue.last.assigned_role
@@ -36,8 +36,8 @@ class ReportNoteTest < ApplicationSystemTestCase
     visit browse_note_path(note)
 
     click_on I18n.t("browse.note.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.note.spam_label")
     fill_in "report_details", :with => "This is spam"
@@ -45,7 +45,7 @@ class ReportNoteTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal note, Issue.last.reportable
     assert_equal "moderator", Issue.last.assigned_role
index 5bdf3c201c4914b0490e521f98e8d7f384ef476f..879558ab5fe05bb777f495d5c7c1afe68f424db9 100644 (file)
@@ -4,9 +4,9 @@ class ReportUserTest < ApplicationSystemTestCase
   def test_no_link_when_not_logged_in
     note = create(:note_with_comments)
     visit browse_note_path(note)
-    assert page.has_content?(note.comments.first.body)
+    assert_content note.comments.first.body
 
-    assert_not page.has_content?(I18n.t("users.show.report"))
+    assert_no_content I18n.t("users.show.report")
   end
 
   def test_can_report_user
@@ -15,8 +15,8 @@ class ReportUserTest < ApplicationSystemTestCase
     visit user_path(user)
 
     click_on I18n.t("users.show.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.user.vandal_label")
     fill_in "report_details", :with => "This user is a vandal"
@@ -24,7 +24,7 @@ class ReportUserTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal user, Issue.last.reportable
     assert_equal "moderator", Issue.last.assigned_role
@@ -36,8 +36,8 @@ class ReportUserTest < ApplicationSystemTestCase
     visit user_path(user)
 
     click_on I18n.t("users.show.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.user.vandal_label")
     fill_in "report_details", :with => "This user is a vandal"
@@ -45,7 +45,7 @@ class ReportUserTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal user, Issue.last.reportable
     assert_equal "moderator", Issue.last.assigned_role
@@ -53,8 +53,8 @@ class ReportUserTest < ApplicationSystemTestCase
     visit user_path(user)
 
     click_on I18n.t("users.show.report")
-    assert page.has_content? "Report"
-    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
+    assert_content "Report"
+    assert_content I18n.t("reports.new.disclaimer.intro")
 
     choose I18n.t("reports.new.categories.user.spam_label")
     fill_in "report_details", :with => "This user is a spammer"
@@ -62,7 +62,7 @@ class ReportUserTest < ApplicationSystemTestCase
       click_on "Create Report"
     end
 
-    assert page.has_content? "Your report has been registered successfully"
+    assert_content "Your report has been registered successfully"
 
     assert_equal user, Issue.last.reportable
     assert_equal "administrator", Issue.last.assigned_role
index bf43e97b6cbf9ff1c68138879f1542b41008a405..a097b63747a1281f82ee7e1b658580bbad7c42e9 100644 (file)
@@ -4,45 +4,45 @@ class UserLogoutTest < ApplicationSystemTestCase
   test "Sign out via link" do
     user = create(:user)
     sign_in_as(user)
-    assert_not page.has_content? "Log In"
+    assert_no_content "Log In"
 
     click_on user.display_name
     click_on "Log Out"
-    assert page.has_content? "Log In"
+    assert_content "Log In"
   end
 
   test "Sign out via link with referer" do
     user = create(:user)
     sign_in_as(user)
     visit traces_path
-    assert_not page.has_content? "Log In"
+    assert_no_content "Log In"
 
     click_on user.display_name
     click_on "Log Out"
-    assert page.has_content? "Log In"
-    assert page.has_content? "Public GPS Traces"
+    assert_content "Log In"
+    assert_content "Public GPS Traces"
   end
 
   test "Sign out via fallback page" do
     sign_in_as(create(:user))
-    assert_not page.has_content? "Log In"
+    assert_no_content "Log In"
 
     visit logout_path
-    assert page.has_content? "Logout from OpenStreetMap"
+    assert_content "Logout from OpenStreetMap"
 
     click_button "Logout"
-    assert page.has_content? "Log In"
+    assert_content "Log In"
   end
 
   test "Sign out via fallback page with referer" do
     sign_in_as(create(:user))
-    assert_not page.has_content? "Log In"
+    assert_no_content "Log In"
 
     visit logout_path(:referer => "/traces")
-    assert page.has_content? "Logout from OpenStreetMap"
+    assert_content "Logout from OpenStreetMap"
 
     click_button "Logout"
-    assert page.has_content? "Log In"
-    assert page.has_content? "Public GPS Traces"
+    assert_content "Log In"
+    assert_content "Public GPS Traces"
   end
 end
index d4da01436be9c4183fd26588ab35dd94ebb7b82c..7e2c6ba546c8761376dbb4cd22e994768261e38f 100644 (file)
@@ -6,6 +6,6 @@ class UserSignupTest < ApplicationSystemTestCase
 
     click_on "Register now"
 
-    assert page.has_content? "Confirm Password"
+    assert_content "Confirm Password"
   end
 end