aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models/presence_validation_test.rb
blob: aa804506dd1b4f1d3e7761de53e09f7b0aafb5bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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