Ensure report details are not blank.

This commit is contained in:
Andy Allan 2017-09-06 18:17:54 +01:00
parent d7612f42d0
commit c00c515d9d
4 changed files with 17 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :report do
sequence(:details) { |n| "Report details #{n}" }
issue
user
end
end

View file

@ -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