From: Andy Allan Date: Wed, 28 Mar 2018 03:05:21 +0000 (+0800) Subject: Add more tests X-Git-Tag: live~2937^2~12 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/46c183ffeb68a45e6e0793c813f2756109f40642?hp=ab3150646c539daef1a05a25245fe70c6ad8206f Add more tests --- diff --git a/test/models/issue_test.rb b/test/models/issue_test.rb index 5af3779b5..8804b6b28 100644 --- a/test/models/issue_test.rb +++ b/test/models/issue_test.rb @@ -1,8 +1,17 @@ require "test_helper" class IssueTest < ActiveSupport::TestCase + def test_assigned_role + issue = create(:issue) + + assert issue.valid? + issue.assigned_role = "bogus" + assert !issue.valid? + end + def test_reported_user note = create(:note_comment, :author => create(:user)).note + anonymous_note = create(:note_comment, :author => nil).note user = create(:user) create(:language, :code => "en") diary_entry = create(:diary_entry) @@ -12,11 +21,14 @@ class IssueTest < ActiveSupport::TestCase issue.save! assert_equal issue.reported_user, user - # FIXME: doesn't handle anonymous notes issue.reportable = note issue.save! assert_equal issue.reported_user, note.author + issue.reportable = anonymous_note + issue.save! + assert_nil issue.reported_user + issue.reportable = diary_entry issue.save! assert_equal issue.reported_user, diary_entry.user diff --git a/test/models/report_test.rb b/test/models/report_test.rb index fad76297b..810035c9d 100644 --- a/test/models/report_test.rb +++ b/test/models/report_test.rb @@ -1,6 +1,22 @@ require "test_helper" class ReportTest < ActiveSupport::TestCase + def test_issue_required + report = create(:report) + + assert report.valid? + report.issue = nil + assert !report.valid? + end + + def test_user_required + report = create(:report) + + assert report.valid? + report.user = nil + assert !report.valid? + end + def test_details_required report = create(:report) diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 05344b7a4..200029176 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -3,6 +3,11 @@ require "application_system_test_case" class IssuesTest < ApplicationSystemTestCase include IssuesHelper + def test_view_issues_not_logged_in + visit issues_path + assert page.has_content?(I18n.t("user.login.title")) + end + def test_view_issues_normal_user sign_in_as(create(:user)) diff --git a/test/system/report_diary_comment_test.rb b/test/system/report_diary_comment_test.rb new file mode 100644 index 000000000..8b709195d --- /dev/null +++ b/test/system/report_diary_comment_test.rb @@ -0,0 +1,35 @@ +require "application_system_test_case" + +class ReportDiaryCommentTest < ApplicationSystemTestCase + def setup + create(:language, :code => "en") + @diary_entry = create(:diary_entry) + @comment = create(:diary_comment, :diary_entry => @diary_entry) + end + + 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 !page.has_content?(I18n.t("diary_entry.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 + + click_on I18n.t("diary_entry.diary_comment.report") + assert page.has_content? "Report" + assert page.has_content? I18n.t("issues.new.disclaimer.intro") + + choose I18n.t("reports.categories.diary_comment.spam") + fill_in "report_details", :with => "This comment is spam" + click_on "Create Report" + + assert page.has_content? "Your report has been registered sucessfully" + + assert_equal 1, Issue.count + assert Issue.last.reportable == @comment + end +end diff --git a/test/system/report_diary_entry_test.rb b/test/system/report_diary_entry_test.rb index 41fba9604..570fbb1de 100644 --- a/test/system/report_diary_entry_test.rb +++ b/test/system/report_diary_entry_test.rb @@ -6,7 +6,7 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase @diary_entry = create(:diary_entry) end - def test_no_flag_when_not_logged_in + 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) diff --git a/test/system/report_anonymous_note_test.rb b/test/system/report_note_test.rb similarity index 54% rename from test/system/report_anonymous_note_test.rb rename to test/system/report_note_test.rb index d8f52d10f..c5a70b488 100644 --- a/test/system/report_anonymous_note_test.rb +++ b/test/system/report_note_test.rb @@ -1,7 +1,7 @@ require "application_system_test_case" -class ReportAnonymousNoteTest < ApplicationSystemTestCase - def test_no_flag_when_not_logged_in +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) @@ -27,4 +27,23 @@ class ReportAnonymousNoteTest < ApplicationSystemTestCase assert_equal 1, Issue.count assert Issue.last.reportable == note end + + def test_can_report_notes_with_author + note = create(:note_comment, :author => create(:user)).note + sign_in_as(create(:user)) + visit browse_note_path(note) + + click_on I18n.t("browse.note.report") + assert page.has_content? "Report" + assert page.has_content? I18n.t("issues.new.disclaimer.intro") + + choose I18n.t("reports.categories.note.spam") + fill_in "report_details", :with => "This is spam" + click_on "Create Report" + + assert page.has_content? "Your report has been registered sucessfully" + + assert_equal 1, Issue.count + assert Issue.last.reportable == note + end end diff --git a/test/system/report_user_test.rb b/test/system/report_user_test.rb new file mode 100644 index 000000000..dc6c51175 --- /dev/null +++ b/test/system/report_user_test.rb @@ -0,0 +1,30 @@ +require "application_system_test_case" + +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 !page.has_content?(I18n.t("user.view.report")) + end + + def test_can_report_user + user = create(:user) + sign_in_as(create(:user)) + visit user_path(user.display_name) + + click_on I18n.t("user.view.report") + assert page.has_content? "Report" + assert page.has_content? I18n.t("issues.new.disclaimer.intro") + + choose I18n.t("reports.categories.user.vandal") + fill_in "report_details", :with => "This user is a vandal" + click_on "Create Report" + + assert page.has_content? "Your report has been registered sucessfully" + + assert_equal 1, Issue.count + assert Issue.last.reportable == user + end +end