]> git.openstreetmap.org Git - rails.git/commitdiff
Add more tests
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Mar 2018 03:05:21 +0000 (11:05 +0800)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Mar 2018 03:05:47 +0000 (11:05 +0800)
test/models/issue_test.rb
test/models/report_test.rb
test/system/issues_test.rb
test/system/report_diary_comment_test.rb [new file with mode: 0644]
test/system/report_diary_entry_test.rb
test/system/report_note_test.rb [moved from test/system/report_anonymous_note_test.rb with 54% similarity]
test/system/report_user_test.rb [new file with mode: 0644]

index 5af3779b574ba3a1a24cbe855d00d94d20410185..8804b6b2861d79ed4be2d04c2ce545795d7a120f 100644 (file)
@@ -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
index fad76297bf9f2a178323501a054849692519dbe1..810035c9da5d9a3fbdd97d986ad189fb377c37b9 100644 (file)
@@ -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)
 
index 05344b7a4706e1992d74459f5c996d5a744e6acb..20002917680d70da8ceb0ad3fb89bca48acba4bc 100644 (file)
@@ -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 (file)
index 0000000..8b70919
--- /dev/null
@@ -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
index 41fba960447ceeebf5d2d9fe5234daf5342bc91d..570fbb1de59503fc0f9c5c6b7085292d0d80bc65 100644 (file)
@@ -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)
 
similarity index 54%
rename from test/system/report_anonymous_note_test.rb
rename to test/system/report_note_test.rb
index d8f52d10f9baf444bde58f8f15b3170f5b925eb8..c5a70b488fc8807c599916edfe8a2b80a801d207 100644 (file)
@@ -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 (file)
index 0000000..dc6c511
--- /dev/null
@@ -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