Always require association

#697

(cherry picked from commit a65354c)
This commit is contained in:
Artur Beljajev 2018-02-11 03:18:39 +02:00
parent 8c5478bb6f
commit 9697752823
4 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,6 @@
class Message < ActiveRecord::Base
include Versions # version/message_version.rb
belongs_to :registrar
belongs_to :registrar, required: true
before_create -> { self.queued = true }

View file

@ -0,0 +1,5 @@
class ChangeMessagesRegistrarIdToNotNull < ActiveRecord::Migration
def change
change_column_null :messages, :registrar_id, false
end
end

View file

@ -2183,7 +2183,7 @@ ALTER SEQUENCE mail_templates_id_seq OWNED BY mail_templates.id;
CREATE TABLE messages (
id integer NOT NULL,
registrar_id integer,
registrar_id integer NOT NULL,
body character varying NOT NULL,
attached_obj_type character varying,
attached_obj_id integer,
@ -5094,6 +5094,8 @@ INSERT INTO schema_migrations (version) VALUES ('20180207071528');
INSERT INTO schema_migrations (version) VALUES ('20180207072139');
INSERT INTO schema_migrations (version) VALUES ('20180211011450');
INSERT INTO schema_migrations (version) VALUES ('20180211011948');
INSERT INTO schema_migrations (version) VALUES ('20180212123810');

View file

@ -14,4 +14,10 @@ class MessageTest < ActiveSupport::TestCase
@message.validate
assert @message.invalid?
end
def test_invalid_without_registrar
@message.registrar = nil
@message.validate
assert @message.invalid?
end
end