From c00c515d9d12e25e63d3a0b3271862dd5b134ca4 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 6 Sep 2017 18:17:54 +0100 Subject: [PATCH] Ensure report details are not blank. --- app/models/report.rb | 2 ++ db/migrate/20160822153055_create_issues_and_reports.rb | 2 +- test/factories/reports.rb | 7 +++++++ test/models/report_test.rb | 10 +++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/factories/reports.rb 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 -- 2.39.5