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 5af3779..8804b6b 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 fad7629..810035c 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 05344b7..2000291 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 41fba96..570fbb1 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 d8f52d1..c5a70b4 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