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)
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
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)
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))
--- /dev/null
+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
@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)
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)
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
--- /dev/null
+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