openstreetmap-website/test/models/issue_test.rb
Andy Allan 506c0b5f0d Set the reported_user in a callback
This avoids passing around the reported_user via forms. There was no
validation anywhere that the reported_user corresponded to the object
being reported. This approach removes those worries too.
2017-07-12 13:36:48 +01:00

24 lines
621 B
Ruby

require "test_helper"
class IssueTest < ActiveSupport::TestCase
def test_reported_user
note = create(:note_comment, :author => create(:user)).note
user = create(:user)
create(:language, :code => "en")
diary_entry = create(:diary_entry)
issue = Issue.new
issue.reportable = user
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 = diary_entry
issue.save!
assert_equal issue.reported_user, diary_entry.user
end
end