]> git.openstreetmap.org Git - rails.git/commitdiff
Ensure report details are not blank.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 6 Sep 2017 17:17:54 +0000 (18:17 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 6 Sep 2017 17:17:54 +0000 (18:17 +0100)
app/models/report.rb
db/migrate/20160822153055_create_issues_and_reports.rb
test/factories/reports.rb [new file with mode: 0644]
test/models/report_test.rb

index 477b4b1824842d37997e8cc2e05054dbf5dc4706..b857d7375a52c70c7fcea03df6c4366ea58ee5a3 100644 (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
index aa7af1a730782f32796e9a1a97d62c32270339ce..20d4fb2754e85030ee32ebf85b4e970d9f331f39 100644 (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
 
diff --git a/test/factories/reports.rb b/test/factories/reports.rb
new file mode 100644 (file)
index 0000000..7c00766
--- /dev/null
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+  factory :report do
+    sequence(:details) { |n| "Report details #{n}" }
+    issue
+    user
+  end
+end
index c7d4f0adc130d10b4cfef44d7a53f88d982a585b..a0de9448c206adcd0a0831a3072102870d8f3df8 100644 (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