From: Andy Allan Date: Wed, 6 Sep 2017 17:17:54 +0000 (+0100) Subject: Ensure report details are not blank. X-Git-Tag: live~3562^2~100 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c00c515d9d12e25e63d3a0b3271862dd5b134ca4 Ensure report details are not blank. --- diff --git a/app/models/report.rb b/app/models/report.rb index 477b4b182..b857d7375 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,4 +1,6 @@ class Report < ActiveRecord::Base belongs_to :issue, :counter_cache => true belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id + + validates :details, :presence => true end diff --git a/db/migrate/20160822153055_create_issues_and_reports.rb b/db/migrate/20160822153055_create_issues_and_reports.rb index aa7af1a73..20d4fb275 100644 --- a/db/migrate/20160822153055_create_issues_and_reports.rb +++ b/db/migrate/20160822153055_create_issues_and_reports.rb @@ -25,7 +25,7 @@ class CreateIssuesAndReports < ActiveRecord::Migration create_table :reports do |t| t.integer :issue_id t.integer :reporter_user_id - t.text :details + t.text :details, :null => false t.datetime :created_at t.datetime :updated_at diff --git a/test/factories/reports.rb b/test/factories/reports.rb new file mode 100644 index 000000000..7c0076677 --- /dev/null +++ b/test/factories/reports.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :report do + sequence(:details) { |n| "Report details #{n}" } + issue + user + end +end diff --git a/test/models/report_test.rb b/test/models/report_test.rb index c7d4f0adc..a0de9448c 100644 --- a/test/models/report_test.rb +++ b/test/models/report_test.rb @@ -1,7 +1,11 @@ require "test_helper" class ReportTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_details_required + report = create(:report) + + assert report.valid? + report.details = '' + assert !report.valid? + end end