ref: master
test/unit/abuse_report_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
require_relative "../test_helper" class AbuseReportTest < ActiveSupport::TestCase def setup @reported = fast_create(Profile) @reporter = fast_create(Person) @abuse_complaint = AbuseComplaint.create!(:reported => @reported) end attr_accessor :reporter, :abuse_complaint should 'ensure presence of complaint, reporter and reported' do abuse_report = AbuseReport.new(:reason => 'some reason') refute abuse_report.valid? assert abuse_report.invalid?(:reporter) assert abuse_report.invalid?(:abuse_complaint) abuse_report.reporter = reporter abuse_report.abuse_complaint = abuse_complaint assert abuse_report.valid? end should 'not allow more than one report by a user to the same complaint' do abuse_report = AbuseReport.new(:reason => 'some reason') abuse_report.reporter = reporter abuse_report.abuse_complaint = abuse_complaint abuse_report.save! assert_raise ActiveRecord::RecordInvalid do another_abuse = AbuseReport.new(:reason => 'some reason') another_abuse.reporter = reporter another_abuse.abuse_complaint = abuse_complaint another_abuse.save! end end end |