diff options
author | fatkodima <fatkodima123@gmail.com> | 2018-02-11 17:53:23 +0200 |
---|---|---|
committer | fatkodima <fatkodima123@gmail.com> | 2018-02-11 17:53:23 +0200 |
commit | 42259ce904eb2538761b32a793cbe390fb8272b7 (patch) | |
tree | 67888a5c970b20aaecf88765d8255299dbc15e95 /activestorage/test | |
parent | a2a752d1026346e3a348682551dfc952f7cf3a58 (diff) | |
download | rails-42259ce904eb2538761b32a793cbe390fb8272b7.tar.gz rails-42259ce904eb2538761b32a793cbe390fb8272b7.tar.bz2 rails-42259ce904eb2538761b32a793cbe390fb8272b7.zip |
has_(one/many)_attached presence validation
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/presence_validation_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activestorage/test/models/presence_validation_test.rb b/activestorage/test/models/presence_validation_test.rb new file mode 100644 index 0000000000..aa804506dd --- /dev/null +++ b/activestorage/test/models/presence_validation_test.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "test_helper" +require "database/setup" + +class ActiveStorage::PresenceValidationTest < ActiveSupport::TestCase + class Admin < User; end + + teardown do + Admin.clear_validators! + end + + test "validates_presence_of has_one_attached" do + Admin.validates_presence_of :avatar + a = Admin.new + assert_predicate a, :invalid? + + a.avatar.attach create_blob(filename: "funky.jpg") + assert_predicate a, :valid? + end + + test "validates_presence_of has_many_attached" do + Admin.validates_presence_of :highlights + a = Admin.new + assert_predicate a, :invalid? + + a.highlights.attach create_blob(filename: "funky.jpg") + assert_predicate a, :valid? + end +end |