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
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
--- /dev/null
+FactoryGirl.define do
+ factory :report do
+ sequence(:details) { |n| "Report details #{n}" }
+ issue
+ user
+ end
+end
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