Sha256: 7e3c3e2c0e3df793d9fea5f175828628f2e8e88298efc70ff4fe183228e28e1a

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'test_helper'

module EacRailsUtils
  module Patches
    class ModelAttributeRequiredTest < ActiveSupport::TestCase
      setup do
        reset_test_database
      end

      test 'column with presence validator should be required' do
        assert User.column_required?(:password)
      end

      test 'column with format validator should be required' do
        assert User.column_required?(:email)
      end

      test 'column without validators should be optional' do
        assert_not User.column_required?(:name)
      end

      test 'association with presence validator should be required' do
        assert User.column_required?(:job)
      end

      test 'required column in active model' do
        assert ActiveModelStub.column_required?(:name), 'name is required'
        assert_not ActiveModelStub.column_required?(:age), 'age is optional'
      end

      class ActiveModelStub
        include ActiveModel::Model

        attr_accessor :name, :age
        validates :name, presence: true
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eac_rails_utils-0.10.1 test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
eac_rails_utils-0.10.0 test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
eac_rails_utils-0.9.1 test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
eac_rails_utils-0.9.0 test/lib/eac_rails_utils/patches/model_attribute_required_test.rb